Skip to content

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

Open

Description

@KelfiSQd

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:

    CODEX_HOME\worktrees\<id>\<repo-name>
    
  4. The worktree was valid according to Git:

    git worktree list --porcelain
  5. The WorkTree was detached HEAD, which appears to be normal for Codex-managed WorkTrees.

  6. The new thread existed in local Codex state / rollout files.

  7. The new thread appeared in the original project sidebar briefly.

  8. After the sidebar refreshed, the thread disappeared from the original project grouping.

  9. 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.

Activity

  1. added
    enhancementNew feature or request
    appIssues related to the Codex desktop app
    windows-osIssues related to Codex on Windows systems
    sessionIssues involving session (thread) management, resuming, forking, naming, archiving
    on May 25, 2026
  2. github-actions commented on May 25, 2026

    @github-actions
    Contributor

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

    Powered by Codex Action

  3. KelfiSQd commented on May 26, 2026

    @KelfiSQd
    Author

    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.

  4. dxzcsd123 commented on Jun 16, 2026

    @dxzcsd123

    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.

  5. shuntksh commented on Aug 15, 2026

    @shuntksh

    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.

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

    appIssues related to the Codex desktop appenhancementNew feature or requestsessionIssues involving session (thread) management, resuming, forking, naming, archivingwindows-osIssues related to Codex on Windows systems

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions