[BUG] claude -w creates worktree from stale local branch without fetching remote HEAD

Resolved 💬 3 comments Opened Apr 24, 2026 by jrwoolley Closed Apr 28, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] 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

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗