Stale worktrees are never cleaned up
Open 💬 8 comments Opened Feb 18, 2026 by atrimble-synmax
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 -Dbecause 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 witherror: 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 --cleanupcommand 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
This issue has 8 comments on GitHub. Read the full discussion on GitHub ↗