From 2f203b7e08e4bf2800125ec051581990a56b6c2a Mon Sep 17 00:00:00 2001 From: jnjpng Date: Wed, 28 Jan 2026 17:51:56 -0800 Subject: [PATCH] fix: skip UserPromptSubmit hooks for slash commands (#734) --- src/hooks/index.ts | 6 ++++++ src/tests/hooks/executor.test.ts | 2 +- src/tests/hooks/integration.test.ts | 10 +++++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/hooks/index.ts b/src/hooks/index.ts index 3950443..f6b9b71 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -139,6 +139,7 @@ export async function runPermissionRequestHooks( /** * Run UserPromptSubmit hooks before processing a user's prompt * Can block the prompt from being processed + * Skips execution for slash commands (e.g., /help, /clear) */ export async function runUserPromptSubmitHooks( prompt: string, @@ -147,6 +148,11 @@ export async function runUserPromptSubmitHooks( conversationId?: string, workingDirectory: string = process.cwd(), ): Promise { + // Skip hooks for slash commands - they don't trigger agent execution + if (isCommand) { + return { blocked: false, errored: false, feedback: [], results: [] }; + } + const hooks = await getHooksForEvent( "UserPromptSubmit", undefined, diff --git a/src/tests/hooks/executor.test.ts b/src/tests/hooks/executor.test.ts index 0f42635..e094555 100644 --- a/src/tests/hooks/executor.test.ts +++ b/src/tests/hooks/executor.test.ts @@ -184,7 +184,7 @@ describe.skipIf(isWindows)("Hooks Executor", () => { test("LETTA_AGENT_ID is not set when agent_id is not provided", async () => { const hook: HookCommand = { type: "command", - command: "echo \"agent_id:${LETTA_AGENT_ID:-empty}\"", + command: 'echo "agent_id:${LETTA_AGENT_ID:-empty}"', }; const input: PreToolUseHookInput = { diff --git a/src/tests/hooks/integration.test.ts b/src/tests/hooks/integration.test.ts index 1f2f89a..f53f33b 100644 --- a/src/tests/hooks/integration.test.ts +++ b/src/tests/hooks/integration.test.ts @@ -405,12 +405,12 @@ describe.skipIf(isWindows)("Hooks Integration Tests", () => { expect(result.blocked).toBe(true); }); - test("receives prompt and command flag in input", async () => { + test("skips hooks for slash commands", async () => { createHooksConfig({ UserPromptSubmit: [ { matcher: "*", - hooks: [{ type: "command", command: "cat" }], + hooks: [{ type: "command", command: "echo 'should not run'" }], }, ], }); @@ -423,9 +423,9 @@ describe.skipIf(isWindows)("Hooks Integration Tests", () => { tempDir, ); - const parsed = JSON.parse(result.results[0]?.stdout || "{}"); - expect(parsed.prompt).toBe("/clear"); - expect(parsed.is_command).toBe(true); + // Hooks should not run for slash commands + expect(result.blocked).toBe(false); + expect(result.results).toHaveLength(0); }); });