claude-code - 💡(How to fix) Fix Hook event for assistant text completion before tool dispatch (preamble invisible to PreToolUse)

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Fix Action

Fix / Workaround

Add a hook event that fires after an assistant text content block finishes streaming and before the next tool call is dispatched — or, equivalently, add a preceding_text (or current_message_text) field to the PreToolUse hook payload containing the assistant text emitted earlier in the same turn.

A. New hook event: AssistantTextComplete — fires after each content_block_stop for a text block, before the next tool_use block is dispatched. Payload includes the completed text and the in-flight message_id.

Workarounds today

RAW_BUFFERClick to expand / collapse

Feature request

Add a hook event that fires after an assistant text content block finishes streaming and before the next tool call is dispatched — or, equivalently, add a preceding_text (or current_message_text) field to the PreToolUse hook payload containing the assistant text emitted earlier in the same turn.

Problem

When the assistant emits preamble text and then calls a tool in the same turn, sidecars/integrations that hook on PreToolUse cannot see that preamble:

  1. The preamble has not yet been flushed to transcript_path when PreToolUse fires — reading the JSONL at that moment returns the prior turn's content.
  2. No hook payload field carries the in-flight assistant text.
  3. PostToolUse / Stop are too late for sidecars that render UI alongside the tool call itself (e.g., a custom UI for AskUserQuestion).

This is especially painful for AskUserQuestion: the model's preamble text often contains the why of the question, but the UI rendering the question can't access it. Users see a question without context.

Hook events checked (none expose in-flight text)

PreToolUse, PostToolUse, UserPromptSubmit, Notification, Stop, SubagentStop, PreCompact, SessionStart, SessionEnd — all receive tool_name/tool_input/transcript_path/session_id, but none carry the assistant message currently being streamed.

Proposed solutions (either would unblock)

A. New hook event: AssistantTextComplete — fires after each content_block_stop for a text block, before the next tool_use block is dispatched. Payload includes the completed text and the in-flight message_id.

B. Augment PreToolUse — add a preceding_text field containing all assistant text content blocks emitted in the current turn before this tool call.

(B) is the smaller change and solves the immediate use case. (A) is more general and would also unblock streaming sidecars, live transcripts, partial-message indexers, etc.

Use cases

  • Sidecar UIs rendering AskUserQuestion with the preamble as context.
  • External logging/observability tools that want to capture assistant reasoning before each tool call.
  • Live transcript mirrors (the existing includePartialMessages SDK request — anthropics/claude-code#41732 — is the SDK-side equivalent).

Workarounds today

  • Prompt the model to embed preamble inside tool_input (e.g., AskUserQuestion description). Brittle, relies on model compliance, doesn't help other tools.
  • Long-running daemon tailing transcript_path. Still races flush timing, and isn't a hook.

Related

  • anthropics/claude-code#41732 — V2 persistent sessions should support includePartialMessages for streaming (SDK-side request for the same underlying signal).

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Hook event for assistant text completion before tool dispatch (preamble invisible to PreToolUse)