Skip to content

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

@jayenashar

Description

@jayenashar

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

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions