Main branch detection ignores remote HEAD, hardcodes 'main'

Open 💬 6 comments Opened Feb 9, 2026 by golergka

Bug

Claude Code's system prompt injects:

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

However, the repository's remote HEAD is set to staging:

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

Claude Code appears to detect the "main branch" by looking for a branch literally named main or master, rather than checking the remote HEAD (refs/remotes/origin/HEAD). This causes Claude to target PRs at main instead of the actual default branch.

Impact

When asked to create a pull request, Claude targets main (as instructed by its own system prompt) instead of the correct default branch (staging in our case). This requires manual correction every time and has caused PRs to be opened against the wrong branch.

The workaround is adding an explicit override in CLAUDE.md or project memory, but the auto-detection should work correctly in the first place.

Expected behavior

The "Main branch" in the system prompt should reflect the remote's HEAD branch (i.e., the output of git remote show origin | grep "HEAD branch" or the target of refs/remotes/origin/HEAD).

Environment

  • Claude Code version: 2.1.37
  • OS: macOS (Darwin 25.2.0)
  • Git remote HEAD: staging
  • Detected main branch in system prompt: main

View original on GitHub ↗

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