WorktreeRemove hook not invoked for subagent worktrees (isolation: worktree)
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
WorktreeRemove hooks never fire when a subagent launched with isolation: "worktree" finishes. The worktree directory, git worktree metadata, and branch all linger indefinitely.
WorktreeCreate hooks fire correctly for the same subagent worktrees — the setup side works, just not teardown.
I verified this by replacing my cleanup script with a bare echo "test" >> /tmp/log — still nothing. The hook simply isn't invoked.
What Should Happen?
The WorktreeRemove hook should fire when a subagent worktree session ends, same as it does for EnterWorktree sessions. Without this, worktrees from isolation: "worktree" accumulate under .claude/worktrees/ and require manual cleanup.
Steps to Reproduce
- Configure WorktreeCreate and WorktreeRemove hooks in
.claude/settings.json:
{
"hooks": {
"WorktreeCreate": [
{
"hooks": [
{
"type": "command",
"command": "bash \"$CLAUDE_PROJECT_DIR/scripts/worktree-setup.sh\""
}
]
}
],
"WorktreeRemove": [
{
"hooks": [
{
"type": "command",
"command": "echo \"FIRED\" >> /tmp/worktree-remove.log"
}
]
}
]
}
}
- Launch a subagent with
isolation: "worktree"(via the Task tool in a conversation) - Let the subagent finish (no changes made)
- Check
/tmp/worktree-remove.log— file doesn't exist - Check
.claude/worktrees/— worktree directory still present - Check
git worktree list— stale entry still registered - Check
git branch— worktree branch still exists
Error Messages/Logs
No errors — the hook silently doesn't run. There's nothing to see because it never executes.
Claude Code Version
2.1.53
Platform
Anthropic API (Max)
Operating System
macOS 15.4
Terminal/Shell
Ghostty + zsh
Additional Information
The v2.1.50 changelog says: "Added WorktreeCreate and WorktreeRemove hook events, enabling custom VCS setup and teardown when agent worktree isolation creates or removes worktrees." — emphasis on "agent worktree isolation", which is exactly the isolation: "worktree" codepath that doesn't work.
Also worth noting: the subagent worktrees don't get cleaned up by built-in behavior either. With a custom WorktreeCreate hook, Claude seems to defer cleanup entirely to the WorktreeRemove hook — but since that hook never fires, nothing cleans up.
This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗