--worktree creates worktree from origin/HEAD instead of current branch

Resolved 💬 3 comments Opened Mar 31, 2026 by ZelinBobyard Closed Mar 31, 2026

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

  1. Clone a repo where origin/HEAD points to main but you regularly work on dev
  2. Checkout dev: git checkout dev
  3. Run claude --worktree
  4. The new worktree is based on origin/HEAD (main), not dev

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 dev integration branch — changes merged to dev but not yet to main are 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 dev as working branch, main as origin/HEAD

View original on GitHub ↗

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