Branch detection uses init.defaultBranch instead of remote HEAD

Resolved 💬 3 comments Opened Mar 6, 2026 by AdamGoyer Closed Mar 10, 2026

Bug Description

Claude Code's system prompt reports the wrong main branch when the repository's default branch differs from git config init.defaultBranch.

Steps to Reproduce

  1. Have a global git config: git config --global init.defaultBranch main
  2. Clone a repository whose default branch is NOT main (e.g., grove)
  3. Start a Claude Code session

Expected Behavior

The system prompt should report:

Main branch (you will usually use this for PRs): grove

Actual Behavior

The system prompt reports:

Main branch (you will usually use this for PRs): main

This causes PR creation to fail when using --base main (the branch doesn't exist or has no commits relative to HEAD).

Root Cause

Claude Code appears to be reading git config init.defaultBranch (a global setting for new repos) instead of git symbolic-ref refs/remotes/origin/HEAD (the actual default branch for this repo).

Evidence from the affected repo:

$ git config --get init.defaultBranch
main

$ git symbolic-ref refs/remotes/origin/HEAD
refs/remotes/origin/grove

$ git remote show origin | grep "HEAD branch"
HEAD branch: grove

Impact

  • PR creation fails with: No commits between main and <branch>
  • Users must manually remember to use --base grove instead of --base main
  • Workaround: document the correct branch in CLAUDE.md, but the system prompt still shows the wrong value

Suggested Fix

Prefer git symbolic-ref refs/remotes/origin/HEAD (or git remote show origin | grep 'HEAD branch') over git config init.defaultBranch when determining the main branch for PR targeting.

View original on GitHub ↗

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