Problem
Claude Code creates git worktrees under ~/.claude-worktrees/ for parallel task execution but has no mechanism to clean them up if a session ends without proper cleanup (crash, interruption, or bug in teardown). There is also no garbage collection on subsequent session starts — each session is completely unaware of what previous sessions left behind.
This leaves behind:
- Full repo copies on disk (wasting space)
- Git branches that cannot be deleted even with
git branch -D because git refuses to delete a branch checked out in any worktree
- Worktree refs in
.git/worktrees/ that persist indefinitely
The only way a user discovers these is by stumbling into the cannot delete branch error, at which point they have to manually git worktree remove or rm -rf the directory, then git worktree prune to clean up refs.
Reproduction
- Use Claude Code on a project where it creates a worktree (parallel task execution)
- End the session (or have it crash/interrupt)
- Observe that
~/.claude-worktrees/<project>/<worktree-name> persists
- Try to delete the branch:
git branch -D <worktree-name> → fails with error: cannot delete branch used by worktree
Expected behavior
- Claude Code should clean up worktrees on session exit
- On session start, Claude Code should scan for and prune stale worktrees from previous sessions
- At minimum, a
claude --cleanup command or similar should exist
Environment
- macOS (Darwin 25.2.0)
- Claude Code (CLI)
- Found a stale worktree from January 15, 2026 that was never cleaned up across dozens of subsequent sessions
Problem
Claude Code creates git worktrees under
~/.claude-worktrees/for parallel task execution but has no mechanism to clean them up if a session ends without proper cleanup (crash, interruption, or bug in teardown). There is also no garbage collection on subsequent session starts — each session is completely unaware of what previous sessions left behind.This leaves behind:
git branch -Dbecause git refuses to delete a branch checked out in any worktree.git/worktrees/that persist indefinitelyThe only way a user discovers these is by stumbling into the
cannot delete brancherror, at which point they have to manuallygit worktree removeorrm -rfthe directory, thengit worktree pruneto clean up refs.Reproduction
~/.claude-worktrees/<project>/<worktree-name>persistsgit branch -D <worktree-name>→ fails witherror: cannot delete branch used by worktreeExpected behavior
claude --cleanupcommand or similar should existEnvironment