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
- Have a repository with a remote-tracking branch such as
origin/feature/autorego, but no local branch named feature/autorego.
- In Codex Desktop, start a new worktree-backed conversation.
- Open the branch picker.
- Search for
autorego.
- 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.
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/autoregobut does not exist locally asfeature/autorego, Codex runs:Git fails with:
Environment
26.506.31421(build2620)26.5(25F71)git version 2.50.1 (Apple Git-155)Repro
origin/feature/autorego, but no local branch namedfeature/autorego.autorego.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:
or:
The UI should not offer
feature/autoregoas 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:Because
feature/autoregois not a local ref, Git returns:Codex then reports:
Local checks
In the affected repository:
I also tested whether Git's
worktree.guessRemote=truewould paper over this, but it does not help when--detachis present:The same Git config can help non-detached
git worktree addcreate 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.