claude-code - 💡(How to fix) Fix [BUG] claude -w creates worktree from stale local branch without fetching remote HEAD [1 comments, 2 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#53025Fetched 2026-04-25 06:14:24
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Author
Timeline (top)
labeled ×4commented ×1
  • The user's CLAUDE.md and memory both specify "Always base worktrees on dev, not main"
  • git remote show origin reports HEAD branch: dev
  • The information needed to do the right thing is available — it's just not used

Error Message

  1. Warn the user that the source branch is behind its remote integration branch

Root Cause

  • The user's CLAUDE.md and memory both specify "Always base worktrees on dev, not main"
  • git remote show origin reports HEAD branch: dev
  • The information needed to do the right thing is available — it's just not used
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

claude -w creates a worktree based on the current local branch without fetching the remote integration branch first. If the source branch is behind the remote HEAD (e.g. origin/dev), the worktree silently inherits stale code. No fetch, no warning.

This caused an entire refactoring session to be built on code missing a recently merged PR. The bug was only discovered late in the session when tests revealed a cache bug that had already been fixed in a PR merged to the integration branch earlier that day.

Steps to Reproduce

  1. Have a repo where origin HEAD is dev
  2. Be on a feature branch that was created from dev a few commits ago
  3. A PR is merged to dev after the feature branch was created
  4. Run claude -w to create a worktree for a new task
  5. The worktree is created from the current branch's HEAD, not from origin/dev
  6. The worktree is missing the code from the merged PR

Expected Behavior

claude -w should either:

  1. git fetch origin and base the worktree on the latest remote HEAD branch (e.g. origin/dev), or
  2. Warn the user that the source branch is behind its remote integration branch

The remote HEAD is discoverable via git remote show origin | grep "HEAD branch".

Actual Behavior

The worktree is silently created from whatever stale state the current local branch is in. No fetch, no rebase, no warning. Work proceeds on outdated code.

Context

  • The user's CLAUDE.md and memory both specify "Always base worktrees on dev, not main"
  • git remote show origin reports HEAD branch: dev
  • The information needed to do the right thing is available — it's just not used

Related Issues

  • #51545 — stale SHA within a session (different: that's about branch advancing after worktree creation)
  • #30070 — wrong remote (different: that's about which remote, not about fetching)

Version

Claude Code 2.1.104, macOS Darwin 25.3.0

extent analysis

TL;DR

The most likely fix is to modify the claude -w command to fetch the remote integration branch before creating a worktree.

Guidance

  • Verify that the remote HEAD branch is correctly identified using git remote show origin | grep "HEAD branch".
  • Consider adding a git fetch origin command before creating a worktree to ensure the latest code is used.
  • Modify the claude -w command to either fetch the remote integration branch or warn the user if the source branch is behind its remote integration branch.
  • Check the CLAUDE.md and memory settings to ensure they are correctly configured to base worktrees on the dev branch.

Example

# Fetch the remote integration branch before creating a worktree
git fetch origin
claude -w

Notes

The provided information suggests that the necessary data to fix the issue is available, but it's not being used. The fix may involve modifying the claude -w command to fetch the remote integration branch or warn the user if the source branch is outdated.

Recommendation

Apply a workaround by adding a git fetch origin command before running claude -w to ensure the latest code is used. This will prevent the creation of worktrees with stale code until a permanent fix is implemented.

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