ExitWorktree with action: "remove" reports success but leaves worktree directory and branch on disk

Resolved 💬 1 comment Opened Apr 13, 2026 by xoelop Closed Apr 13, 2026

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 list still shows the worktree as registered
  • The branch created by EnterWorktree is still present in git branch

The session's cwd is correctly restored to the original directory, but nothing is actually cleaned up.

Reproduction

  1. In a git repo, call EnterWorktree with a name (e.g. my-test)
  2. Make a commit on the new branch inside the worktree
  3. Call ExitWorktree with action: "remove" — it will refuse because of uncommitted state / unmerged commits
  4. Call ExitWorktree again with action: "remove" and discard_changes: true
  5. Tool responds: "Exited and removed worktree at .../.claude/worktrees/my-test. Session is now back in ..."
  6. 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 / ExitWorktree tools
  • Git repo with WorktreeCreate hook configured
  • macOS (Darwin 25.2.0), zsh

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗