Desktop app leaves stale temp worktree and blocks switching back to main

Open 💬 1 comment Opened Mar 13, 2026 by jskoiz

Summary

The Codex desktop app failed to switch branches because Git believed main was already checked out in a different worktree, but that worktree was not visible as an active session in the app.

Error shown in the desktop app:

Failed to switch branch: fatal: 'main' is already used by worktree at '/private/tmp/codex-limit-mainfix'

What happened

Codex appears to have left behind a temp worktree at:

/private/tmp/codex-limit-mainfix

That worktree was still registered with Git, so the app could not switch the current repo back to main.

Expected behavior

If Codex creates a temporary worktree for a session, it should clean it up when the session is closed or no longer active.

If cleanup fails, the app should either:

  • surface the stale worktree clearly in the UI, or
  • offer a "clean up stale worktrees" action

Actual behavior

The app only showed the Git error that main was already used by another worktree. There was no visible active session or branch in the UI that explained why, so it looked like the branch was "stuck".

Workaround

I fixed it manually with:

git worktree list
git worktree remove /private/tmp/codex-limit-mainfix
git worktree prune

After that, switching branches worked again.

Notes

The stale worktree was clean, and there did not appear to be an active process still using it.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗