From 9bf85fb97da7df8698a273b30942b72911db3f7b Mon Sep 17 00:00:00 2001 From: Tom Boucher Date: Fri, 20 Mar 2026 10:45:56 -0400 Subject: [PATCH] fix(install): add matcher and timeout to context-monitor hook (#1246) The gsd-context-monitor PostToolUse hook was configured without a matcher or timeout, causing it to fire on every tool use including Read, Glob, and Grep. When multiple Read calls happen in parallel, some hook processes failed with errors. Added matcher: 'Bash|Edit|Write|MultiEdit|Agent|Task' to limit the hook to tools that actually modify context significantly. Added timeout: 10 to prevent hangs. Includes migration logic: existing installations without matcher/timeout get them added on next /gsd:update. --- bin/install.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/bin/install.js b/bin/install.js index 7a130043b..0dc24d554 100755 --- a/bin/install.js +++ b/bin/install.js @@ -4055,14 +4055,36 @@ function install(isGlobal, runtime = 'claude') { if (!hasContextMonitorHook) { settings.hooks[postToolEvent].push({ + matcher: 'Bash|Edit|Write|MultiEdit|Agent|Task', hooks: [ { type: 'command', - command: contextMonitorCommand + command: contextMonitorCommand, + timeout: 10 } ] }); console.log(` ${green}✓${reset} Configured context window monitor hook`); + } else { + // Migrate existing context monitor hooks: add matcher and timeout if missing + for (const entry of settings.hooks[postToolEvent]) { + if (entry.hooks && entry.hooks.some(h => h.command && h.command.includes('gsd-context-monitor'))) { + let migrated = false; + if (!entry.matcher) { + entry.matcher = 'Bash|Edit|Write|MultiEdit|Agent|Task'; + migrated = true; + } + for (const h of entry.hooks) { + if (h.command && h.command.includes('gsd-context-monitor') && !h.timeout) { + h.timeout = 10; + migrated = true; + } + } + if (migrated) { + console.log(` ${green}✓${reset} Updated context monitor hook (added matcher + timeout)`); + } + } + } } }