Worktree auto-deleted on exit when work is committed

Resolved 💬 2 comments Opened Feb 22, 2026 by virafb Closed Mar 22, 2026

Problem

When using EnterWorktree to create a worktree, the worktree is automatically deleted on session exit if there are no uncommitted changes. This means if you commit your work properly during the session, the worktree gets cleaned up without prompting — even though you may be in the middle of a multi-session project.

Expected Behavior

The cleanup logic should check for commits on the worktree branch that don't exist on the parent branch, not just uncommitted changes. If the worktree branch has diverged from the base, the user should always be prompted before deletion.

Steps to Reproduce

  1. EnterWorktree to create a new worktree
  2. Make changes and commit them
  3. Exit the Claude Code session
  4. Worktree is auto-deleted without prompting, losing the branch context

Current Workaround

Manage worktrees manually with git worktree add outside of Claude Code's lifecycle management.

Suggested Fix

Before auto-deleting, check:

git log <base-branch>..<worktree-branch> --oneline

If there are any commits, prompt the user to keep or remove — same as the uncommitted changes path.

View original on GitHub ↗

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