Codex Desktop should diagnose Git safe.directory / ownership failures when WorkTree project association fails

Open 💬 5 comments Opened May 25, 2026 by KelfiSQd
💡 Likely answer: A maintainer (github-actions[bot], contributor) responded on this thread — see the highlighted reply below.

What version of the Codex App are you using?

Codex Desktop on Windows. I can provide the exact version later if needed, but this report is mainly about a diagnostic gap around Git metadata / project association.

What platform is your computer?

Windows.

Summary

This is a follow-up / diagnostic report related to disappearing Codex Desktop WorkTree threads.

In my case, the Codex-managed Git worktree itself was created correctly, but the new WorkTree thread briefly appeared under the original project in the sidebar and then disappeared after the sidebar refreshed. The thread still existed locally, so this was not data loss. The root cause in my setup was a local Git ownership / safe.directory mismatch that prevented Codex/Git from reading the repository origin from the repo's .git directory.

I am filing this separately from the general disappearing-thread reports because the useful finding is not just "WorkTree disappears", but a concrete diagnostic path and possible product improvement:

Codex Desktop should surface a clear diagnostic when WorkTree project association fails because Git cannot read repository metadata from .git due to ownership / safe.directory.

Related issue: #14519.

What happened, step by step

  1. I opened a normal Git project in Codex Desktop on Windows.
  2. I started a new Codex Desktop WorkTree thread from that project.
  3. Codex created the physical managed worktree under:

``text
CODEX_HOME\worktrees\<id>\<repo-name>
``

  1. The worktree was valid according to Git:

``powershell
git worktree list --porcelain
``

  1. The WorkTree was detached HEAD, which appears to be normal for Codex-managed WorkTrees.
  2. The new thread existed in local Codex state / rollout files.
  3. The new thread appeared in the original project sidebar briefly.
  4. After the sidebar refreshed, the thread disappeared from the original project grouping.
  5. To access it, I had to manually open the CODEX_HOME\worktrees\... folder as if it were a separate project.

So the physical Git layer was fine, but the Desktop project/thread association layer was not persisted correctly.

What I checked first

These were not the bug in my case:

  • The worktree being located under CODEX_HOME\worktrees.
  • Detached HEAD.
  • Git worktree registration.
  • Missing physical worktree folder.
  • Data loss.

The suspicious part was the missing association between the new WorkTree thread and the original project root.

How I tried to solve it before finding the root cause

The confusing part was that the WorkTree was not obviously "failed". It was created, it existed on disk, and Git knew about it. Because of that, I initially suspected the wrong things.

The rough path was:

  1. I first thought the problem might be that Codex was placing WorkTrees under CODEX_HOME\worktrees instead of next to my project.
  2. After checking the Codex WorkTrees behavior, I realized that this location is normal for Codex-managed WorkTrees.
  3. I then suspected stale Codex Desktop state, because old hidden WorkTree threads existed locally and some sidebar/project metadata looked out of sync.
  4. Manually aligning local metadata such as workspace-root hints could make some already-created hidden threads visible again, but that only recovered old threads. It did not fix newly created WorkTrees.
  5. I tested fresh WorkTree creation again. The new WorkTree still appeared briefly under the original project and then disappeared from the sidebar.
  6. That made the problem narrower: Git worktree creation was healthy, but Codex Desktop was not persisting the new thread's association with the original project root.
  7. The key clue came from the Desktop logs: No matching origin found originUrl=<repo origin url>.
  8. I then compared Git origin lookup from the repo root versus from the .git directory.

That last check is what exposed the actual local cause in my setup.

Important log clue

The useful log clue was:

No matching origin found originUrl=<repo origin url>

That suggested Codex Desktop could not match the WorkTree thread back to the original project by Git origin/root metadata.

Diagnostic commands

This command worked:

git -C "<MAIN_WORKSPACE_ROOT>" config --get remote.origin.url

But this command failed or returned nothing:

git -C "<MAIN_WORKSPACE_ROOT>\.git" config --get remote.origin.url

That difference was the key.

Root cause in my setup

The repository root was owned by my normal Windows user, but the .git directory itself had a different local owner from an older setup / folder move.

My global Git safe.directory config trusted the repository root, but it did not trust the .git directory path.

Because Codex Desktop / its Git worker appeared to query Git metadata from inside .git, Git refused to read the repo metadata from that location. As a result, Codex Desktop could not match the origin/project root and did not persist the WorkTree thread association for the sidebar.

Minimal workaround that fixed new WorkTree grouping for me

First, verify whether Git can read the origin from .git:

git -C "<MAIN_WORKSPACE_ROOT>\.git" config --get remote.origin.url

If that fails or prints nothing, add a narrow trust entry for that repo's .git directory:

git config --global --add safe.directory "<MAIN_WORKSPACE_ROOT>/.git"

Then verify again:

git -C "<MAIN_WORKSPACE_ROOT>\.git" config --get remote.origin.url

After restarting Codex Desktop, newly created WorkTree threads stayed associated with the original project again in my setup.

Prevention I used afterwards

For future projects under my normal project folder, I used scoped wildcard entries instead of trusting every repository globally:

git config --global --add safe.directory "C:/Users/<you>/Projects/*"
git config --global --add safe.directory "C:/Users/<you>/.codex/worktrees/*"

I would not recommend this as a universal fix for everyone, and I would not recommend safe.directory=* as a convenience workaround, because that disables Git's ownership protection too broadly.

The cleaner long-term fix is probably to repair the Windows owner / ACL of the repository's .git directory or reclone the repository cleanly.

Expected Codex Desktop behavior

Codex Desktop probably should not automatically change safe.directory, because that is a Git security setting.

But Codex Desktop could detect this situation and show a clear diagnostic before or during WorkTree creation:

Codex created the Git worktree, but could not associate it with the original project because Git could not read repository metadata from .git. Check repository ownership or safe.directory.

At minimum, it would help if the UI surfaced that origin/project-root matching failed, instead of allowing the WorkTree thread to appear briefly and then silently disappear from the original project sidebar.

Why this matters

For users who are newer to Git worktrees, Windows ownership, or Git's safe.directory checks, the current symptom is very confusing:

  • the worktree exists;
  • the thread exists;
  • Git worktree creation succeeded;
  • but the Codex Desktop sidebar loses the project association.

That makes the issue look like a Codex data-loss or UI bug, when in this specific case the actionable cause was a Git trust / metadata lookup failure.

View original on GitHub ↗

5 Comments

github-actions[bot] contributor · 3 months ago

Potential duplicates detected. Please review them and close your issue if it is a duplicate.

  • #24345

Powered by Codex Action

KelfiSQd · 3 months ago

Thanks for flagging #24345 as a possible duplicate.

I agree this is related: the visible symptom is similar — a Desktop-created WorkTree chat briefly appears under the source project and then disappears from the project sidebar while the thread still exists locally.

The reason I filed this separately is that my case narrowed one concrete diagnostic path / root cause:

  • Git worktree creation itself succeeded.
  • The thread existed locally.
  • The useful Desktop log clue was No matching origin found originUrl=....
  • git -C "<repo>" config --get remote.origin.url worked.
  • git -C "<repo>/.git" config --get remote.origin.url failed / returned nothing.
  • After fixing the Git ownership / safe.directory trust for the repo / .git path, newly-created WorkTree chats stayed associated with the original project again.

So #24345 may be the broader WorkTree/sidebar association bug, while this issue documents one confirmed Git metadata / ownership cause and a possible diagnostic Codex Desktop could surface in the UI.

If maintainers prefer, I am fine with treating this as a diagnostic addendum to #24345 rather than a completely separate bug.

dxzcsd123 · 2 months ago

Adding another Windows datapoint for the same failure mode. This reproduced as a hidden WorkTree-backed thread rather than data loss, and the safe.directory workaround fixed visibility after a full Codex Desktop restart.

Environment:

  • Windows
  • Codex Desktop 26.609.9530.0
  • Codex-managed worktree under the user's Codex worktrees directory
  • Original repo under a user-controlled development root

Symptoms:

  • A Codex-managed worktree thread existed and was still accessible internally.
  • The Git worktree existed on disk.
  • The thread could be found by thread search / backend thread listing.
  • It disappeared from the normal project sidebar, making it look like the session was lost.

Diagnostic signal:

git -C "<repo-root>" config --get remote.origin.url
# succeeded

git -C "<repo-root>/.git" config --get remote.origin.url
# failed / exit code 1

A one-off trusted-root test made the .git metadata lookup succeed:

git -c safe.directory="<dev-root>/*" -C "<repo-root>/.git" config --get remote.origin.url
# succeeded

Permanent workaround used:

git config --global --add safe.directory "<dev-root>/*"

After fully quitting and restarting Codex Desktop, the previously missing worktree-backed session appeared correctly in the project sidebar.

Interpretation:

This looks like another concrete case where Git ownership/trust prevents Codex Desktop from reading repository metadata from the main .git directory, so Desktop fails to associate the worktree thread back to the original project. The session data itself was intact.

A useful product fix would be to surface this as a diagnostic when WorkTree project association fails, e.g. failed to read origin/repository metadata from .git, possible safe.directory mismatch, and a suggested narrow git config --global --add safe.directory "<repo-or-dev-root>" command.

shuntksh · 13 days ago

I reproduced a closely related failure mode on Windows where the physical Codex-managed worktree is created and registered correctly, but the new Worktree environment stalls instead of surfacing Git's ownership error.

Environment

  • Codex Desktop: 26.810.41047
  • Git: 2.55.0.windows.4
  • Windows x64
  • Worktree root: %USERPROFILE%\.codex\worktrees\<id>\<repo>

Reproduction and evidence

  1. Start a new Codex Worktree chat from a healthy Git repository.
  2. Codex creates the managed worktree under %USERPROFILE%\.codex\worktrees.
  3. git worktree list --porcelain shows the checkout correctly registered in detached HEAD state.
  4. The checkout is owned by the interactive Windows user, while sandboxed commands run as CodexSandboxOffline.
  5. Running Git inside the new worktree fails with:
fatal: detected dubious ownership in repository at '<managed-worktree>'
'<managed-worktree>/.git' is owned by:
    <machine>/<interactive-user>
but the current user is:
    <machine>/CodexSandboxOffline

The main checkout works because Codex injects command-scoped safe.directory entries for the configured workspace root:

GIT_CONFIG_KEY_0=safe.directory
GIT_CONFIG_VALUE_0=<main-workspace>
GIT_CONFIG_KEY_1=safe.directory
GIT_CONFIG_VALUE_1=<main-workspace>/*

The newly created managed-worktree path was not included in those injected entries. Two attempts produced two valid, registered worktrees, but both were unusable from the sandbox until explicitly trusted. Repository connectivity checks passed, there were no lock files, and disk space was not constrained.

Verified narrow workaround

Adding only each exact generated worktree path to the user's global Git configuration immediately made git status succeed in both worktrees:

git config --global --add safe.directory "C:/Users/<user>/.codex/worktrees/<id>/<repo>"

I deliberately did not use safe.directory=*. Automatically adding a broad wildcard would weaken Git's ownership protection.

Expected behavior

Codex should handle this generated-path ownership boundary itself, preferably by including the exact managed-worktree path in its command-scoped safe.directory injection before validating or starting the Worktree environment.

If that cannot be done safely, Worktree creation should fail promptly and display Git's actual stderr with actionable guidance. The current UI appears to stall indefinitely even though the underlying Git error is deterministic and immediately diagnosable.

This is the inverse ownership direction of #37965, but the product requirement is the same: preserve Git's protection while surfacing a clear diagnostic instead of silently losing/stalling the workflow.

shleder · 11 days ago

The worktree thread remaining durable while Desktop loses its project/sidebar association is a useful discovery control for codex-rescue. Rescue won’t change Git safe.directory or Desktop project metadata; I’m testing whether session discovery still finds the intact local thread independently of that grouping failure.

If you still have an affected or reproducible local state, could you run:

pipx install codex-rescue
codex-rescue sessions
codex-rescue doctor --latest

A healthy/no-damage result is expected and useful here. The key signal is whether sessions sees the durable thread that Desktop temporarily hides, without rewriting the rollout or Git configuration.

Please share sanitized output, versions and exit codes only—no raw rollouts/SQLite, repository paths, prompts, credentials, or private paths. Repo: https://github.com/shleder/codex-rescue