From 4395b2ecf9aa200004884f0bce350f123c010511 Mon Sep 17 00:00:00 2001 From: Tom Boucher Date: Sat, 21 Mar 2026 14:08:32 -0400 Subject: [PATCH] fix: use BeforeTool hook event for Gemini CLI instead of PreToolUse Gemini CLI uses BeforeTool (not PreToolUse) for pre-tool hooks, matching the existing pattern where AfterTool is used instead of PostToolUse. The prompt injection guard hook was hardcoded to PreToolUse, causing Gemini CLI to log "Invalid hook event name: PreToolUse" on startup. Apply the same runtime-conditional mapping used for post-tool hooks, and update the uninstall cleanup to iterate both event names. Co-Authored-By: Claude Opus 4.6 (1M context) --- bin/install.js | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/bin/install.js b/bin/install.js index d4ded0b27..c80e2abec 100755 --- a/bin/install.js +++ b/bin/install.js @@ -3214,24 +3214,26 @@ function uninstall(isGlobal, runtime = 'claude') { } } - // Remove GSD hooks from PreToolUse (prompt injection guard) - if (settings.hooks && settings.hooks.PreToolUse) { - const before = settings.hooks.PreToolUse.length; - settings.hooks.PreToolUse = settings.hooks.PreToolUse.filter(entry => { - if (entry.hooks && Array.isArray(entry.hooks)) { - const hasGsdHook = entry.hooks.some(h => - h.command && h.command.includes('gsd-prompt-guard') - ); - return !hasGsdHook; + // Remove GSD hooks from PreToolUse and BeforeTool (Gemini uses BeforeTool) + for (const eventName of ['PreToolUse', 'BeforeTool']) { + if (settings.hooks && settings.hooks[eventName]) { + const before = settings.hooks[eventName].length; + settings.hooks[eventName] = settings.hooks[eventName].filter(entry => { + if (entry.hooks && Array.isArray(entry.hooks)) { + const hasGsdHook = entry.hooks.some(h => + h.command && h.command.includes('gsd-prompt-guard') + ); + return !hasGsdHook; + } + return true; + }); + if (settings.hooks[eventName].length < before) { + settingsModified = true; + console.log(` ${green}✓${reset} Removed prompt injection guard hook from settings`); + } + if (settings.hooks[eventName].length === 0) { + delete settings.hooks[eventName]; } - return true; - }); - if (settings.hooks.PreToolUse.length < before) { - settingsModified = true; - console.log(` ${green}✓${reset} Removed prompt injection guard hook from settings`); - } - if (settings.hooks.PreToolUse.length === 0) { - delete settings.hooks.PreToolUse; } } @@ -4117,7 +4119,8 @@ function install(isGlobal, runtime = 'claude') { } // Configure PreToolUse hook for prompt injection detection - const preToolEvent = 'PreToolUse'; + // Gemini and Antigravity use BeforeTool instead of PreToolUse for pre-tool hooks + const preToolEvent = (runtime === 'gemini' || runtime === 'antigravity') ? 'BeforeTool' : 'PreToolUse'; if (!settings.hooks[preToolEvent]) { settings.hooks[preToolEvent] = []; }