claude-code - 💡(How to fix) Fix Worktree branch created from wrong base branch and stale commit [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#45316Fetched 2026-04-09 08:08:10
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
labeled ×3cross-referenced ×1
RAW_BUFFERClick to expand / collapse

Describe the bug

When Claude Code creates a worktree, it does not use the repository's configured default branch from GitHub, and it does not fetch the latest state before branching. The result is a worktree that starts from the wrong branch and is missing recent commits.

Steps to reproduce

  1. Have a repository where the default branch in GitHub is set to develop (not main)
  2. Let Claude Code create a worktree (e.g. via an agentic task)
  3. Observe the base branch and commit the worktree was created from

Expected behavior

  • Claude Code reads the repository's GitHub default branch (e.g. via git remote show origin or GitHub API) and uses it as the base
  • Claude Code runs git fetch origin before creating the worktree branch, so the base is always up to date

Actual behavior

  • Worktree was branched from main instead of the actual GitHub default branch (develop)
  • Worktree was ~2 commits behind the actual tip of the intended base branch

Environment

  • OS: Windows 11
  • Shell: bash (Git Bash)
  • Claude Code version: latest

🤖 Reported via Claude Code CLI

extent analysis

TL;DR

Update Claude Code to correctly read the default branch from GitHub and fetch the latest state before creating a worktree.

Guidance

  • Verify that Claude Code is configured to use the GitHub API or git remote show origin to determine the default branch of the repository.
  • Check the Claude Code documentation for any options or settings that control the branch used when creating a worktree.
  • Consider adding a step to the workflow that runs git fetch origin before Claude Code creates the worktree to ensure the latest commits are available.
  • Test the worktree creation process with a repository that has a default branch other than main to confirm the issue is resolved.

Example

No explicit code example is provided, as the issue implies a configuration or workflow change rather than a code modification.

Notes

The solution assumes that Claude Code has the capability to read the default branch from GitHub and fetch the latest state. If this is not the case, additional development or changes to the tool may be required.

Recommendation

Apply a workaround by adding a git fetch origin step before worktree creation and configuring Claude Code to use the correct default branch, as upgrading to a fixed version is not explicitly mentioned as an option.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

  • Claude Code reads the repository's GitHub default branch (e.g. via git remote show origin or GitHub API) and uses it as the base
  • Claude Code runs git fetch origin before creating the worktree branch, so the base is always up to date

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING