Worktree not cleaned up on /exit

Resolved 💬 2 comments Opened Apr 11, 2026 by jacwright Closed May 24, 2026

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

  1. cd into a git repo
  2. Run claude -w test
  3. Once the session starts (worktree is created and entered), type /exit
  4. 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.

View original on GitHub ↗

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