Codex Desktop worktree creation fails for remote-only branches

Open 💬 0 comments Opened May 14, 2026 by thomast8

Summary

Codex Desktop's native "New worktree" flow can list a remote-only branch in the branch picker, but then fail to create the worktree because it passes the short branch name to git worktree add --detach.

For a branch that exists as origin/feature/autorego but does not exist locally as feature/autorego, Codex runs:

git worktree add --detach /Users/thomastiotto/.codex/worktrees/ac05/PolicyAsCode feature/autorego

Git fails with:

fatal: invalid reference: feature/autorego

Environment

  • Codex Desktop: 26.506.31421 (build 2620)
  • macOS: 26.5 (25F71)
  • Git: git version 2.50.1 (Apple Git-155)
  • Local repository on macOS filesystem

Repro

  1. Have a repository with a remote-tracking branch such as origin/feature/autorego, but no local branch named feature/autorego.
  2. In Codex Desktop, start a new worktree-backed conversation.
  3. Open the branch picker.
  4. Search for autorego.
  5. Select feature/autorego, which appears under "Branches".

Expected

Codex should create the worktree from the remote-tracking branch, for example by using one of these strategies:

git worktree add --detach <path> origin/feature/autorego

or:

git worktree add --track -b feature/autorego <path> origin/feature/autorego

The UI should not offer feature/autorego as a selectable branch if the worktree creation code cannot resolve it.

Actual

The UI shows the remote-only branch as feature/autorego, but the worktree creation code passes that bare ref to Git:

git worktree add --detach /Users/thomastiotto/.codex/worktrees/ac05/PolicyAsCode feature/autorego

Because feature/autorego is not a local ref, Git returns:

fatal: invalid reference: feature/autorego

Codex then reports:

Worktree setup failed.
[info] Starting worktree creation
fatal: invalid reference: feature/autorego
[stderr] git worktree add failed: fatal: invalid reference: feature/autorego

Local checks

In the affected repository:

git rev-parse --verify feature/autorego
fatal: Needed a single revision

git rev-parse --verify origin/feature/autorego
58b0b7e94ccd22b061c02273bb1586c4a9f7f2ae

I also tested whether Git's worktree.guessRemote=true would paper over this, but it does not help when --detach is present:

git -c worktree.guessRemote=true worktree add --detach <path> feature/detach-only
fatal: invalid reference: feature/detach-only

The same Git config can help non-detached git worktree add create a local tracking branch, but Codex currently uses the detached form.

Notes

There is an adjacent open worktree issue, #16936, about worktree creation timing out after Git succeeds. This one appears distinct: Git fails before setup/environment scripts run because the selected branch name is a remote-only ref that was shortened before worktree creation.

View original on GitHub ↗