Main branch detection incorrectly identifies current branch as main branch
Resolved 💬 2 comments Opened Jan 8, 2026 by icholy Closed Jan 8, 2026
Description
When Claude Code generates the gitStatus section of its system prompt, the "Main branch" detection sometimes incorrectly identifies the currently checked-out feature branch as the main branch instead of the actual main/master branch.
Steps to Reproduce
- In a git repository where
masteris the main branch, check out a feature branch (e.g.,cplat-789-ws-tsconfig-build) - Start Claude Code in that directory
- Observe the
gitStatussection in the system prompt
Expected Behavior
The gitStatus should report:
Main branch (you will usually use this for PRs): master
Actual Behavior
The gitStatus reports:
Main branch (you will usually use this for PRs): cplat-789-ws-tsconfig-build
This causes agents to create PRs targeting the wrong branch.
Impact
When using Claude Code in automation scenarios (e.g., xagent orchestration), this bug causes PRs to be opened against feature branches instead of the actual main branch, requiring manual intervention to fix.
Environment
- Claude Code CLI (via
npx @anthropic-ai/claude-code) - The bug was observed when Claude Code was run from within a Docker container where a repository volume was mounted with a feature branch checked out
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗