[BUG] Worktree cleanup removes .git/worktrees/ entry but leaves .claude/worktrees/ directory, blocking re-creation
Resolved 💬 2 comments Opened Apr 9, 2026 by JacoCheung Closed Apr 10, 2026
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report
- [x] I am using the latest version of Claude Code
What's Wrong?
When exiting a claude -w <name> session with no changes (automatic cleanup), Claude Code removes the git worktree registration (.git/worktrees/<name>/) but fails to remove the actual worktree directory (.claude/worktrees/<name>/).
On the next claude -w <name> with the same name, creation fails because git worktree add finds the directory already exists.
What Should Happen?
Automatic cleanup should either:
- Remove both
.git/worktrees/<name>/and.claude/worktrees/<name>/atomically, OR - On re-creation, detect the orphaned directory and clean it up before calling
git worktree add
Error Messages/Logs
$ claude -w benchmark_only
Error creating worktree: Failed to create worktree: Preparing worktree (new branch 'worktree-benchmark_only')
fatal: '/path/to/repo/.claude/worktrees/benchmark_only' already exists
After the error, the state is:
$ git worktree list
/path/to/repo 633d4e20 [main]
# No linked worktrees shown
$ ls .claude/worktrees/
benchmark_only/ # Directory still exists (orphaned)
$ ls .git/worktrees/
# Empty — git registration was removed
Steps to Reproduce
- In a git repository, run
claude -w benchmark_only - Inside the session, make no changes (no commits, no modified files)
- Exit the session (type
/exitor Ctrl+D) - Claude auto-cleans the worktree (no prompt since there are no changes)
- Run
claude -w benchmark_onlyagain - Error:
fatal: '.claude/worktrees/benchmark_only' already exists
Workaround: manually rm -rf .claude/worktrees/benchmark_only before re-creating.
Claude Model
Opus
Is this a regression?
I don't know
Claude Code Version
2.1.85 (Claude Code)
Platform
Anthropic API
Operating System
Other Linux
Terminal/Shell
Cursor
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗