Codex Desktop should diagnose Git safe.directory / ownership failures when WorkTree project association fails
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.gitdue to ownership /safe.directory.
Related issue: #14519.
What happened, step by step
- I opened a normal Git project in Codex Desktop on Windows.
- I started a new Codex Desktop WorkTree thread from that project.
- Codex created the physical managed worktree under:
``text``
CODEX_HOME\worktrees\<id>\<repo-name>
- The worktree was valid according to Git:
``powershell``
git worktree list --porcelain
- The WorkTree was detached HEAD, which appears to be normal for Codex-managed WorkTrees.
- The new thread existed in local Codex state / rollout files.
- The new thread appeared in the original project sidebar briefly.
- After the sidebar refreshed, the thread disappeared from the original project grouping.
- 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:
- I first thought the problem might be that Codex was placing WorkTrees under
CODEX_HOME\worktreesinstead of next to my project. - After checking the Codex WorkTrees behavior, I realized that this location is normal for Codex-managed WorkTrees.
- I then suspected stale Codex Desktop state, because old hidden WorkTree threads existed locally and some sidebar/project metadata looked out of sync.
- 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.
- I tested fresh WorkTree creation again. The new WorkTree still appeared briefly under the original project and then disappeared from the sidebar.
- 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.
- The key clue came from the Desktop logs:
No matching origin found originUrl=<repo origin url>. - I then compared Git origin lookup from the repo root versus from the
.gitdirectory.
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.
5 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
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:
No matching origin found originUrl=....git -C "<repo>" config --get remote.origin.urlworked.git -C "<repo>/.git" config --get remote.origin.urlfailed / returned nothing.safe.directorytrust for the repo /.gitpath, 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.
Adding another Windows datapoint for the same failure mode. This reproduced as a hidden WorkTree-backed thread rather than data loss, and the
safe.directoryworkaround fixed visibility after a full Codex Desktop restart.Environment:
26.609.9530.0Symptoms:
Diagnostic signal:
A one-off trusted-root test made the
.gitmetadata lookup succeed:Permanent workaround used:
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
.gitdirectory, 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, possiblesafe.directorymismatch, and a suggested narrowgit config --global --add safe.directory "<repo-or-dev-root>"command.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
26.810.410472.55.0.windows.4%USERPROFILE%\.codex\worktrees\<id>\<repo>Reproduction and evidence
%USERPROFILE%\.codex\worktrees.git worktree list --porcelainshows the checkout correctly registered in detached HEAD state.CodexSandboxOffline.The main checkout works because Codex injects command-scoped
safe.directoryentries for the configured workspace root: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 statussucceed in both worktrees: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.directoryinjection 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.
The worktree thread remaining durable while Desktop loses its project/sidebar association is a useful discovery control for
codex-rescue. Rescue won’t change Gitsafe.directoryor 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:
A healthy/no-damage result is expected and useful here. The key signal is whether
sessionssees 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