[Bug] Claude struggles to check if in git worktrees

Resolved 💬 3 comments Opened Oct 22, 2025 by ariccio Closed Oct 26, 2025

Bug Description
Claude code seems to frequently struggle to check if it's in a worktree. This is a common developer workflow, and probably should recieve some attention to prevent future annoyance from other devs

Environment Info

  • Platform: darwin
  • Terminal: Apple_Terminal
  • Version: 2.0.25
  • Feedback ID: aff697ed-35c8-4041-a3be-ffb48144310d

Claude has struggled enough to reason about git worktrees that I've actually directed it in my instructions to always check if it's in a worktree and explicitly state it to ensure it's in the context. This helps a lot, but I find claude still struggles a lot to use git to reliably check if it's in a worktree. I have had to have the following interaction a few dozen times over the past few weeks:

```claude-code-session

▗ ▗ ▖ ▖ Claude Code v2.0.25
Haiku 4.5 · API Usage Billing
▘▘ ▝▝ /Users/alexanderriccio/Documents/GitHub/DeeDee-explore-build-automation
⎿  SessionStart:startup hook succeeded:

Launch an Explore subagent to understand our MCP config and management archtecture in this repo

⎿  UserPromptSubmit hook succeeded: End of Session ID: a3d3982b-c99f-48eb-bd08-519c899be851

⏺ I'll start by checking if I'm in a worktree, then launch an Explore subagent to understand the MCP config and management architecture.

⏺ Bash(if git rev-parse --git-path HEAD > /dev/null 2>&1; then if git rev-parse --show-superproject-working-tree | grep -q .; then echo "✓ IN WORKTREE"; else echo "✓ IN MAIN REPO"; fi; fi)
⎿  ✓ IN MAIN REPO
⎿  Interrupted · What should Claude do instead?

loud buzzer noise WRONG

⎿  UserPromptSubmit hook succeeded: End of Session ID: a3d3982b-c99f-48eb-bd08-519c899be851

⏺ Bash(if [ -f .git ]; then echo "✓ IN WORKTREE (file .git found)"; elif [ -d .git ]; then echo "✓ IN MAIN REPO (dir .git found)"; else echo "✗ UNKNOWN"; fi)
⎿  ✓ IN WORKTREE (file .git found)

/feedback

Issues using a single command line tool would probably usually not warrant a bug report. HOWEVER, `git` is one of the most commonly used developer tools on the planet, so it's surprising that it's struggling so often to use it! The obvious reason is that git worktrees are an uncommonly-used feature, and honestly the main reason I finally got to using them myself was because a tool like claude code was able to let me work in several worktrees at once.

In the meantime I'll probably hack together some scripting to work around this, but it's still worth a report.

View original on GitHub ↗

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