How to add a writable directory for Codex

Adding a writable directory for Codex expands the normal write boundary when a session needs to change files outside the main project root. This is the safer path when the task needs one or two extra locations instead of unrestricted host access.

Current OpenAI Codex CLI docs describe --add-dir as a repeatable flag that grants additional directories write access alongside the primary workspace. The primary workspace is the current directory by default, or the path passed with -C, while each extra root is added explicitly on the command line.

This flag is most useful with workspace-write sandboxing, where Codex can edit the project but still stays out of unrelated paths unless they are added on purpose. If the same extra roots are needed every time, save them in the workspace-write section of ~/.codex/config.toml, and if the session truly needs unrestricted access, danger-full-access removes the boundary entirely.

Steps to add a writable directory for Codex:

  1. Review the installed CLI help so the current flag name and argument shape are clear.
    $ codex --help
    ##### snipped #####
          --add-dir <DIR>
              Additional directories that should be writable alongside the primary workspace
    ##### snipped #####

    Current OpenAI docs describe the same flag as repeatable, so the option can be passed more than once when several extra paths are needed.

  2. Start Codex with workspace-write and one extra writable path.
    $ codex --sandbox workspace-write --add-dir /srv/notes

    The added path stays separate from the primary workspace root. Use an absolute path so the writable boundary is clear in shell history, scripts, and copied examples. Quote the path when it contains spaces.

  3. Repeat --add-dir for each additional directory that Codex should be allowed to change.
    $ codex --sandbox workspace-write --add-dir /srv/notes --add-dir /mnt/specs

    Add only the directories that the task actually needs. Expanding the writable set too broadly weakens the main safety boundary of workspace-write mode.

  4. Combine -C with --add-dir when the primary workspace should be a different project root.
    $ codex -C /srv/app --sandbox workspace-write --add-dir /srv/notes

    -C changes the primary workspace, while --add-dir adds a separate writable root outside that workspace. The two flags solve different problems and are often used together.

  5. Save the same extra writable roots in ~/.codex/config.toml when they should apply to future workspace-write sessions.
    sandbox_mode = "workspace-write"
    
    [sandbox_workspace_write]
    writable_roots = ["/srv/notes", "/mnt/specs"]

    The current OpenAI config reference uses the [sandbox_workspace_write] section for additional writable roots. Start a new Codex session after saving the file so the updated boundary is loaded.

  6. Verify the persistent extra roots from the config file after saving them.
    $ cat ~/.codex/config.toml
    ##### snipped #####
    sandbox_mode = "workspace-write"
    
    [sandbox_workspace_write]
    writable_roots = ["/srv/notes", "/mnt/specs"]
    ##### snipped #####

    This confirms the saved workspace-write boundary on disk. For one-off runs started with --add-dir, the decisive success state is that Codex can edit the added path without widening the session to danger-full-access.

  7. Keep danger-full-access for tasks that truly need unrestricted host access rather than using it as a shortcut for one missing path.
    $ codex --sandbox danger-full-access

    If the only missing capability is writing to one or two directories outside the workspace, --add-dir keeps the session narrower and easier to reason about than removing the sandbox entirely.