Skip to content

Make the Codex Working Directory Explicit

2026-08-24codex, automation

When cron or CI runs Codex, it starts wherever the scheduler started, so relative paths can point at the wrong project. Set the working directory in the command instead of inheriting it.

You need: the Codex CLI, a terminal, and a project that is a Git repository. This check reads files and edits nothing.

Put the working directory in the command the scheduler runs:

bash
codex exec --cd /srv/projects/invoices --sandbox read-only \
  "Do not edit anything. Report your working directory, the current Git revision, and the path of README.md relative to that directory."

Run it twice, from two different parent directories, such as your home directory and /tmp. The result to test for: both runs report the same directory, the same revision, and README.md. If either run reports the directory you launched from, the automation still inherits its location. Fix that boundary before giving it write access.

Codex also expects to run inside a Git repository. OpenAI documents that it refuses to run outside one unless you pass --skip-git-repo-check. If a scheduled run stops on that check, look at the directory first; the flag bypasses the check without changing where the task runs.

Save the command and its expected result with the project so the next host can verify setup without inheriting your shell history.

What was checked: --cd, --sandbox, and --skip-git-repo-check appear in codex exec --help for codex-cli 0.155.1, run on September 20, 2026. The Git requirement comes from OpenAI's documentation. The two-directory trial was not run against a live model for this note, so the expected result above is what to test for, not a recorded output.

Next: make Codex explain which instructions it loaded. The working directory also decides which AGENTS.md files apply.

OpenAI documentation.