[BUG] Windows: bash non-functional inside auto-created worktrees — unrecoverable deadlock

Resolved 💬 9 comments Opened Mar 28, 2026 by qraveh Closed Apr 29, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Bug On Windows 11, Claude Code automatically creates git worktrees under .claude/worktrees/<name>/ for each conversation. Bash is completely non-functional inside these worktrees — every command returns exit code 1 with no output (including echo, pwd, git, etc.). This creates a deadlock: Claude Code auto-creates a worktree before the agent gets control Bash doesn't work in the worktree There is no setting to disable worktree isolation The agent cannot run any commands, including gh issue create to report this bug Cleanup scripts don't prevent recurrence — next conversation creates a new broken worktree Environment OS: Windows 11 Home 10.0.26200 Shell: Git Bash (C:\Program Files\Git\bin\bash.exe) via CLAUDE_CODE_GIT_BASH_PATH Claude Code: Desktop app (latest as of 2026-03-28) Git repo: Normal repo, no submodules, no special config Reproduction Open Claude Code on Windows with a git repository Start a new conversation (worktree auto-created) Any Bash tool call → exit code 1, empty output Expected Either bash should work in worktrees, or there should be a setting to disable worktree isolation. Workaround needed A settings.json option like "worktree": false or "isolation": "none" to opt out of worktree creation entirely.

What Should Happen?

This bug can be addressed at multiple layers — any one of them would break the deadlock:

(1) Opt-out for automatic worktree creation
Sessions that don't need isolation should be able to opt out. A settings.json flag like "worktreeIsolation": false (global or per-project) would prevent the worktree from being created at all. Currently there is no such option, so users on broken configurations are stuck with no escape hatch.

(2) Bash should fail loudly, not silently
When bash is non-functional (e.g., due to a damaged git worktree from a prior crash), the Bash tool currently returns exit code 1 with empty output — no error message, no diagnostic. Claude cannot distinguish "command returned nothing" from "bash itself is broken." The tool should surface a clear error (e.g., "bash process failed to start" or "working directory not accessible") so the agent can detect the problem immediately rather than silently continuing.

(3) Git auto-healing on session startup
When Claude Code creates a new worktree and detects that the git state is damaged (stale worktree registrations under .git/worktrees/, missing HEAD refs, locked directories from prior crashes), it should attempt to self-heal before starting the session — pruning stale registrations, removing orphaned worktree dirs — rather than inheriting a broken environment. Alternatively, a pre-session health check that warns the user and aborts cleanly would be far better than a silently broken session.

Error Messages/Logs

This is actually the most telling part — there are no logs, which is the bug itself:

Error Messages / Logs
Bash tool output (every command, including echo "test")
Exit code 1
(no output, no stderr, no error message)

What Claude Code shows
Nothing diagnostic — the tool call simply fails with exit code 1 and an empty result. There is no indication that bash itself failed to start vs. the command returning an error.

What is NOT present (but should be)
No "bash failed to start" message
No "working directory inaccessible" message
No "worktree is damaged" warning at session startup
No startup-time health check output
Accumulated side-effects from prior crashed sessions
Each failed session leaves behind silent damage with no warnings:

Worktree directories under .claude/worktrees/ locked by lingering processes
Stale registrations under .git/worktrees/
Orphan branches under refs/heads/claude/
These compound across sessions — each new conversation inherits the broken state
Worktree name from this session
elegant-dijkstra (C:\SelectiveMirror\.claude\worktrees\elegant-dijkstra)

Environment variable set
"CLAUDE_CODE_GIT_BASH_PATH": "C:\\Program Files\\Git\\bin\\bash.exe"

Steps to Reproduce

Minimal reproduction (single session)
Install Claude Code on Windows 11 with Git Bash (C:\Program Files\Git\bin\bash.exe)
Set CLAUDE_CODE_GIT_BASH_PATH in ~/.claude/settings.json pointing to Git Bash
Open any git repository in Claude Code (desktop app)
Start a new conversation — Claude Code auto-creates a worktree under .claude/worktrees/<random-name>/
Ask Claude to run any bash command (e.g., echo test, pwd, git status)
Result: Exit code 1, no output
Deadlock reproduction (multiple sessions)
Reproduce the above
Note: the worktree directory is now locked by the Claude Code process
Close the conversation (not the app) and attempt cleanup (e.g., git worktree prune, delete dirs)
Start a new conversation in the same repo
A new worktree is created — bash fails again
Result: Each new session creates a new broken worktree; cleanup does not prevent recurrence
Compounding state (across many sessions)
Repeat the above multiple times (as happens naturally over days of use)
Inspect .git/worktrees/ — stale registrations accumulate
Inspect .claude/worktrees/ — locked directories accumulate
Inspect git branch — orphan claude/<name> branches accumulate
Result: Repo git state degrades with each session; no automatic cleanup occurs
Confirmed NOT caused by
The git repository itself (works fine outside worktrees)
The sync-to-drive.sh PostToolUse hook (bash fails before any hook runs)
A specific Claude Code version (persists across updates)
how to validate that this is indeed reproduces the bug?

Validation / Confirming the Bug is Reproduced
After following the steps above, confirm the bug is active with these checks:

  1. Confirm bash is broken inside the worktree

Ask Claude to run:

echo "hello"

Expected (broken): Exit code 1, no output
Expected (healthy): hello

  1. Confirm bash works outside the worktell (proving it's worktree-specific)

Open a terminal and run:

cd C:\<your-repo>
"C:\Program Files\Git\bin\bash.exe" -c "echo hello"

Expected: hello — bash itself is fine, the issue is specific to the worktree context inside Claude Code

  1. Confirm the worktree was auto-created

ls C:\<your-repo>\.claude\worktrees\
git worktree list

Expected: A new named directory (e.g., elegant-dijkstra) and a matching entry in git worktree list

  1. Confirm orphan branches accumulate across sessions

git branch | grep claude/

Expected: One claude/<name> branch per failed session

  1. Confirm cleanup does not prevent recurrence

Run git worktree prune and delete .claude\worktrees\, then start a new Claude Code conversation.
Expected: A new broken worktree is created immediately — the bug reproduces on every session.

Claude Model

Not sure / Multiple models

Is this a regression?

I don't know

Last Working Version

A version without an autocreated git worktree?

Claude Code Version

Version 1.1.9310 (cb30ac)

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

PowerShell

Additional Information

_No response_

View original on GitHub ↗

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