[FEATURE] Worktree creation should sync from remote default branch, not local

Status Fixed / completed
Maintainer reply None cached
Activity 13 comments · opened Feb 26, 2026 · closed Aug 17, 2026

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:

  1. Default behavior: Always pull from the remote default branch when creating a worktree (safest option, ensures freshness).
  2. 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

  1. A colleague merges several pull requests into main on the remote.
  2. 2. My local main branch is now behind the remote by several commits.
  3. 3. I open Claude Code Desktop and ask it to create a new worktree to work on a new feature.
  4. 4. Claude Code creates the worktree from my stale local main — without warning me.
  5. 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.

View original on GitHub ↗

12 Comments

github-actions[bot] · 6 months ago

Found 2 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/28495
  2. https://github.com/anthropics/claude-code/issues/18437

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

webbertakken · 6 months ago

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.

henrikra · 5 months ago

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.

angela1031 · 5 months ago

Is this resolved?

webbertakken · 5 months ago

Does not seem resolved. Still see many PRs from CLAUDE users that come in with conflicts right off the bat.

cookshelf-katie · 5 months ago

Would also love to see this

lewis-agentimise · 4 months ago

+1 for this

TomasTokaMrazek · 3 months ago

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.

henrikra · 3 months ago

I think this is working now. I havent had problems anymore

TomasTokaMrazek · 3 months ago

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.

{
  "hooks": {
    "SessionStart": [
      {
        "matcher": "",
        "hooks": [
          {
            "type": "command",
            "command": "git fetch origin --prune"
          }
        ]
      }
    ]
  }
}
goleary · 1 month ago

fascinating to me that this is not the default behavior. does anyone want to create worktrees off stale local main by default?

webbertakken · 1 month ago

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.

Showing cached comments. Read the full discussion on GitHub ↗