[BUG] isolation="worktree" fails on Windows — falsely reports "not in a git repository"
Summary
When spawning subagents with isolation: "worktree" on Windows 11, Claude Code fails to detect the git repository and falls back to running without worktree isolation — even though the working directory is a valid git repo.
Error Message
Cannot create agent worktree: not in a git repository and no
WorktreeCreate hooks are configured. Configure WorktreeCreate/WorktreeRemove
hooks in settings.json to use worktree isolation with other VCS systems.
Followed by fallback: Not a git repo — spawning without worktree isolation.
Steps to Reproduce
- Open Claude Code in a valid git repository on Windows 11
- Use bash as the shell (Git Bash)
- Trigger an Agent tool call with
isolation: "worktree"(e.g., via a framework that spawns subagents with worktree isolation) - The worktree creation fails with the above error, then falls back to no isolation
Environment
- OS: Windows 11 Pro 10.0.26200
- Shell: bash (Git Bash)
- Working directory: Valid git repo (
.git/exists,git statusworks correctly) - Trigger: Agent tool with
isolation: "worktree"parameter
Expected Behavior
Worktree creation should succeed since the CWD is a valid git repository with a .git/ directory present.
Actual Behavior
Claude Code reports "not in a git repository" and skips worktree isolation entirely.
Suspected Cause
Path resolution mismatch on Windows — the spawned subprocess may resolve the working directory differently (e.g., POSIX-style /c/dev/... vs Windows-style C:\dev\...), causing the .git directory existence check to fail.
Workaround
The fallback (running without worktree isolation) works fine functionally. No data loss or execution failure — just loses the isolation benefit.
Related Issues
- #32747 — worktree removal Permission denied on Windows
- #39680 — worktree EEXIST error on Windows
- #34645 — parallel worktree git lock contention on Windows
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗