Scratch-folder Codex runs can fail before the prompt starts when codex exec is launched outside a Git working tree. The repository check protects normal project work, but an intentional temporary directory may need a one-run override instead of a repository checkout.
The --skip-git-repo-check flag bypasses only the non-interactive repository guard for that command. It does not authenticate the CLI, widen the sandbox, or mark a directory as trusted for project-scoped .codex/config.toml layers.
Use the flag only after the working directory is known and isolated. A safer fix for normal project work is to move into the intended repository, because the same prompt can otherwise read or write files from a scratch path that was not meant to own the task.
$ git rev-parse --show-toplevel fatal: not a git repository (or any of the parent directories): .git
If this command prints a repository path, keep the repository check enabled and run Codex from that project instead.
$ codex exec --ephemeral --sandbox read-only "Return OK." Not inside a trusted directory and --skip-git-repo-check was not specified.
The message appears before a model run starts, so it is separate from authentication, sandbox, and prompt errors.
$ codex exec --ephemeral --sandbox read-only --skip-git-repo-check "Return OK." OK
Use the override only for a directory created for the task. It removes the repository boundary that normally catches a command launched from the wrong folder.
$ codex exec --ephemeral --sandbox read-only --skip-git-repo-check "Run pwd and return only the command output." /home/user/tmp/codex-scratch
The printed path should match the scratch directory that was intentionally selected. Use -C when a script launches Codex from another shell location.