Worktree exit prompt defaults to 'Keep' — accidental Enter leaves stale worktrees

Resolved 💬 3 comments Opened Apr 27, 2026 by karyandrew Closed Apr 30, 2026

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

  1. claude --worktree foo from any git repo
  2. Do some work and commit it (or do nothing)
  3. Type /exit and press Enter
  4. The prompt appears; press Enter once more without thinking
  5. Worktree and branch remain in ~/.claude/worktrees/<repo>/foo/

Expected behavior

One of:

  1. 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.
  2. Auto-remove on /exit for clean worktrees, with an opt-out flag or setting (--keep-worktree, or worktree.removeOnExit: false in settings).
  3. 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

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗