[Bug] Worktree deletion removes branch with unmerged commits without warning

Status Open
Reported on v2.1.286
Maintainer reply None cached
Activity 0 comments · opened Oct 1, 2026

Bug Description
▎ What happened ▎ I worked in a Claude Code worktree session and committed my work on the worktree's branch. The commit wasn't merged or pushed anywhere else. When I exited the session I chose to delete the worktree. It removed the worktree folder and also deleted the branch, so my only copy of the committed work disappeared from git branch. Nothing warned me that the branch held commits that existed nowhere else. ▎ ▎ The commit could only be recovered with its sha (git branch <name> <sha>). Without the sha the work is effectively lost, and git deletes unreferenced commits for good once garbage collection runs, after about two weeks by default. ▎ ▎ Expected ▎ Deleting a worktree removes the worktree folder only, the way git worktree remove does and keeps the branch. If the branch must be deleted, Claude Code should warn and ask first when it holds commits that aren't on any other branch or remote. ▎ ▎ Also ▎ Choosing "keep" isn't a clean alternative: the worktree stays locked, so removing it later with git worktree remove fails with "cannot remove a locked working tree" until you run git worktree unlock. ▎ ▎ Steps to reproduce ▎ 1. Start a Claude Code session in a worktree. ▎ 2. Commit a change on the worktree branch without merging or pushing it. ▎ 3. Exit the session and choose to delete the worktree. ▎ 4. Run git branch: the branch is gone, and the commit is on no branch.

Environment Info

  • Platform: linux
  • Terminal: xterm-256color
  • Version: 2.1.286
  • Feedback ID: 61272a57-ae27-4632-9c03-f7f0be75ec6f

Errors

[]

View original on GitHub ↗