hooks.json ships without default timeouts - ctx upgrade silently reverts manual timeout patch

Author: LunascielCreated Sep 30, 2026Updated Sep 30, 2026

Summary

hooks.json ships without any timeout fields on its hook entries. After ctx upgrade restores upstream files, every manually added per-hook timeout is gone, and a hung hook (e.g. an infinite loop in a PreToolUse matcher) blocks the host CLI indefinitely with no permission prompt to escape.

Context

We hit a real infinite loop in a different hook script (check-destructive-rm.sh): a bash ${var/${BASH_REMATCH[0]}/repl} replacement treated a regex match as a glob, the replace became a no-op, and the loop never terminated. Because the context-mode plugin's pretooluse.mjs chain had no timeout in hooks.json, the CLI hung for 1+ minutes until manual kill. Our mitigation was patching "timeout": 30 onto all 11 hook entries in the plugin cache (~/.claude/plugins/cache/context-mode/context-mode/1.0.136/hooks/hooks.json) - but ctx upgrade overwrites that patch on every update.

Proposal

Either (or both):

  1. Ship sensible default timeout values in hooks.json itself (e.g. 10-30s per hook entry), so upgrades keep them.
  2. Add a process.exit-style safeguard / hard watchdog inside pretooluse.mjs so a stuck matcher chain terminates itself instead of hanging the host.

Why it matters

Defense-in-depth for foreign plugin code: a hang in any hook should degrade to a skipped/blocked hook, not a frozen CLI.

Environment: plugin 1.0.136, Linux, Claude Code host.