ExitWorktree with action: "remove" reports success but leaves worktree directory and branch on disk
Summary
Calling ExitWorktree with action: "remove" (and discard_changes: true when prompted) returns a success message saying the worktree was removed, but in reality:
- The worktree directory under
.claude/worktrees/<name>is still on disk git worktree liststill shows the worktree as registered- The branch created by
EnterWorktreeis still present ingit branch
The session's cwd is correctly restored to the original directory, but nothing is actually cleaned up.
Reproduction
- In a git repo, call
EnterWorktreewith a name (e.g.my-test) - Make a commit on the new branch inside the worktree
- Call
ExitWorktreewithaction: "remove"— it will refuse because of uncommitted state / unmerged commits - Call
ExitWorktreeagain withaction: "remove"anddiscard_changes: true - Tool responds:
"Exited and removed worktree at .../.claude/worktrees/my-test. Session is now back in ..." - Verify from the main repo:
````
git worktree list
# still shows .claude/worktrees/my-test
ls .claude/worktrees/
# directory still there
git branch
# branch still there
Expected
ExitWorktree with action: "remove" should:
- Run
git worktree remove --force <path> - Delete the branch created by
EnterWorktree - Prune stale worktree metadata
…as documented in the tool description.
Actual
None of the above happens. Only the session cwd is restored.
Workaround
Manual cleanup:
git worktree remove .claude/worktrees/<name> --force
git branch -D <branch>
Or register a WorktreeRemove hook in .claude/settings.json that runs the cleanup. Note: WorktreeRemove fires after the built-in removal and cannot replace it, so the hook has to forcibly re-run git worktree remove --force and git branch -D itself.
Environment
- Claude Code with
EnterWorktree/ExitWorktreetools - Git repo with
WorktreeCreatehook configured - macOS (Darwin 25.2.0), zsh
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗