Worktree auto-deleted on exit when work is committed
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
EnterWorktreeto create a new worktree- Make changes and commit them
- Exit the Claude Code session
- 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.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗