Commit Graph
1 Commits
Author SHA1 Message Date
rabbit-collabandClaude Opus 5.5 21d651cb8e fix: exit hook runners whose parent process is gone
On Windows, Claude Code kills an overrunning hook by killing the bash.exe
wrapper; the node.exe runner underneath survives. If another process still
holds the write end of the runner's stdin (a handle inherited by a process
spawned at the same moment), the runner never sees EOF and waits forever.
Orphaned runners were observed living 3-18 hours.

Add scripts/hooks/hook-watchdog.js and start it from the four hook entry
points (plugin-hook-bootstrap, run-with-flags, posttooluse-dispatcher,
lifecycle-hook-bootstrap). It exits the process when the parent PID is gone
(Windows) or the process was re-parented (POSIX), polled every 2s, or when a
hard deadline passes (330s, above the longest hooks.json timeout, or an
earlier inherited ECC_HOOK_DEADLINE_MS). Timers are unref'd so a finished
hook is never kept alive.

The regression test reproduces the leak with a detached runner whose stdin
write end is held by an unrelated process; it fails without the watchdog
(runner still alive after 8s) and passes with it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 03:08:18 -07:00