claude-code - 💡(How to fix) Fix [DOCS] Worktree cleanup docs omit failed-removal safety behavior for gitignored and in-progress files

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

Documentation Type

Incorrect/outdated documentation

Documentation Location

https://code.claude.com/docs/en/worktrees

Section/Topic

Clean up worktrees and related worktree-removal guidance

Current Documentation

The worktrees page currently says:

  • Uncommitted changes, untracked files, or new commits exist: Claude prompts you to keep or remove the worktree. Keeping preserves the directory and branch so you can return later. Removing deletes the worktree directory and its branch, discarding any uncommitted changes, untracked files, and commits

It also says:

  • Non-interactive runs: worktrees created with --worktree alongside -p are not cleaned up automatically since there is no exit prompt. Remove them with git worktree remove

The agent view docs also say:

Deleting removes the session from agent view and cleans up its worktree, including any uncommitted changes in it, so push or commit work you want to keep before deleting.

Worktrees are removed when you delete the session that created them. If a session ended without cleaning up, list leftover entries with git worktree list in the project directory and remove each with git worktree remove <path>.

What's Wrong or Missing?

Changelog v2.1.143 includes this user-visible fix:

Worktree cleanup no longer falls back to rm -rf when git worktree remove fails, preventing loss of gitignored or in-progress files

The current docs still describe worktree removal as if deletion is unconditional once the user chooses remove, but they do not explain the failure behavior when git worktree remove cannot complete.

That leaves two important gaps:

A. Failed cleanup safety behavior is undocumented

The docs do not say that Claude now avoids a destructive filesystem-level fallback when Git refuses to remove a worktree. Users reading the current wording could reasonably assume Claude will always delete the directory once they choose removal.

B. Protection for gitignored and in-progress files is not stated

The fix specifically protects worktrees that still contain gitignored files or other in-progress local state when git worktree remove fails. That safety guarantee is not reflected anywhere in the worktree cleanup docs.

Suggested Improvement

Update the worktree cleanup guidance to distinguish between a successful Git removal and a failed one.

Suggested wording for worktrees.md:

When you choose to remove a worktree, Claude first uses git worktree remove. If Git refuses to remove the worktree, Claude leaves the directory in place instead of force-deleting it, so gitignored files and other in-progress local changes are not lost.

Add a short note near the manual cleanup guidance:

If git worktree remove fails, inspect the worktree contents before retrying or deleting it manually. This commonly happens when the worktree still contains local state Git will not remove safely.

Optionally mirror the same note in agent-view.md and the desktop worktree cleanup guidance so all session-deletion surfaces describe the same safety behavior.

Impact

High - Prevents users from using a feature

Additional Context

Affected Pages:

PageLine(s)Context
https://code.claude.com/docs/en/worktrees85-91Explains cleanup outcomes but not what happens when git worktree remove fails
https://code.claude.com/docs/en/agent-view176, 420Says deleting a session cleans up or removes the worktree, but not that failed Git removal now preserves the directory
https://code.claude.com/docs/en/desktop289Desktop guidance tells users to remove/archive worktrees but does not mention failed-removal safety

Total scope: 3 pages affected

Source: Changelog v2.1.143

Exact changelog entry:

Worktree cleanup no longer falls back to rm -rf when git worktree remove fails, preventing loss of gitignored or in-progress files

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 [DOCS] Worktree cleanup docs omit failed-removal safety behavior for gitignored and in-progress files