Skip to content

fix(prompt-hook): skip Claude Code <agent-message> subagent hand-backs (#2184) - #2190

Closed
danusha2345 wants to merge 1 commit into
colbymchenry:mainfrom
danusha2345:fix/2184-prompt-hook-agent-message
Closed

danusha2345 wants to merge 1 commit into
colbymchenry:mainfrom
danusha2345:fix/2184-prompt-hook-agent-message

Conversation

@danusha2345

Copy link
Copy Markdown
Contributor

Fixes #2184

Claude Code hands a subagent's report back to the parent session as a UserPromptSubmit prompt wrapped in <agent-message from="…">…</agent-message>. The prompt hook treated it as user input and ran a full codegraph_explore on the whole report. That is slow on a multi-KB prose query — past Claude Code's 30 s hook timeout in the report — and when it does finish, the injected context is matched from words in the report, not from anything the user asked.

Change

Tests

  • Unit cases for isAgentMessage (full envelope, surrounding whitespace, no attributes; a user question quoting it, trailing text, <agent-messages> and an unclosed envelope are not skipped).
  • End-to-end: the hook injects context for a report that names indexed symbols, and prints nothing for the same report inside <agent-message>.
  • These fail on main (the hook injects explore output for the envelope) and pass with the fix.

Measured

On a 375-file index, an 8 KB report took the hook 60 s on main; wrapped in <agent-message> it now exits in 0.17 s.

Not in this PR

Hook time grows faster than prompt length (500 chars → 2.3 s, 2 KB → 13 s, 4 KB → 40 s on that index): explore runs a separate search for every query term, with no cap on how many, re-reads SELECT DISTINCT name FROM nodes per term in the fuzzy/substring passes, and re-splits the whole query for every candidate path in scorePathRelevance. So a ~4 KB prose prompt typed by a user can still pass the 30 s timeout. Happy to follow up separately.

🤖 Generated with Claude Code

Claude Code delivers a subagent's report to the parent session as a
UserPromptSubmit prompt wrapped in <agent-message from="…">…</agent-message>.
The prompt hook treated it as user input and ran a full codegraph_explore
on the whole report, which is slow on a multi-KB prose query (past the
30 s hook timeout in the report) and injects context unrelated to the
user's question.

Add isAgentMessage next to isTaskNotification (colbymchenry#1832) with the same rule:
only a prompt that is entirely the envelope is skipped, so a user question
that mentions the tag still goes through the gate.

Fixes colbymchenry#2184

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@colbymchenry

Copy link
Copy Markdown
Owner

Thank you! This landed in #2281: your commit carried onto current main with its authorship kept, plus a changelog credit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

prompt-hook runs on Claude Code <agent-message> subagent hand-backs and hits the 30s hook timeout

2 participants