Worktree not cleaned up on /exit
Description
When starting Claude Code with -w <name> (worktree mode) and immediately calling /exit, the session exits without prompting to keep or remove the worktree. The worktree and its branch are left behind on disk.
Steps to Reproduce
cdinto a git repo- Run
claude -w test - Once the session starts (worktree is created and entered), type
/exit - Session exits immediately without any worktree cleanup prompt
Expected Behavior
Per the ExitWorktree tool docs: "On session exit, if still in the worktree, the user will be prompted to keep or remove it."
The user should be asked whether to keep or remove the worktree before the session ends.
Actual Behavior
Session exits with no prompt. The worktree directory (~/.claude/worktrees/<repo>/<name>/) and its git branch remain on disk. The user must manually clean up with git worktree remove and git branch -d.
Additional Context
This reportedly worked before hooks were introduced. The /exit command may be taking a code path that bypasses the worktree session cleanup logic.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗