The "Workroom That Looked Empty" Was Deleted Without Asking — Claude Code v2.1.304 Plugs the Worktree Auto-Delete Commit Loss
Claude Code auto-manages git worktrees as disposable workrooms — but a pitfall let it delete branches and commits without asking. v2.1.304 restores the pre-deletion confirmation and adds a review-depth choice. Here are the self-defense measures and the rescue procedure.
Spinning up a "disposable workroom" for parallel tasks — the move to make git worktree the default for agent workflows has gained momentum over the past few weeks in both Codex and Claude Code. But it turns out that the mechanism meant to "clean up automatically once you're done" harbored a pitfall: it could silently delete your work, commits and all. Anthropic has restored this behavior to require confirmation in Claude Code v2.1.304 (released October 19, 2026).
The tool misread the signal to clean up
claude --worktree is designed to carve out a dedicated work tree and branch, do its work there, and delete them at the end of the session if they're no longer needed. It was supposed to ask "may I delete this?" when there was still something left behind. But the end-of-session check failed to correctly distinguish certain states, and in some cases it skipped the confirmation and deleted the tree and branch outright.
The deleted commits become "orphans" that no branch references. There's a grace period until Git's periodic garbage collection runs, but once that cleanup is done they can no longer be recovered. Uncommitted changes, meanwhile, are lost the moment the tree disappears. What should have been "just tidying up a room that looked empty" turns out to be an accident in which a half-written draft was still sitting on the desk.
Which state tripped the mine
The confirmation was skipped when the HEAD at exit (the position you're currently viewing) had moved off the branch Claude created. There are two cases, laid out below.
| State | What happened |
|---|---|
| detached HEAD (pointing directly at a commit rather than a branch) | The tree and branch could be deleted without the confirmation dialog appearing |
| Switched to a branch other than the one Claude created | Likewise, could be deleted without confirmation |
In other words, "switching branches mid-task" or "going to look at a specific commit and ending up in detached HEAD" — operations that happen perfectly routinely during development — became mines in their own right.
What v2.1.304 fixed
This fix corrects the state check performed before deletion so that a confirmation is always inserted when work remains. Alongside it, the safety check for rm -r was extended to also cover mounted drives and top-level folders. It plugs paths where that same confirmation had not previously been shown. If you use worktree sessions daily and run into situations where you switch branches or end up in detached HEAD, updating sooner rather than later is recommended.
Self-defense that works right now, and rescue after the fact
Two approaches are known for protecting yourself before and after updating.
- Put your own lock in place: temporarily release it with
git worktree unlock <path>, then re-lock it with a custom reason string usinggit worktree lock --reason "keep" <path>. Claude Code's cleanup routine only releases locks whose reason matches theclaude (agent|session) …form. If you lock with a different reason, it's treated as "a lock I didn't write myself" and the tree is preserved. - Search after it's gone: before garbage collection runs, you can enumerate orphaned commits with
git fsck --unreachable --no-reflogsand rescue them by reattaching a branch withgit branch rescue/name <hash>. Be aware that it becomes a race against the clock.
Note that the behavior of auto-deleting a tree when it is "empty (0 changes, 0 new commits) and an unnamed session" is, by design, correct operation. For a work tree you don't want deleted, the safe move is to give it a name or draw a line with the lock described above.
The "review depth" option that landed alongside it
The same update added a stage for choosing review depth to GitHub-integrated Code Review. Organization owners can set three levels — Quick (lighter), Standard (default), and Deep (deeper) — across the whole organization, and can also specify them individually per repository. There's also a new setting to make every repository in a GitHub organization (including ones added later) a review target in one go. This makes it easier to tune the balance between review load and missed issues for each team.
In addition, /auto-mode-setup, which reads your project and recent sessions to adapt auto mode to your environment, became available on Bedrock, Vertex, Foundry, and others, and on Pro/Max plans a warning now appears when resuming a conversation you'd left idle would consume a large chunk of your 5-hour usage allowance.
The default of convenience had swung toward destruction
Worktree auto-management is a handy mechanism that takes the cleanup after parallel work off your hands. But this incident showed that the default of the "cleanup" kindness could, depending on conditions, tip toward deleting your work. The more the territory we hand over to agent judgment expands, the more the design of where to stop "destructive operations that run silently" — confirmation dialogs and fail-closed checkpoints — gets weighed with the same importance as productivity. The more you reach for the benefits of automation, the more it pays to mark the things you can't afford to lose with a lock or a name.
References: Claude Code changelog (official) / Major Updates in Claude Code v2.1.303 to v2.1.304 (Classmethod) / Claude Code's --worktree Could Delete a Branch on Exit Without Asking. 2.1.304 Fixes It (DEV) / Claude Code deletes clean worktrees on exit without asking. git worktree lock stops it. (DEV) / Claude Code 2.1.304 release notes (ai-tldr)


