Skip to content

[Windows] Git status/diff reports "this operation must be run in a work tree" while rev-parse reports a work tree #52527

Open

Description

@akirameikyou

What version of the Codex App are you using (From "About Codex" dialog)?

26.1002.7124.0. This is the installed MSIX package version (OpenAI.Codex, x64) read with Get-AppxPackage; I did not read it from the About dialog. The bundled CLI recorded in the session metadata is codex-cli 0.162.0-alpha.2.

What subscription do you have?

Not provided

What platform is your computer?

Microsoft Windows NT 10.0.26200.0 x64 (Windows 11 Pro, build 26200)

What issue are you seeing?

In one Codex Desktop chat on Windows (sandbox policy workspace-write), read-only Git commands against a normal, non-bare repository with a .git directory behave inconsistently:

  • git rev-parse queries succeed and report a work tree.
  • git status and git diff fail with fatal: this operation must be run in a work tree (exit code 128).

About the repository:

  • It is a plain clone: .git is a directory, HEAD is detached, and it has no linked worktrees and no remote.
  • core.bare=false and core.worktree is not set.

On the same repository:

  • In an ordinary, unsandboxed shell on the same machine, git status --short and git diff --quiet HEAD -- both exit 0 (Git for Windows 2.55.0.windows.1).
  • In an earlier Codex chat on the same day, git status --short succeeded (see the steps below).

Output recorded in the failing chat. The working directory had been set to the repository root with Set-Location; paths are redacted.

git rev-parse HEAD                            -> <commit sha>                    exit 0
git rev-parse --show-toplevel                 -> C:/<WORKSPACE>/<repo>           exit 0
git rev-parse --git-dir                       -> .git                            exit 0
git rev-parse --absolute-git-dir              -> C:/<WORKSPACE>/<repo>/.git      exit 0
git rev-parse --git-common-dir                -> .git                            exit 0
git rev-parse --show-prefix                   -> (empty)                         exit 0
git rev-parse --is-inside-work-tree           -> true                            exit 0
git rev-parse --is-inside-git-dir             -> false                           exit 0
git rev-parse --is-bare-repository            -> false                           exit 0
git config --show-origin --get core.bare      -> file:.git/config  false         exit 0
git config --show-origin --get core.worktree  -> (empty)                         exit 1
GIT_DIR / GIT_WORK_TREE / GIT_COMMON_DIR      -> all unset
Test-Path .git                                -> True (Directory, Hidden)

git status --short                            -> fatal: this operation must be run in a work tree   exit 128
git status --porcelain=v1 --untracked-files=no -> same message                                    exit 128
git diff --quiet HEAD --                      -> same message                                     exit 128

git ls-files --error-unmatch <file> also reported one file as unknown to Git. That file is intentionally untracked, so this result is expected and is not part of the problem.

Earlier in the same chat, before the working directory was changed, every command of the form git -C C:\<WORKSPACE>\<repo> ... failed with the message below. That includes rev-parse HEAD, which later succeeded after Set-Location.

fatal: cannot change to 'C:\<WORKSPACE>\<repo>': Permission denied

Reading files in the repository from PowerShell in that chat worked: Get-Item, opening a file for reading, and Get-FileHash all succeeded.

What steps can reproduce the bug?

This is what was observed. I have not yet tried a minimal reproduction from a clean setup.

  1. Codex Desktop on Windows 11, sandbox policy workspace-write. ~/.codex/config.toml currently contains [windows] sandbox = "elevated". The Windows sandbox mode itself is not recorded in the session log; the config file was last modified within a second of the failing chat's start.
  2. The chat's project folder (its cwd) was a folder under the user's OneDrive Documents folder. That path contains non-ASCII characters (the localized Documents folder name), and the project folder name contains a space. The repository lives elsewhere, at C:\<WORKSPACE>\<repo> (an ASCII path, not under OneDrive).
    • The effective file-system policy in the session log (file_system_sandbox_policy) for this chat is:
      • filesystem root: read
      • the project folder: write
      • the per-session .codex\visualizations\... folder: write
      • tmpdir and slash_tmp: write
    • So the repository was covered only by the read entry for the root.
  3. In that chat, run git -C C:\<WORKSPACE>\<repo> status --short --untracked-files=no. Result: fatal: cannot change to ...: Permission denied.
  4. Run Set-Location C:\<WORKSPACE>\<repo>, then the commands listed above. Result: rev-parse succeeds; status and diff fail with "this operation must be run in a work tree".

For comparison: in an earlier chat on the same day, the project folder (cwd) was C:\<WORKSPACE>, the parent folder of the repository. Its effective file-system policy gave C:\<WORKSPACE> write access. There, git -C C:\<WORKSPACE>\<repo> status --short succeeded and listed the untracked files. The session metadata shows the same sandbox policy type (workspace-write) and the same CLI version for both chats.

What is the expected behavior?

Read-only Git inspection (git status, git diff) should work in a normal work tree that the chat can read. If the path is outside what the sandboxed process may use, I would expect an error that says so, rather than Git reporting that the directory is not a work tree.

Additional information

Status of the cause: the outputs above are copied from the Codex session log; the cause has not been determined.

One possible explanation (not verified):

  • In Git's setup.c, setup_work_tree() dies with "this operation must be run in a work tree" when no work tree is found, and also when the chdir into the work tree fails.
  • status and diff go through that step; the rev-parse queries above do not.
  • Together with the earlier cannot change to ...: Permission denied, the message may therefore be a downstream effect of a refused chdir into a folder that the policy grants only read, even though reading files there succeeded.

I have not confirmed this. I also have not confirmed:

  • which Windows access check is involved;
  • whether the OneDrive or non-ASCII project path plays any role;
  • which git.exe the sandboxed process used. On the host, git on PATH is Git for Windows 2.55.0.windows.1.

A separate observation on the same machine and day, which may or may not be related. In a chat whose cwd was C:\<WORKSPACE> (policy write on C:\<WORKSPACE>), a Python 3.12 test suite failed during setup:

  • With the default TEMP (...\AppData\Local\Packages\sandbox.{...}\AC\Temp): tempfile.TemporaryDirectory() was created, but os.mkdir of a subdirectory inside it raised PermissionError: [WinError 5].
  • With TMP/TEMP pointed to a folder inside C:\<WORKSPACE>: creating and writing a temporary file succeeded, but os.link(tmp, path) (a hard link in the same directory) raised PermissionError: [WinError 5].

Outside the sandbox, the same tests pass on the same NTFS volume. Hard links work normally there, both within a directory and across directories, and linking onto an existing file raises FileExistsError as expected.

Possibly related issues (not identical):

#34828 shows the same Git message, but with a different cause (macOS, bare common-dir).

Questions:

  1. Is this a known limitation or expected behavior of the Windows sandbox, or more likely an environment or configuration problem on my side?
  2. Is a repository outside the chat's project folder expected to allow file reads but refuse a chdir into it?
  3. Is hard-link creation (os.link / CreateHardLink) expected to be refused inside a workspace-write root?
  4. What is the recommended way to inspect such a repository with Git while keeping the sandbox enabled? For example, should the repository itself (or its parent) be the chat's project folder?

Activity

  1. added
    bug
    app
    windows-os
    sandbox
    on Oct 9, 2026
  2. executiveos2026 commented on Nov 11, 2026

    @executiveos2026

    Additional reproduction: Codex Desktop Git failure and PowerShell filesystem initialization error

    I can reproduce the Git working-tree failure described in this issue on Windows using Codex Desktop.

    Observed behavior

    Inside Codex Desktop, the following command fails:

    git status --short --branch

    Output:

    Attempting to perform the InitializeDefaultDrives operation on the 'FileSystem' provider failed.
    fatal: this operation must be run in a work tree
    

    Exit code: 1.

    This occurs consistently, including in newly created Codex conversations.

    Repository verification

    The repository is a normal, non-bare Git working repository.

    Inside Codex:

    • git rev-parse --show-toplevel succeeds.
    • git rev-parse --is-inside-work-tree returns true.
    • git rev-parse --is-bare-repository returns false.
    • git ls-files succeeds.
    • .git/index exists and is readable.
    • core.bare=false.
    • No core.worktree override is configured.
    • GIT_DIR, GIT_WORK_TREE, and GIT_COMMON_DIR are unset.

    Despite these results, git status fails.

    Comparison outside Codex Desktop

    The identical Git installation works in ordinary Windows PowerShell.

    Git version:

    2.54.0.windows.1

    Running:

    git status --short --branch

    Returns:

    ## main
    

    The repository is clean.

    Sandbox testing

    The failure persists under:

    • Read-only sandbox permissions
    • Workspace-write sandbox permissions
    • Elevated Windows sandbox configuration
    • MXC Windows sandbox configuration
    • Fresh Codex Desktop conversations

    However, invoking the standalone Codex CLI with MXC succeeds.

    The standalone MXC test returned:

    ## main
    

    Exit code: 0.

    Execution environment

    Both the PowerShell/.NET current directory and native cmd.exe current directory correctly identify the repository root.

    Launching Git through cmd.exe from inside Codex Desktop produces the same failure.

    The issue is therefore not explained by an incorrect working directory or by using a different Git installation.

    Runtime information

    The problem persisted after the Codex workspace runtime was updated to:

    26.1110.11613

    Codex Desktop uses a packaged Windows runtime.

    The built-in dependency diagnostic reports that dependencies are healthy.

    Impact

    This prevents Codex Desktop from reliably inspecting Git working-tree status, which interferes with normal development workflows.

    The existing repository works correctly outside Codex Desktop.

    Requested investigation

    Please investigate whether Codex Desktop's packaged Windows execution environment is interfering with PowerShell filesystem-provider initialization or Git working-tree access.

    The successful standalone MXC CLI test, compared with the failing Desktop execution, may help isolate the affected component.

    No Git repository corruption has been established.

    I can provide sanitized diagnostic excerpts if additional information is required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    appbugsandboxwindows-os

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions