[Feature Request] Support selecting base branch when creating git worktree
Open 💬 22 comments Opened Feb 6, 2026 by denysdanyliukboosters
Bug Description
I have a feature request for claude app -> claude code section.
When working with worktree i want to be able to select base branch for this worktree like it was done in codex app. This will be very helpfull.
Environment Info
- Platform: darwin
- Terminal: Apple_Terminal
- Version: 2.1.34
- Feedback ID: 40c08d3e-f600-4585-b62c-5634e7ddaa9f
Errors
[]
22 Comments
Seconding this — particularly important for automated/headless workflows where Claude Code is invoked via
--worktreeto implement GitHub issues.Many repos use a
dev(ordevelop) branch as the integration target rather thanmain. Without a--base-branchoption, worktrees always branch frommain, which means PRs either target the wrong branch or require manual rebasing after the fact. The workaround of ensuring the main worktree hasdevchecked out before invoking Claude is fragile in parallel/concurrent setups.A
--base-branch <branch>flag (or equivalent config in agent definitions viaisolation: worktree) would make this work cleanly without workarounds. TheWorktreeCreatehook can paper over it for now, but a first-class option would be much better.This would be greatly appreciated. I actually wrote a proposal but it was a duplicate of this issue:
Feature Request
When using
claude --worktree(orclaude -w), the new worktree always branches from the default remote branch (e.g.,main). There's no way to create a worktree based on the current branch/HEAD.Use Case
When working on a feature branch and wanting to spin up an isolated Claude session to work on a subtask or related change, it would be useful to branch from the current branch rather than
main. Currently, the workaround is to manually create a worktree with git and then start Claude in it:This loses the automatic cleanup prompt and other niceties of
--worktree.Proposal
Add a
--worktree-baseflag (or similar) to specify the base branch/ref:Alternatively, a simpler approach: make
--worktreebranch fromHEADby default (matchinggit worktree addbehavior) instead of always using the default remote branch. This would be the least surprising behavior for users already on a feature branch.A middle ground could be a setting in
~/.claude/settings.json:Current Behavior
claude --worktreealways branches from the default remote branch (e.g.,origin/main).Expected Behavior
Users should be able to control which branch/ref the worktree is based on, either via a CLI flag or a setting.
Is this the same issue/related, to where when creating a new work tree (in CC) it will create it from head instead of the base branch. I.e. creating a new work tree from master/main should take from that branch, but it seems to take the commits from head instead?
Slightly related. I should be able to choose the base branch that worktrees inherit from. Right now it only inherits from main/master/default branch.
________________________________
From: Christopher Jenkins @.*>
Sent: Wednesday, February 25, 2026 12:51 PM
To: anthropics/claude-code @.*>
Cc: Orinks @.>; Comment @.>
Subject: Re: [anthropics/claude-code] [Feature Request] Support selecting base branch when creating git worktree (Issue #23622)
[https://avatars.githubusercontent.com/u/1167793?s=20&v=4]chrisjenx left a comment (anthropics/claude-code#23622)<https://github.com/anthropics/claude-code/issues/23622#issuecomment-3960967415>
Is this the same issue/related, to where when creating a new work tree (in CC) it will create it from head instead of the base branch. I.e. creating a new work tree from master/main should take from that branch, but it seems to take the commits from head instead?
—
Reply to this email directly, view it on GitHub<https://github.com/anthropics/claude-code/issues/23622#issuecomment-3960967415>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AJFLE3EPP5HNKZTYP63EYDT4NXOJ3AVCNFSM6AAAAACUGNSW3OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTSNRQHE3DONBRGU>.
You are receiving this because you commented.Message ID: @.***>
+1 to this feature request. This bit me a few times today when I was expecting claude --worktree to add worktrees from the feature branch it was invoked from.
+1 👍
exactly what i wanted to ask for.
I need this too
+1. The desktop app has a similar issue when selecting the base branch https://github.com/anthropics/claude-code/issues/23626.
Built a skill for now. Claude's smart enough to just use git fundamentals.
https://skills.sb28.ai/cc-worktree-workaround
Additional use case: non-origin remote feature branches
I frequently work on long-lived feature branches tracked on non-origin remotes (e.g.
upstream/feat/perf-database).EnterWorktreealways branches from HEAD, which points tomain— not the feature branch I need.Current workaround
This loses session integration (automatic CWD switch, cleanup prompt,
ExitWorktreesupport).Proposed
baseparameterFor the
EnterWorktreetool:Implementation notes:
git worktree addalready accepts<commit-ish>as the last arg — this is a minimal changegit rev-parse --verify <base>before creationgit fetch <remote>in the error messageExitWorktreeneeds no changes (operates on path, not base)basepreserves current HEAD behaviorFor the CLI
--worktreeflag (related to #27876):This would cover both the tool-level and CLI-level entry points.
I desperately need this feature.
As a workaround, I’m using this hook
And then in the config
Note: On my machine the
$HOMEpath is actually hardcoded, so if the hook doesn’t work try hardcoding the full path. _(I’m not home now, so I can’t test)_I honestly thought that was just the default behaviour.... Cost me two expensive rebases.
Seriously it should be changed to use current branch at least.
Even when making a script, we're pretty limited without relying on hacky tricks.
Need UI in Claude Code Desktop for this.
very anoying.
It seems like this UI is now there, just super flipping buggy, for some reson it misses origin branches sometimes.
+1 for this feature
Thanks @HelloThisIsFlo for sharing the script, seems to work fine.
Added a small change to the script use the worktree name passed in by user
Claude code now natively support setting worktree baseref to local HEAD since 2.1.133
See CHANGELOG https://github.com/anthropics/claude-code/blob/main/CHANGELOG.md:
You can just add this to ~/.calude/settings.json now:
+1 specifically for the Agent tool's
isolation: "worktree"mode — same bug as the CLI--worktreeflag, same fix needed. The thread is mostly framed around CLI invocation; documenting the programmatic-Agent angle here so it isn't lost.Concrete impact from a real session today
Workflow: solo developer, intentional batched-push pattern (
epicbranches commit locally, single push when the whole epic ships). Localmasterwas 23 commits ahead oforigin/master, including 4 shipped feature implementations and aready-for-devtech-spec the Agent was supposed to implement.Spawned an Agent with
isolation: "worktree". The worktree was created fromorigin/master, not local HEAD. Reflog evidence (three worktrees from the session):origin/masterwas at a 6-day-old commit. The Agent's worktree was missing:PULL_REQUEST_TEMPLATE.mdextension the spec requiredNet result: 22 tool calls wasted, no usable output. Even if the Agent had completed within its usage limit, the work would have been unmergeable because it was rooted on a baseline 23 commits behind reality.
Proposed fix (endorsing @dariusrosendahl's earlier shape)
For the Agent tool specifically, an object form on
isolationwould be ergonomic:…and the same
worktree.baseBranchsetting would cover both the CLI flag and the Agent tool.Strong preference for
HEADas the default rather thanorigin/<default-branch>:git worktree add <path>behaviourorigin/mainif they explicitly want the remote baselineThe current default of
origin/<default>is the least-safe option: it silently produces output rooted in stale state without ever surfacing the divergence to the user. At minimum, the Agent tool could refuse to create a worktree if local<branch>is ahead oforigin/<branch>and warn the user — but the cleaner fix is just to base on HEAD.I think the CLI flag still would be very useful.
Sometimes I want to do sub-feature on top of the current HEAD, sometimes I want to start from scratch (origin/HEAD). Editing settings every time is not convenient, CLI flag would work the best here.