Hook event for assistant text completion before tool dispatch (preamble invisible to PreToolUse)

Resolved 💬 2 comments Opened May 24, 2026 by jayenashar Closed Jun 24, 2026

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).

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗