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

  1. In a git repository where master is the main branch, check out a feature branch (e.g., cplat-789-ws-tsconfig-build)
  2. Start Claude Code in that directory
  3. Observe the gitStatus section 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

View original on GitHub ↗

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