How do I fix Codex CLI's trusted directory error on Mac?

If Codex CLI on your Mac reports Not inside a trusted directory, first check whether you are in the project's Git working directory. Don't rush to change system permissions. The usual fix is to switch to the existing repository; for a new project, consider initializing Git. Use the option to skip this check with codex exec only for a one-off task that clearly does not need a repository.

Read the full error first

This message is easy to confuse with a file access problem or a project that has not been trusted yet. If the full error also includes --skip-git-repo-check was not specified, check the Git working directory before looking at macOS privacy settings.

Save the complete error message, then run:

pwd
git rev-parse --is-inside-work-tree
git rev-parse --show-toplevel
codex --version

If the second command returns true, the current directory is inside a Git working tree. The third command shows the repository root. If you see not a git repository, you are usually in the wrong directory, or Git has not been initialized for the project.

If you cannot run git at all, follow the prompt to install the command-line developer tools before continuing. Git being unavailable does not mean Codex lacks permissions.

The Git repository check, project trust, and permission to execute commands are separate checks. Resolving one error does not mean every subsequent operation should be allowed.

Find the right project directory

When you open a new terminal or connect to a Mac over SSH, you may start in your home directory rather than the project you last worked on. Opening a project in Finder does not change the working directory of another terminal.

For a project located at ~/Projects/ios-client, run:

cd "$HOME/Projects/ios-client"
pwd
git status --short
git rev-parse --show-toplevel

First, confirm that the path exists and that the files in the directory belong to the intended project. Keep the quotation marks around paths containing spaces so that one path is not split into multiple arguments.

If the repository root is higher up than expected—for example, if it points to the entire Projects directory—check whether a repository was accidentally initialized in a parent directory. Do not let the tool work on the entire parent directory, and do not delete .git without inspecting it first.

For projects with multiple repositories, distinguish the application directory from dependency directories. If you enter a dependency's own repository, the scope Codex sees may not be the application you intend to change. Also, a Git worktree's .git can be a file, so the absence of a .git folder does not prove there is no repository.

Initialize Git if needed

Code extracted from an archive or a newly created script directory may genuinely have no Git repository. If you plan to keep using Codex to modify the code, establish version history first so you can review differences and restore files.

After confirming that you are in the correct project root, run:

git init
git status --short

Pause here. Review .gitignore and exclude secrets, environment configuration, build caches, and generated files that should not be committed. Once you have checked the list, select the files you want to track individually.

For example, if the directory actually contains the following files:

git add .gitignore README.md
git diff --cached
git commit -m "Record project setup"

This is an example, not a requirement for your project to contain files with these names. Do not stage everything just to complete the initial commit. Git's ability to track changes does not guarantee that secrets have been excluded.

A commit is not required to resolve the repository-check error, but it provides a clear recovery point. If Git reports that the author identity is not configured when you try to commit, configure the current repository with information approved by your team. Do not casually change the global settings for the entire machine.

Skip the check for a one-off task

If you only need to analyze a temporary text file and do not intend to create a repository, you can use the following in a dedicated directory that you have cleaned up first:

codex exec --help
codex exec --skip-git-repo-check \
  "只列出当前目录的文件名并说明可能的用途,不修改任何文件"

Check the local help output first to confirm that the option is available. This is an exec mode option; do not assume that entering it in an interactive session will change that session's configuration.

It skips only the Git repository check. It does not disable the sandbox or automatically approve commands. Asking for “no changes” in a prompt is not a technical read-only restriction either; execution permissions still need to be checked separately.

Do not run this example in your home directory, Downloads directory, or a parent directory containing other teams' materials. Copy the necessary files into a dedicated directory and remove credentials before starting the task.

SSHMini's cloud Macs let you keep code changes and Xcode builds on the same dedicated physical machine, but switching to macOS does not automatically resolve directory trust issues. In a remote terminal, you still need to verify the current path and permissions.

Recheck scope and permissions

Once you are back in the correct directory, give Codex a narrowly scoped task first, such as “Explain the project's entry point without modifying any files.” Check the path it identifies before gradually allowing changes and builds.

If a project trust prompt appears in interactive mode, first assess whether the code comes from a reliable source. Instruction files, scripts, and tool configuration in the project can influence subsequent operations. Do not approve everything simply to continue.

After fixing the issue, check at least these three things:

  • pwd matches the intended project directory, and the Git root does not unexpectedly include a broader directory.
  • The commands the tool intends to run are relevant to the current task and do not request unrelated system permissions.
  • After the task, review git status --short and git diff to confirm the scope of the changes.

If the Git checks now pass but the original error persists, record the complete launch command, Codex version, and exact error message. Check whether an editor task or script is launching Codex in a different directory. Record only what is necessary; do not include tokens, environment variable values, or private source code in troubleshooting notes.

Find the right directory first, then decide whether you need a repository, and only then consider a one-off bypass. This restores operation without turning a path mistake into a machine-wide permissions change.

Frequently asked questions

Do I always need to run git init to fix this error?

No. Check your location with pwd and git rev-parse --show-toplevel first. Enter the existing repository if there is one. Initialize Git only for a new project you intend to version.

Does --skip-git-repo-check also disable the sandbox?

No. With codex exec, it only skips the Git repository check for that invocation. It does not disable sandboxing, approve every command, or grant extra file access.

Move builds to a dedicated physical Mac

Compare the Apple M4 and Apple M4 Pro Mac mini to find the right configuration and billing term for your team’s CI pipeline.

Rent now

Set up your runner

Choose a dedicated physical Mac mini and run your team’s builds on your own Apple Silicon node.