--worktree creates worktree from origin/HEAD instead of current branch
Bug Description
When running claude --worktree while on a feature branch (e.g., dev), Claude Code creates the worktree from origin/HEAD (the remote default branch, e.g., main) rather than the currently checked-out branch.
Steps to Reproduce
- Clone a repo where
origin/HEADpoints tomainbut you regularly work ondev - Checkout
dev:git checkout dev - Run
claude --worktree - The new worktree is based on
origin/HEAD(main), notdev
Expected Behavior
claude --worktree should default to creating the worktree from the current branch (i.e., HEAD), following the principle of least surprise. Users running the command from a branch naturally expect the worktree to start from where they are.
Actual Behavior
All worktrees created via claude --worktree are based on origin/HEAD. If origin/HEAD points to main but the user is on dev, the worktree is missing all commits that are in dev but not yet in main.
Impact
- Code that exists on the current branch (e.g., feature branches, merged-to-dev code) is absent from the worktree
- This is particularly confusing for repos with a
devintegration branch — changes merged todevbut not yet tomainare silently excluded
Workaround
\\\`bash
Sync local origin/HEAD to match the remote default branch
git remote set-head origin -a
Or manually point origin/HEAD to the desired branch
git remote set-head origin dev
\\\`
This works, but it only helps if the user knows why the worktree is missing code in the first place.
Suggested Fix
Use the current HEAD (or current branch) as the base for the new worktree, instead of origin/HEAD. Alternatively, add a --base <branch> flag to let users specify explicitly.
Note
This is distinct from issue #27876 (feature request for specifying base branch). That request was about flexibility; this is about the default behavior violating the principle of least surprise when the user is already on a non-default branch.
Environment:
- Claude Code CLI (claude --worktree)
- macOS Darwin 24.6.0
- Git repo with
devas working branch,mainasorigin/HEAD
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗