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.
Related: How to set the working directory for Codex
Related: How to set Codex sandbox mode
$ 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.
$ 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.
$ 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.
$ 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.
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.
$ 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.
$ 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.
Related: How to set Codex sandbox mode