From db5ea78f0343d0c598b379e23fab87eef6104300 Mon Sep 17 00:00:00 2001 From: J8MAE Date: Tue, 26 May 2026 14:00:30 -0600 Subject: [PATCH] fix(RepeatDetection): use stdout+exit 0 to inject as additionalContext MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The UserPromptSubmit hook contract is that the hook can return text via stdout + exit 0, which Claude Code injects as `additionalContext` into the model's context. stderr + exit 2 is the BLOCK pattern — it prevents the prompt from being processed and surfaces the message to the user instead of the model. Before this fix, when RepeatDetection triggered: - The user's repeated prompt was blocked - The "⚠️ REPEAT DETECTION" warning surfaced to the user (who already knows they repeated; they're the one repeating) - The model never received the signal it was supposed to act on After this fix: - The user's prompt is allowed to proceed - The warning is injected into the model's context as additionalContext - The model receives the signal to STOP and re-read the user's message Two-line change: stderr→stdout, exit(2)→exit(0). No other behavior changed. --- Releases/v5.0.0/.claude/hooks/RepeatDetection.hook.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Releases/v5.0.0/.claude/hooks/RepeatDetection.hook.ts b/Releases/v5.0.0/.claude/hooks/RepeatDetection.hook.ts index a1882efc6..060fd6da0 100755 --- a/Releases/v5.0.0/.claude/hooks/RepeatDetection.hook.ts +++ b/Releases/v5.0.0/.claude/hooks/RepeatDetection.hook.ts @@ -106,15 +106,17 @@ function main(): void { // Threshold: 0.6 (60%) similarity triggers warning if (similarity >= 0.6) { - // Output warning to stderr — this gets injected into model context - process.stderr.write( + // UserPromptSubmit hook contract: stdout + exit 0 injects the text as + // additionalContext into the model's context (the desired behavior). + // stderr + exit 2 blocks the prompt and surfaces the warning to the + // user instead of injecting it for the model — wrong direction. + process.stdout.write( `⚠️ REPEAT DETECTION: This message is ${Math.round(similarity * 100)}% similar to the previous message. ` + `The user is likely REPEATING a request you missed. ` + `STOP. Re-read their message carefully. Do NOT proceed with what you were doing before. ` + `Address their ACTUAL request this time.`, ); - // Exit 2 = blocking error, stderr fed to Claude - process.exit(2); + process.exit(0); } process.exit(0);