The Codex message Not inside a trusted directory and --skip-git-repo-check was not specified. appears when codex exec starts outside a Git working tree, so the task stops before Codex can read files or run commands.
Current OpenAI Codex documentation treats this as the non-interactive repository safeguard for codex exec. That safeguard is separate from project trust for .codex/config.toml, which only controls whether project-scoped configuration layers load.
The safest fix is to launch codex exec from the repository that should own the task and keep the repository check enabled. Use --skip-git-repo-check only for intentional scratch directories, because it removes the check that helps prevent work in the wrong folder.
Steps to fix Codex trusted directory error:
- Reproduce the failure from the directory that is currently blocked.
$ codex exec "Return OK." Not inside a trusted directory and --skip-git-repo-check was not specified.
That output confirms the run stopped at the repository safeguard before the task started.
- Check whether the current directory is inside a Git working tree.
$ git rev-parse --show-toplevel fatal: not a git repository (or any of the parent directories): .git
If git rev-parse prints a repository root instead, the failing shell is already inside a repo and the error came from a different launch location.
- Change to the repository that should own the Codex run.
$ cd /home/user/projects/example-repo
Start the command from the repository itself. Current CLI behavior can still stop at the same safeguard when -C points to a repo but the launch directory is outside Git.
- Confirm the new location is now inside the intended repository.
$ git rev-parse --show-toplevel /home/user/projects/example-repo
The printed path should be the repository root or a parent of the current working directory.
- Run codex exec again from inside the repository.
$ codex exec "Return OK." OK
The exact prompt can differ. The decisive success signal is that Codex starts normally instead of returning the trusted-directory error.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
