fix: skip UserPromptSubmit hooks for slash commands (#734)

This commit is contained in:
jnjpng
2026-01-28 17:51:56 -08:00
committed by GitHub
parent 0b8fe9661b
commit 2f203b7e08
3 changed files with 12 additions and 6 deletions

View File

@@ -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<HookExecutionResult> {
// 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,

View File

@@ -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 = {

View File

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