Trusted directory checks in Codex can block exec runs started from arbitrary folders, which commonly happens when a command is launched from a scratch directory or an unversioned workspace.

The Codex CLI treats a Git repository as its trust boundary and context root, allowing prompts and diffs to be anchored to a known project directory instead of the current filesystem location.

Pointing the run at a repository directory preserves the safety check. Using --skip-git-repo-check should be limited to disposable tasks because it removes guardrails meant to prevent execution against unintended paths.

Steps to fix Codex trusted directory errors:

  1. Identify the repository root for the task.
    $ git rev-parse --show-toplevel
    /home/user/projects/example-repo

    Use the repo root that contains the files you want Codex to read or edit.

  2. Run Codex with a working directory that is a Git repository.
    $ codex exec -C /home/user/projects/example-repo "Return OK."
    OK

    -C runs codex exec from the specified repository without changing the current shell directory.

  3. Run Codex with the Git repo check disabled when no repo is available.
    $ codex exec --skip-git-repo-check "Return OK."
    OK

    Skipping the repository check removes the trusted-directory safeguard, so accidental reads/writes in the wrong folder become easier.

  4. Re-run the original prompt once the trusted directory setting is corrected.
    $ codex exec "Return OK."
    OK