claude-code - 💡(How to fix) Fix EnterWorktree branches from origin/<default> instead of HEAD [4 comments, 4 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#54940Fetched 2026-05-01 05:50:27
View on GitHub
Comments
4
Participants
4
Timeline
10
Reactions
0
Author
Timeline (top)
commented ×4labeled ×4mentioned ×1subscribed ×1

The EnterWorktree tool's documentation states it creates a new worktree "with a new branch based on HEAD", but in practice it branches from origin/<default-branch> — even when local master/main is ahead of the remote and HEAD is on the local branch (not detached).

Root Cause

The EnterWorktree tool's documentation states it creates a new worktree "with a new branch based on HEAD", but in practice it branches from origin/<default-branch> — even when local master/main is ahead of the remote and HEAD is on the local branch (not detached).

Fix Action

Fix / Workaround

Workarounds

Code Example

git checkout master
   git log --oneline origin/master..master   # shows N local-only commits
   git rev-parse HEAD master origin/master   # HEAD == master, both ahead of origin/master

---

git reflog show <new-worktree-branch>

---

250ec80 worktree-deploy_scripts@{1}: branch: Created from origin/master
RAW_BUFFERClick to expand / collapse

Summary

The EnterWorktree tool's documentation states it creates a new worktree "with a new branch based on HEAD", but in practice it branches from origin/<default-branch> — even when local master/main is ahead of the remote and HEAD is on the local branch (not detached).

Repro

  1. In a clean checkout, ensure local master is ahead of origin/master:
    git checkout master
    git log --oneline origin/master..master   # shows N local-only commits
    git rev-parse HEAD master origin/master   # HEAD == master, both ahead of origin/master
  2. Have Claude Code invoke EnterWorktree (e.g. ask it to "start a worktree").
  3. Inspect the new branch:
    git reflog show <new-worktree-branch>

Expected

Per the tool's docstring, the new branch should be created from HEAD (i.e. local master).

Actual

The reflog shows the branch was created from origin/master:

250ec80 worktree-deploy_scripts@{1}: branch: Created from origin/master

Concrete numbers from my repro:

  • Local master HEAD: 63ecb8d (committed 2026-04-30 10:02)
  • Worktree directory created: 2026-04-30 10:22 (20 minutes later)
  • Worktree branch base: 250ec80 = origin/master (not HEAD)

HEAD was not detached; I had committed directly to local master and those commits had not yet been pushed.

Impact

Surprising and silently destructive-feeling: any unpushed work on local master is invisible to the new worktree. The user has to discover the discrepancy and git merge --ff-only master after the fact.

Workarounds

  • git fetch && git push before creating worktrees, so origin/master == master.
  • Create the worktree manually (git worktree add ... master) and pass path= to EnterWorktree.

Suggestion

Either:

  1. Make the actual behavior match the docs (branch from HEAD), or
  2. Document that the base is origin/<default>, and expose a setting / parameter to override it.

Environment

  • Platform: darwin 24.2.0
  • Model: claude-opus-4-7[1m]

extent analysis

TL;DR

The EnterWorktree tool should be modified to branch from the local HEAD instead of origin/<default-branch> to match its documentation.

Guidance

  • Verify the current behavior by checking the reflog of the new worktree branch using git reflog show <new-worktree-branch>.
  • To mitigate the issue, use the workaround of running git fetch && git push before creating worktrees to ensure origin/master is up-to-date with local master.
  • Consider creating the worktree manually using git worktree add ... master and passing path= to EnterWorktree as an alternative workaround.
  • To fix the issue, the EnterWorktree tool's code should be updated to branch from the local HEAD instead of origin/<default-branch>.

Example

No code snippet is provided as the issue does not include the EnterWorktree tool's code.

Notes

The fix may require modifications to the EnterWorktree tool's code, and the workaround may not be suitable for all use cases.

Recommendation

Apply the workaround of running git fetch && git push before creating worktrees, as it is a simple and effective solution to ensure origin/master is up-to-date with local master.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING