claude-code - 💡(How to fix) Fix Worktree exit prompt defaults to 'Keep' — accidental Enter leaves stale worktrees [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#53720Fetched 2026-04-28 06:48:49
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
0
Timeline (top)
labeled ×2commented ×1

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.

Root Cause

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.

RAW_BUFFERClick to expand / collapse

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

extent analysis

TL;DR

Change the default behavior of the worktree removal prompt to require an explicit choice or auto-remove clean worktrees on /exit.

Guidance

  • Consider modifying the prompt to have no default selection, requiring users to actively choose between Keep and Remove.
  • Implement an opt-out flag or setting, such as --keep-worktree or worktree.removeOnExit: false, to allow users to customize the behavior.
  • If possible, auto-remove clean worktrees on /exit to reduce cleanup burden on users.
  • Review related issues (#46557, #48751, #26725) to ensure a comprehensive solution.

Example

No code snippet is provided as the issue does not contain specific code references.

Notes

The solution may vary depending on the implementation details of the claude tool and its configuration options. The proposed changes aim to improve the user experience and reduce the accumulation of orphaned worktrees.

Recommendation

Apply a workaround by requiring an explicit choice on the worktree removal prompt, as this is the cheapest fix and improves the user experience.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

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.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Worktree exit prompt defaults to 'Keep' — accidental Enter leaves stale worktrees [1 comments, 2 participants]