claude-code - 💡(How to fix) Fix Exit dialog warns about uncommitted files in worktree that was removed during the session [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#54537Fetched 2026-04-30 06:42:56
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
labeled ×3

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.

Root Cause

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.

Code Example

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.
RAW_BUFFERClick to expand / collapse

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

  1. Start a Claude Code session with cwd inside a git worktree (e.g. ~/code/.worktrees/myrepo-feature or in my case ~/code/cous/.claude/worktrees/<sprint>).
  2. During the session, run git worktree remove <path> (or invoke a skill that does this — e.g. /ship's Step 9 cleanup).
  3. Continue using the session. git worktree list confirms the worktree is gone and the directory has been deleted.
  4. 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 main and pushed to origin.
  • 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

extent analysis

TL;DR

Check if the worktree path exists before rendering the exit warning dialog to avoid misleading messages about uncommitted files.

Guidance

  • Verify the worktree removal by checking if the path still exists on disk and is listed in git worktree list for the parent repo.
  • If the worktree is gone, skip the exit warning dialog or render a mild "session ending" notice instead.
  • Ensure the dirty-file count is sourced from the same repo the warning references, not from ~/.claude.
  • Consider updating the warning message to reflect the actual state of the worktree and files.

Example

No code snippet is provided as it is not clearly supported by the issue, but the suggested fix implies modifying the exit warning dialog logic to check for worktree existence.

Notes

The issue seems to be related to the Claude Code session not being aware of the worktree removal, leading to misleading warnings. The suggested fix aims to address this by checking the worktree existence before rendering the warning dialog.

Recommendation

Apply workaround: Modify the exit warning dialog logic to check for worktree existence and update the warning message accordingly, as this directly addresses the issue described.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Exit dialog warns about uncommitted files in worktree that was removed during the session [1 participants]