[DOCS] Worktree cleanup docs omit killed-agent locked `.git/worktrees/` registration cleanup

Open 💬 0 comments Opened Jun 23, 2026 by coygeek

Documentation Type

Missing documentation (feature not documented)

Documentation Location

https://code.claude.com/docs/en/worktrees
https://code.claude.com/docs/en/agent-view
https://code.claude.com/docs/en/sub-agents

Section/Topic

The Clean up worktrees section, plus related agent-view troubleshooting for .claude/worktrees/ filling up.

Current Documentation

The worktrees page currently says:

Worktrees that Claude created for subagents and background sessions are removed automatically once they are older than your cleanupPeriodDays setting, provided they have no uncommitted changes, no untracked files, and no unpushed commits. Worktrees you create with --worktree are never removed by this sweep. While an agent is running, Claude runs git worktree lock on its worktree so that concurrent cleanup cannot remove it. The lock is released when the agent finishes. To clean up a worktree that the sweep keeps, run git worktree remove, adding --force if the worktree has uncommitted changes or untracked files.

Agent view troubleshooting currently says:

Deleting a session in agent view removes the worktree Claude created for it. claude rm keeps a worktree that has uncommitted changes and prints its path. List leftover entries with git worktree list in the project directory and remove each with git worktree remove <path>. See Clean up worktrees.

What's Wrong or Missing?

Claude Code v2.1.187 fixed leaked agent worktree registrations so locked .git/worktrees/ entries from killed agents are now cleaned up automatically.

The docs explain normal lock release when an agent finishes, but they do not describe the killed-agent path. They also do not tell users when automatic cleanup handles stale locked registrations versus when they still need git worktree remove or git worktree prune.

Suggested Improvement

Add a note near the existing lock paragraph in worktrees.md:

If an agent is killed before it can finish normally, Claude cleans up leaked locked .git/worktrees/ registrations automatically. This prevents stale Git worktree locks from blocking later cleanup. If a worktree directory still remains, inspect it with git worktree list and remove it with git worktree remove <path> when safe.

Also update the .claude/worktrees/ is filling up troubleshooting section in agent-view.md to mention that stale locked registrations from killed agents should now be cleaned up automatically before users resort to manual Git cleanup.

Impact

Medium - Makes feature difficult to understand

Additional Context

v2.1.187 changelog context: Fixed leaked agent worktree registrations: locked .git/worktrees/ entries from killed agents are now cleaned up automatically.

Related but not duplicate issues: #63776 covers unlock behavior when an agent finishes normally, and #59591 covers safety when git worktree remove fails.

View original on GitHub ↗