fix(prompt-hook): skip Claude Code task notifications (#1832) - #1884
Open
danusha2345 wants to merge 1 commit into
Open
danusha2345 wants to merge 1 commit into
danusha2345 wants to merge 1 commit into
Conversation
) Claude Code's UserPromptSubmit hook also fires for the `<task-notification>…</task-notification>` blocks the host injects as `user` messages when a background agent finishes. Those blocks are long machine text full of identifier-shaped tokens, so they pass the structural gate and the whole blob is sent to codegraph_explore as the query — a 3.5s median (7.4s max) stall on the blocking path, on text the user never typed. Recognize a prompt that consists solely of one task-notification envelope (leading/trailing whitespace allowed) and exit before any project lookup, gate or explore work. A prompt that merely mentions the marker, or has text around it, is still treated as a user prompt. Fixes colbymchenry#1832 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Symptom
Claude Code's
UserPromptSubmithook also fires for the<task-notification>…</task-notification>blocks the host injects asusermessages when a backgroundAgentfinishes. Those blocks are long machine text (task IDs,toolu_*IDs, scratchpad paths, an agent's prose summary about code), so they pass the structural gate on the merits and the whole blob is sent tocodegraph_exploreas the query. Reported cost: 3.5 s median / 7.4 s max on the blocking path, on text the user never typed (36% of the hook's firings in the reporter's history).Fix
isTaskNotification(prompt)insrc/directory.ts: true only when the entire prompt (modulo leading/trailing whitespace) is one<task-notification>…</task-notification>envelope.codegraph prompt-hookreturns immediately after parsing stdin when the predicate matches — before telemetry, the gate, project lookup or any explore work. No output is written.[Unreleased]→### Fixes.Verification
npx tsc --noEmit -p tsconfig.json→ exit 0.npx vitest run __tests__/frontload-hook.test.ts→ 42 passed (newdescribe('system task notifications (#1832)')covers the envelope with/without surrounding whitespace and multi-line body, and the negative cases: marker inside a question, trailing text, other tag, plain prompt).dist/bin/codegraph.js prompt-hookfrom an indexed repo: a<task-notification>payload (Claude Code's{"prompt","cwd"}JSON on stdin) prints 0 bytes and exits 0 in ~0.26 s; a normal structural prompt still prints the<codegraph_context>block.Fixes #1832
🤖 Generated with Claude Code