What
A worktree is a separate working copy of a git repository that Claude can work in. The ExitWorktree tool leaves it, either keeping it or removing it.
- Removing a worktree is now refused while a background task or agent may still be working there, unless
discard_changesis set. The message says "Nothing was removed" and names the running task. - The tool's instructions now say
discard_changesalso removes the worktree from under any task still running, so it should be set only after you confirm. - The instructions now say removing also deletes the branch, unless a hook made the worktree or git refuses, in which case the branch is not deleted.
- The result carries a sandbox note that is added to what the tool returns.
Why
This guards against a worktree being deleted while a background agent is still working in it and losing that work. Claude should now ask you before forcing the removal.
Names in the bundleExitWorktree
The entry above is what we published on the day. These lines were added later, as Anthropic's own pages caught up, and they sit beside the original rather than replacing it.
Added since
A small documentation edit on Hooks reference touched a line naming ExitWorktree after this was published.
For a `claude remote-control` cleanup, Claude Code runs your hook without prompting you. `ExitWorktree` refuses to remove a hook-created worktree unless the call passes [`discard_changes: true`](https://code.claude.com/docs/en/agent-sdk/ty…hooks see the edit
Confirmed since
Anthropic's documentation has since written up ExitWorktree, on Claude Code changelog.
* Changed `ExitWorktree` to ask before removing a worktree that may hold unsaved work; refused in don't-ask mode or with nobody to answer, unless an allow rule, auto or bypass permissions mode allows itchangelog see the edit
Two sources agreeTwo things we can check say the same as this entry.
Anthropic's documentation agrees
Anthropic's documentation has since written up ExitWorktree, on Claude Code changelog.
Anthropic's release notes agree
Changed ExitWorktree to refuse removing a worktree while a background subagent or shell command may still be running in it, unless Claude…