Codex Desktop 26.810.41047 can resolve a tracked branch as refs/heads/HEAD when creating a permanent worktree
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.
18 Comments
I can confirm this still reproduces on Codex Desktop 26.810.52044
(build 6662), macOS 26.5.2, bundled codex-cli 0.148.0-alpha.9,
and Git 2.50.1 (Apple Git-155).
The primary worktree is on a normal tracked branch:
git status -sb
main...origin/main
git symbolic-ref -q HEAD
refs/heads/main
The Codex Desktop log shows it invoking:
git worktree add --detach <redacted-worktree-path> refs/heads/HEAD
The operation fails before environment setup with:
fatal: invalid reference: refs/heads/HEAD
This appears to be the same tracked-upstream branch resolution bug.
<img width="583" height="294" alt="Image" src="https://github.com/user-attachments/assets/b49635b0-8131-45f3-9846-e45be293d2cb" />
I can also reproduce this on Windows, so this issue is not macOS-specific and appears to be a cross-platform tracked-branch bug.
Environment:
26.810.7004.019045, x64masterbranch trackingorigin/masterCreating a permanent worktree fails with the same error:
I confirmed the following temporary workaround:
``
bash
``git branch --unset-upstream
``
bash
``git branch --set-upstream-to=origin/master master
Unsetting the upstream only removes the branch tracking configuration temporarily; it does not delete or modify branches or commits. The newly created worktree remains usable after the upstream is restored.
ChatGPT 26.814.41407… It seems that the new version has fixed , right?
i still got the issue in this version
By the way, I didn't experience this issue in all repositories, only in some of them
Confirmed —
26.814.41407still reproduces this for me as well.The “only some repositories” behavior matches the original A/B results: repos where the current branch tracks an upstream can hit
refs/heads/HEAD, while removing the upstream makes permanent worktree creation succeed.So this still looks like a conditional upstream/ref-resolution bug rather than a repository-specific corruption issue.
I am also hitting this bug, and it is making the development workflow very difficult.
The repository is in a normal local branch state, but Codex fails during worktree creation with:
This appears consistent with the tracked-branch/ref-resolution issue described above: Codex is treating the literal
HEADas a local branch name and constructing the invalid refrefs/heads/HEAD, instead of resolving the current branch or commit correctly. The failure occurs before the worktree is created, so normal Codex development is blocked.The temporary workaround of running
git branch --unset-upstream, creating the worktree, and then restoring the upstream works, but it is disruptive and should not be necessary.@smattei-oai Could you please prioritize investigating and fixing this? Codex should handle a normal branch with an upstream tracking configuration and pass a valid branch/ref or commit to
git worktree add.Same here, windows
Checked it on all other agents and cli, this is Codex bug only.
What version of Codex is running?
Codex App for Windows (MSIX) 26.818.5229.0 — also reproduced on 26.818.3698.0 right before the auto-update. The bug is in the app bundle (
app.asar), not in thecodexcore binary.Which model were you using?
N/A — the failure happens in the worktree-creation dialog before any conversation starts.
What platform is your computer?
Windows 11 Pro 10.0.22631,
git version 2.53.0.windows.2.What steps can reproduce the bug?
git clonequalifies:maintracksorigin/main.…menu → Create permanent worktree → type a name → Create.Dialog log:
The same repository works with a manual
git worktree add, with the App's normal per-thread (temporary) worktrees, and with other tools' worktree features — only this dialog fails.What is the expected behavior?
A new worktree checked out at the project's current
HEAD, as the dialog promises ("Create a new git worktree from HEAD, add it as a project, and keep it until you remove it").What do you see instead?
"Worktree setup failed" at the "Preparing workspace" step, with the log above.
Root cause (read from
app.asar, 26.818.5229.0)The "Create permanent worktree" dialog (i18n id
sidebarElectron.createStableWorktree.*) submits the pending worktree with a hard-coded starting state:The starting-ref resolver then treats the literal
"HEAD"as a branch name:refs/heads/HEADgit rev-parse --abbrev-ref --symbolic-full-name HEAD@{u}— this succeeds whenever the checked-out branch has an upstream (returns e.g.origin/main)git rev-list --left-right --count refs/heads/HEAD...refs/remotes/origin/main→ exit 128 (refs/heads/HEADis not a revision) → treated asnullright-ahead, falls back to{ ref: "refs/heads/HEAD" }git worktree add --detach <path> refs/heads/HEAD→fatal: invalid reference: refs/heads/HEADMinified excerpt (26.818.5229.0):
Shell equivalent of the failing sequence (any fresh clone):
Why it sometimes "works": when the checked-out branch has no upstream (or HEAD is detached), step 2 fails and a later fallback in the same resolver picks
refs/remotes/origin/HEAD(the remote's default branch tip) instead. The worktree then gets created — but from the last-fetchedorigin/<default>, not from the localHEADthe dialog describes, so any unpushed local commits are silently missing. That is a second bug on the same code path.Suggested fix
Don't route the literal
"HEAD"through the branch-name path. Either:git rev-parse --abbrev-ref HEAD, orgit rev-parse HEADwhen detached), orHEAD: never wrap it inrefs/heads/, never queryHEAD@{u}for it, and resolve it to the localHEADcommit.Additional information
mainbranch), #12685 ("Create permanent worktree" doesn't run env setup / isn't listed in Settings → Worktrees), #30954 (local branch as starting branch creates a detached worktree).git worktree add -b <branch> <path> <base>) and add the folder as a project.issues still persists
Still reproducible on macOS Codex App 26.818.41509 (build 6962).
The app executes the following invalid command:
git worktree add --detach <path> refs/heads/HEAD
I reproduced this across multiple unrelated repositories where the current branch tracks an upstream.
I am paying $200 per month for this service, yet this core workflow remains broken across multiple releases. Permanent worktrees are a major reason I use the Codex App, and manually creating and registering worktrees is not an acceptable long-term workaround for a paid product at this price.
The root cause has already been clearly identified in this issue. Please prioritize the fix and provide an update or expected release timeline.
Fix merged this morning all, sorry for the troubles. Looking into getting this released ASAP
Fix should be out by late afternoon today.
This issue is still reproducible in the latest available Codex Desktop release.
Environment
26.818.61809Powered by Codex & OWLmasterorigin/masterError
Creating a permanent worktree still fails immediately:
yes still not working
@smattei-oai ChatGPT 26.820.60940 still not working. Please fix this as soon as possible, as it significantly impacts the user experience with the Codex app.
Confirmed: this issue is still reproducible in the latest Codex App version, 26.820.60940, so the recent release has not resolved it for me either. Creating a permanent worktree still fails with:
fatal: invalid reference: refs/heads/HEAD
This makes a core workflow unusable and significantly impacts the user experience with the Codex App.
I am paying $200 per month for this service, and permanent worktrees are one of the main reasons I use the Codex App. Having to manually create and register worktrees is not an acceptable long-term workaround for a paid product at this price.
The root cause has already been identified in this issue. Please prioritize releasing the fix as soon as possible and provide a concrete update or timeline.
Still reproducible for me on macOS with Codex Desktop 26.820.60940 (latest available).
Repository state is healthy: local branch
mastertracksorigin/master, andgit rev-parse --verify HEADresolves successfully. Manual creation works with:git worktree add <path> -b codex/test HEADHowever, “Create permanent worktree” still fails with:
fatal: invalid reference: refs/heads/HEADThis appears to be isolated to the permanent-worktree UI flow, which is still treating the literal
HEADas a local branch name. Please release the merged fix or provide an updated build/timeline.On it, folks! Sorry for the hold up, we're releasing this as soon as we can (should be today's regular Thursday release).