{
  "slug": "codex-exec-not-inside-trusted-directory",
  "url": "https://insidetheloop.dev/fixes/codex-exec-not-inside-trusted-directory",
  "markdown_url": "https://insidetheloop.dev/fixes/codex-exec-not-inside-trusted-directory.md",
  "title": "Codex CLI: \"Not inside a trusted directory and --skip-git-repo-check was not specified.\"",
  "description": "codex exec refuses to run outside a Git repository. Run git init, cd into the repo, or pass --skip-git-repo-check.",
  "tool": {
    "id": "codex",
    "name": "Codex CLI",
    "long_name": "OpenAI Codex CLI (codex)",
    "url": "https://insidetheloop.dev/tools/codex",
    "latest_version": "0.160.1"
  },
  "error": "Not inside a trusted directory and --skip-git-repo-check was not specified.",
  "variants": [],
  "output": "Reading additional input from stdin...\nNot inside a trusted directory and --skip-git-repo-check was not specified.",
  "exit_code": 1,
  "command": "cd /root/plain && codex exec \"say hi\" </dev/null",
  "versions": {
    "affected": "all versions we ran (0.129.0 to 0.160.1)",
    "first_bad": null,
    "last_good": null,
    "fixed_in": null,
    "tested": [
      "0.129.0",
      "0.160.1"
    ]
  },
  "cause": "`codex exec` exits with status 1 when neither the working directory nor any parent directory contains a `.git` entry, unless `--skip-git-repo-check` or `--dangerously-bypass-approvals-and-sandbox` is passed.",
  "fix": {
    "summary": "Run `codex exec` inside a Git repository (any subdirectory works), run `git init` first, or add `--skip-git-repo-check`.",
    "commands": [
      "# 1. inside a repository, or make the directory one",
      "git init -q && codex exec \"<prompt>\"",
      "",
      "# 2. or allow running outside a repository",
      "codex exec --skip-git-repo-check \"<prompt>\""
    ],
    "note": "Despite the word \"trusted\", in 0.160.1 the check only looks for a `.git` entry in the directory or its parents (`get_git_repo_root`). `Reading additional input from stdin...` is printed first whenever stdin is not a terminal; pass `</dev/null` in scripts."
  },
  "reproduction": {
    "ran_at": "2026-10-07T14:12:12Z",
    "environment": "A fresh Debian 13 VM from `bin/sandbox-run` (Node.js 24, root, online, no credentials for any service), destroyed after the run. Git 2.47.3 was installed with apt for the `git init` fix. Without an OpenAI login the model request fails after the check, so the fix is verified by the session header Codex prints before it calls the API.",
    "steps": [
      {
        "label": "Error in an empty directory",
        "version": "0.129.0",
        "command": "cd /root/plain-0.129.0 && codex exec \"say hi\" </dev/null",
        "output": "Reading additional input from stdin...\nNot inside a trusted directory and --skip-git-repo-check was not specified.",
        "exit": 1
      },
      {
        "label": "Same in the latest release",
        "version": "0.160.1",
        "command": "cd /root/plain-0.160.1 && codex exec \"say hi\" </dev/null",
        "output": "Reading additional input from stdin...\nNot inside a trusted directory and --skip-git-repo-check was not specified.",
        "exit": 1
      },
      {
        "label": "Fix 1 verified: --skip-git-repo-check passes the check (the run then fails on the network)",
        "version": "0.160.1",
        "command": "codex exec --skip-git-repo-check \"say hi\" </dev/null",
        "output": "Reading additional input from stdin...\nOpenAI Codex v0.160.1\n--------\nworkdir: /root/plain-0.160.1\n[… trimmed 16 lines …]",
        "exit": 101
      },
      {
        "label": "Fix 2 verified: after git init the same command passes the check",
        "version": "0.160.1",
        "command": "git init -q && codex exec \"say hi\" </dev/null",
        "output": "Reading additional input from stdin...\nOpenAI Codex v0.160.1\n--------\nworkdir: /root/plain-0.160.1\n[… trimmed 16 lines …]",
        "exit": 101
      },
      {
        "label": "A subdirectory of a repository also passes",
        "version": "0.160.1",
        "command": "cd /root/repo/sub/dir && codex exec \"say hi\" </dev/null",
        "output": "Reading additional input from stdin...\nOpenAI Codex v0.160.1\n--------\nworkdir: /root/repo/sub/dir\n[… trimmed 16 lines …]",
        "exit": 101
      }
    ]
  },
  "why": {
    "text": "In `codex-rs/exec/src/lib.rs` at rust-v0.160.1 (lines 975 to 983), `codex exec` prints this message and calls `std::process::exit(1)` when `--skip-git-repo-check` is not set, `--dangerously-bypass-approvals-and-sandbox` is not set, and `get_git_repo_root` finds no `.git` entry in the working directory or its ancestors. The CLI help describes `--skip-git-repo-check` as \"Allow running Codex outside a Git repository.\"",
    "url": "https://github.com/openai/codex/blob/rust-v0.160.1/codex-rs/exec/src/lib.rs#L975-L983",
    "source": "openai/codex codex-rs/exec/src/lib.rs at rust-v0.160.1"
  },
  "tool_page": "https://insidetheloop.dev/tools/codex#gotcha-codex-exec-refuses-to-run-outside-a-git-repository",
  "related": [
    {
      "slug": "codex-exec-full-auto-removed",
      "error": "error: unexpected argument '--full-auto' found",
      "url": "https://insidetheloop.dev/fixes/codex-exec-full-auto-removed"
    }
  ],
  "sources": [
    {
      "title": "codex-rs/exec/src/lib.rs at rust-v0.160.1, lines 975-983",
      "url": "https://github.com/openai/codex/blob/rust-v0.160.1/codex-rs/exec/src/lib.rs#L975-L983",
      "read": "2026-10-07"
    },
    {
      "title": "codex-rs/exec/src/cli.rs at rust-v0.160.1 (--skip-git-repo-check)",
      "url": "https://github.com/openai/codex/blob/rust-v0.160.1/codex-rs/exec/src/cli.rs#L31-L33",
      "read": "2026-10-07"
    },
    {
      "title": "codex-rs/git-utils/src/info.rs at rust-v0.160.1 (get_git_repo_root)",
      "url": "https://github.com/openai/codex/blob/rust-v0.160.1/codex-rs/git-utils/src/info.rs#L30-L37",
      "read": "2026-10-07"
    }
  ],
  "date_published": "2026-10-07T14:15:32Z",
  "date_modified": "2026-10-07T14:15:32Z",
  "verified": {
    "date": "2026-10-07",
    "versions": [
      "0.129.0",
      "0.160.1"
    ]
  }
}
