Exit dialog warns about uncommitted files in worktree that was removed during the session
Summary
When a Claude Code session starts inside a git worktree and the worktree is removed during the session (e.g. via git worktree remove directly, or via a skill like /ship that does this as part of its cleanup flow), the /exit confirmation dialog still warns about uncommitted files even though the worktree no longer exists. The file count appears to be sourced from a different location (likely ~/.claude's own dirty state) but presented under "Exiting worktree session," which is misleading.
Repro
- Start a Claude Code session with cwd inside a git worktree (e.g.
~/code/.worktrees/myrepo-featureor in my case~/code/cous/.claude/worktrees/<sprint>). - During the session, run
git worktree remove <path>(or invoke a skill that does this — e.g./ship's Step 9 cleanup). - Continue using the session.
git worktree listconfirms the worktree is gone and the directory has been deleted. - Type
/exit.
Expected: dialog notices the worktree is already gone and either exits silently or shows a benign "session ending" message.
Actual: dialog shows:
Exiting worktree session
You have 15 uncommitted files. These will be lost if you remove the worktree.
> 1. Keep worktree Stays at /Users/matt/code/cous/.claude/worktrees/<sprint>
2. Remove worktree All changes and commits will be lost.
The path it offers to "Keep" no longer exists. The "15 uncommitted files" appear to be counted from ~/.claude (memory/plans/settings.json churn) rather than the worktree. The "All changes and commits will be lost" wording is alarming when in fact the worktree was already cleanly removed and pushed earlier in the session.
Impact
- The standard "ship a sprint then exit" flow produces a scary warning right at the end, even when everything has been merged to
mainand pushed toorigin. - Counting files from a different repo than the warning text references makes it hard for the user to verify nothing is actually at risk without dropping into a shell.
Suggested fix
Before rendering the warning, check that the session's recorded worktree path still exists on disk and is still listed in git worktree list for the parent repo. If the worktree is gone, skip the dialog (or render a much milder "session ending" notice). The dirty-file count, if shown, should be sourced from the same repo the warning references — not from ~/.claude.
Environment
- macOS, darwin 23.6.0
- Claude Code CLI
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗