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.
This commit is contained in:
Tom Boucher
2026-03-20 10:45:56 -04:00
parent 40993dd8b0
commit 9bf85fb97d

View File

@@ -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)`);
}
}
}
}
}