[FEATURE] Worktree creation should sync from remote default branch, not local
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
When creating a Git worktree via the Claude Code Desktop App, the worktree is initialized from the local main branch rather than the remote one (or whichever branch is configured as the default).
This means that if the local main branch is behind the remote, the new worktree starts from a stale state. Unless I explicitly remember to instruct Claude to run git pull beforehand, I end up working on outdated code without any warning.
Proposed Solution
When creating a worktree, Claude Code should automatically fetch and sync from the remote default branch before initializing the worktree. This could be implemented in one of two ways:
- Default behavior: Always pull from the remote default branch when creating a worktree (safest option, ensures freshness).
- 2. Opt-in setting: Add a configuration option (e.g., in Claude Code settings) to enable automatic remote sync on worktree creation, for users who prefer explicit control.
Alternative Solutions
Currently, I work around this by manually instructing Claude to run git pull from main on the worktree branch. However, this is a manual step that is easy to forget, and there is no prompt or warning from Claude Code to remind me to do it. A built-in sync step would eliminate this friction entirely.
Priority
Medium - Would be very helpful
Feature Category
CLI commands and flags
Use Case Example
- A colleague merges several pull requests into
mainon the remote. - 2. My local
mainbranch is now behind the remote by several commits. - 3. I open Claude Code Desktop and ask it to create a new worktree to work on a new feature.
- 4. Claude Code creates the worktree from my stale local
main— without warning me. - 5. I spend time working on code that is missing recent changes, potentially causing merge conflicts or duplicated work later.
With this feature, Claude Code would automatically pull the latest changes from the remote before creating the worktree, ensuring I always start from an up-to-date state.
Additional Context
This issue is particularly relevant for teams where main moves quickly (e.g., CI/CD environments with frequent merges). Starting from a stale branch is a common source of unnecessary merge conflicts and wasted effort.
A similar pattern exists in other tools: for example, git worktree add itself does not auto-pull, but many IDE integrations (e.g., JetBrains, VS Code Git extensions) prompt or auto-fetch before branching. Claude Code could follow the same convention to provide a safer default experience.
Showing cached comments. Read the full discussion on GitHub ↗
12 Comments
Found 2 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
That would be great.
It would also prevent some of the issues we're having now where agents are not always committing the right files from worktrees to the PRs, ultimately causing loss of complete fixes and features.
Hitting this too. We want new worktrees to always start from a fresh remote main, but haven't found a clean solution. Would love to see this handled natively.
Is this resolved?
Does not seem resolved. Still see many PRs from CLAUDE users that come in with conflicts right off the bat.
Would also love to see this
+1 for this
This is singlehandedly the most frustrating thing for me while working with Claude Code. I've set up remote dev machine with
--spawn worktree, so I rotate sessions quite frequently because of iterative development and I always, always forget to start the session with asking to fetch remote origin.I think this is working now. I havent had problems anymore
For me it doesn't, in last two days I started several sessions and half of them failed with the prompt due to old origin default branch.
However I've found out that hooks exist and they are perfect place to solve this. And it is quite trivial.
fascinating to me that this is not the default behavior. does anyone want to create worktrees off stale local main by default?
It's not just with worktrees. It generally never considers syncing local main with orgin/main at all or misses it a lot of the time.