File feature request: worktree.cleanupOnExit setting (keep/remove/prompt)

Status Open
Maintainer reply None cached
Activity 0 comments · opened Aug 25, 2026

Preflight Checklist

  • [x] I have searched existing requests and this feature hasn't been resolved despite being requested multiple times
  • [x] This is a single feature request

Problem Statement

There is no supported way to make Claude Code always keep a --worktree session's worktree on exit, with no prompt. Today, exiting an interactive worktree session (e.g. via /quit) checks the worktree for pending work and, if any exists, shows a keep-or-remove confirmation every single time. There is no settings.json key, environment variable, CLI flag, or /config option to set a default answer, and no hook can intercept it: WorktreeRemove is explicitly non-blocking ("failures are logged in debug mode only"), and SessionEnd only shows stderr and cannot influence the outcome.

For a workflow where the branch is almost always already pushed and squash-merged by the time the session ends, but occasionally isn't, the prompt is 99% noise and the only unsafe default (auto-remove) is unacceptable for the other 1%: an accidental or scripted dismissal there is unrecoverable data loss. The only way to skip the prompt entirely today is non-interactive -p mode, which is not how interactive sessions run.

This exact request has been filed at least four times and closed each time by the duplicate-detection bot without ever landing a fix, most recently #64509 (closed as a duplicate of #58034, which was itself closed for inactivity after being marked a duplicate of #56349, #53720, and #31969 — #31969 is open but is a much broader, differently-scoped request). Reopening this cleanly rather than adding a fifth closed duplicate.

Proposed Solution

A new settings.json key:

{
  "worktree": {
    "cleanupOnExit": "keep"   // "prompt" (default) | "keep" | "remove"
  }
}
  • "keep" — never prompt, never remove; the worktree and its branch are always left on disk for the user to clean up later (e.g. via their own pruning tooling).
  • "remove" — never prompt, always remove, matching the request in #64509.
  • "prompt" — current default behavior, unchanged.

This would resolve both directions of the request in one setting, matching the shape already proposed independently in #64509 and #58034.

References

  • #64509 — same request, "remove" direction, closed as duplicate
  • #58034 — same request, "keep" direction (removeOnExit: "never"), closed for inactivity
  • #56349 — related: no project-level opt-out for the exit prompt
  • #53720 — related: default-to-keep-on-accidental-Enter concern
  • #31969 — broader, open, related but different scope

View original on GitHub ↗