Worktree exit prompt defaults to 'Keep' — accidental Enter leaves stale worktrees
Description
When a session that was started in a worktree (claude --worktree <name>) ends via /exit, a prompt appears asking whether to keep or remove the worktree. The default selection is Keep, so a single accidental Enter (e.g. the same Enter that submitted /exit, or muscle-memory while moving on to the next thing) leaves the worktree on disk.
Over a working day this accumulates orphaned worktrees that have to be cleaned up manually.
Steps to reproduce
claude --worktree foofrom any git repo- Do some work and commit it (or do nothing)
- Type
/exitand press Enter - The prompt appears; press Enter once more without thinking
- Worktree and branch remain in
~/.claude/worktrees/<repo>/foo/
Expected behavior
One of:
- Default to Remove when the worktree is in a clean state (no uncommitted changes, branch merged or pushed). Keeping should be the deliberate choice, not the accidental one.
- Auto-remove on
/exitfor clean worktrees, with an opt-out flag or setting (--keep-worktree, orworktree.removeOnExit: falsein settings). - At minimum, require an explicit choice — no default selection on the prompt, so Enter does nothing until the user actively picks Keep or Remove.
Option 3 is the cheapest fix; option 2 is the best long-term UX since the worktree's whole point is ephemeral isolated work.
Why this is worth fixing
The cleanup burden falls entirely on the user, and the prompt's UX actively encourages the bad outcome — the path of least resistance (slamming Enter to dismiss prompts) is exactly the path that creates the mess. This compounds for users who run many parallel worktree sessions per day, which is the audience --worktree was built for.
Related issues
- #46557 — prompt missing entirely on immediate
/exit(different bug; that's no prompt, this is bad-default prompt) - #48751 — Remove button silently fails after commits + exit prompt sometimes missing (related; this issue is specifically about the default selection when the prompt does appear)
- #26725 — stale worktrees never cleaned up (general background)
Environment
- Platform: darwin
- Use case: multiple parallel
claude --worktree <slug>sessions throughout a working day
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗