All articles
FixesCodexOpenAI

Codex “Not inside a trusted directory”: cd, git init, or –skip-git-repo-check (Tested on 0.170.0)

We reproduced Codex “Not inside a trusted directory” on CLI 0.170.0, in an empty directory, without logging in. The check looks for a Git repo. cd, git init, or --skip-git-repo-check gets past it; the run may then stop at 401.

Clay illustration of a pale blue folder and a small terminal left outside a sage-green fence, for the Codex Not inside a trusted directory error
Also available in中文Español

We ran codex exec "say hi" on 18 November 2026, in Beijing time, inside an empty directory that had no .git folder. The CLI was Codex 0.170.0. We did not log in, and we did not set an API key. The process printed one line and exited with status 1:

Not inside a trusted directory and --skip-git-repo-check was not specified.

The wording sounds like a trust policy. On this version it is narrower than that: codex exec will not start unless it can find a Git repository, or you pass --skip-git-repo-check. Below is how to choose among the three fixes, and what happened when we tried two of them.

What Codex is actually checking

The CLI help for --skip-git-repo-check is one sentence: “Allow running Codex outside a Git repository.” That is the rule. In 0.170.0 the check looks for a .git entry in the current directory or in a parent. A subdirectory of a repository is fine. A scratch folder with no Git history is not.

We did not need a model call to see this. The failure happens before authentication. If you are already inside the project you meant to use, the fix is to go there, not to loosen the guard.

Which of the three fixes to use

If you thought you were already in a project, cd into that repository and run the command again. The check walks upward, so a subdirectory of the repo works. This is the usual case, and it keeps the guard in place for the next run.

If the folder itself should be a repository, run git init and then codex exec again. We did that in /tmp/codex-gitinit-1118 on the same day. The trusted-directory line went away.

If you really want a one-off run outside Git, add --skip-git-repo-check. That is the flag the error names, and it is the one the help text describes. It does not turn off the sandbox, and it does not log you in.

Three fixes for Codex Not inside a trusted directory: cd into a repo, git init, or --skip-git-repo-check, with what we saw on CLI 0.170.0

Use one of these, not all three. A project that already has a remote should be entered with cd, not re-initialized. Reserve the skip flag for a deliberate scratch run whose directory you already chose on purpose.

What we ran on 0.170.0

The first command was run in an interactive terminal, in /tmp/codex-plain-1118, which sat outside any Git repository. Codex printed only the trusted-directory line and exited 1. When standard input is not a terminal — for example a script that uses </dev/null — it first prints Reading additional input from stdin... and then the same line. We captured both.

In the same empty folder, codex exec --skip-git-repo-check "say hi" got past the check. Codex printed a session header: version 0.170.0, workdir /tmp/codex-plain-1118, model gpt-6.2-sol, provider openai, approval never, sandbox read-only. After several failed WebSocket reconnects it stopped at 401 Unauthorized: Missing bearer or basic authentication in header, and exited 1. That later 401 is expected. We were not logged in, and we did not send a key.

A fresh git init in /tmp/codex-gitinit-1118, followed by the original codex exec "say hi" with no skip flag, produced the same sequence: the trusted-directory line was gone, the session header appeared, then the same 401. The Git check had already passed.

Terminal output of Codex CLI 0.170.0 in an empty directory: Not inside a trusted directory, then the same command with --skip-git-repo-check reaching a 401 Missing bearer error

We did not log in after the check passed, and no paid request went out. The 401 is the evidence that the directory guard is no longer what is blocking you. Login and API-key failures are a separate step; see OpenAI 401 Incorrect API key provided if the next message is about the key itself.

What this error is not

What Codex Not inside a trusted directory means on 0.170.0, and what it does not mean: it is a Git-repo guard, not a denylist, a sandbox bypass, or a completed login

The word “trusted” is easy to misread as a denylist, a project-trust setting, or a sandbox decision. On 0.170.0 it is a Git-repository guard for codex exec. Passing the check does not mark the folder as trusted for other Codex features, and --skip-git-repo-check does not disable approvals or the sandbox.

A different flag, --dangerously-bypass-approvals-and-sandbox (also called --yolo), is documented as skipping confirmation prompts and running without the sandbox. That is a much wider change, and it is the wrong tool for this error. An older report in openai/codex issue #7522 described --yolo still hitting the trusted-directory line until a later change made that flag skip the Git check as well. Do not reach for it just to work in a non-Git folder.

If the stream later drops after you are logged in, that is a different message. We have a separate write-up for Codex “stream disconnected before completion”. For other Codex wording, start with the OpenAI Codex error codes table.

FAQ

Does this mean my folder is marked untrusted in config.toml?

Not on the evidence we have from 0.170.0. The process exits before it starts a session, and the official help describes the flag as allowing Codex to run outside a Git repository. We did not see a config-file trust prompt at this step.

Will git init upload my files or start a paid run?

No. git init only creates a local .git directory. In our test, Codex still stopped at the 401 because we were not authenticated. Nothing was billed.

I passed the check and now I see a 401 or a login prompt. Is the original error fixed?

Yes. The trusted-directory check has already passed. What you have now is an authentication problem. Sign in, or fix the key, before you treat it as the same error again.

Does this happen in the Codex app, or only with codex exec?

We only reproduced it with codex exec. The error text itself names --skip-git-repo-check, which is an exec flag. We did not test the desktop app or the IDE plugin for this message.

Leave a thought

Your email address will not be published.