Codex Desktop 26.810.41047 can resolve a tracked branch as refs/heads/HEAD when creating a permanent worktree
@smattei-oai is already working on this.
Since Aug 20, 2026.
- Dominant language
- Rust
- Stars
- 125k
- Forks
- 19.5k
- PR merge metrics
- PR metrics pending
Description
What version of the Codex App are you using?
Codex Desktop 26.810.41047.
What platform is your computer?
macOS.
What issue are you seeing?
Creating a permanent worktree can fail immediately with:
[info] Starting worktree creation
fatal: invalid reference: refs/heads/HEAD
[stderr] git worktree add failed: fatal: invalid reference: refs/heads/HEAD
The repository is not in detached HEAD state, and Git resolves the current branch correctly. After further testing, I can reproduce this in a minimal repository where the current local branch tracks an upstream branch.
Codex appears to end up treating the literal value HEAD as a local branch name and constructing the invalid ref refs/heads/HEAD.
Minimal reproduction
Create a completely new repository with one commit and a local bare remote:
rm -rf /tmp/codex-upstream-test /tmp/codex-upstream-remote.git
git init --bare /tmp/codex-upstream-remote.git
git clone /tmp/codex-upstream-remote.git /tmp/codex-upstream-test
cd /tmp/codex-upstream-test
git switch -c main
echo test > README.md
git add README.md
git commit -m "init"
git push -u origin main
Verify the repository is in a normal branch/tracking state:
$ git status -sb
## main...origin/main
$ git branch -vv
* main <commit> [origin/main] init
$ git rev-parse --abbrev-ref --symbolic-full-name '@{u}'
origin/main
Then:
- Add
/tmp/codex-upstream-testas a project in Codex Desktop. - Choose Create permanent worktree.
- Worktree creation fails with:
fatal: invalid reference: refs/heads/HEAD
A/B testing
I also tested the behavior using fresh repositories and fresh clones to isolate the trigger.
The following Git operations all work correctly outside Codex:
git symbolic-ref HEAD
# refs/heads/main
git rev-parse --verify HEAD
# valid commit
git worktree add /tmp/codex-worktree-test --detach HEAD
# succeeds
Fresh clones and depth-1 shallow clones can still reproduce the Codex failure, so the issue is not explained by old worktree metadata, repository history size, or a damaged HEAD.
The most useful A/B result was:
- repository with a remote but no upstream configured for the current branch: permanent worktree creation succeeded
- same repository after setting the current branch to track
origin/main: permanent worktree creation failed withrefs/heads/HEAD
The tracking configuration itself was normal:
branch.main.remote = origin
branch.main.merge = refs/heads/main
upstream = origin/main
origin/HEAD was also valid and resolved to the expected branch, so this does not appear to be caused by a missing or broken origin/HEAD.
Expected behavior
Codex should resolve the selected/current local branch and create the permanent worktree from a valid revision/commit, regardless of whether that branch tracks an upstream remote branch.
Actual behavior
Under the reproducible tracked-branch case above, Codex passes or constructs:
refs/heads/HEAD
which is not a valid local branch ref in the repository, causing git worktree add to fail before the worktree is created.
Additional notes
This is reproducible in a newly created one-commit repository, so it is not specific to any particular project or repository.
The upstream relationship appears to be a reliable trigger in the A/B tests, but I am not claiming it is necessarily the underlying root cause; the bug may be in Codex's branch/ref resolution or cached project Git state.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.