Feature request: Add last_assistant_message to PreToolUse hook input

Open 💬 0 comments Opened Jun 28, 2026 by y-rokutan

Summary

PreToolUse hook input lacks the current assistant message text. Stop and SubagentStop hooks already have last_assistant_message, but PreToolUse does not. This makes it impossible for PreToolUse hooks to inspect the assistant's text output that precedes the tool call in the same message.

Use Case

We use PreToolUse hooks as safety gates that verify protocol compliance (e.g., checking that the assistant output required XML tags before issuing tool calls). Currently, the only way to access assistant text is via transcript_path, but the current message's text block is not yet written to the transcript when PreToolUse fires — it is written only after the entire message (text + tool calls) is processed.

Evidence

We instrumented a debug PreToolUse hook that reads transcript_path at hook fire time:

  • PreToolUse fires at 08:03:06.187Z with transcript_lines=933
  • The text block (containing protocol tags) has timestamp 08:03:05.661Z but is at line 933 — not yet written to the transcript file
  • The text block and tool_use block are part of the same assistant message, and the entire message is flushed to the transcript atomically after PreToolUse completes

This means a PreToolUse hook cannot inspect the assistant's text output that accompanies the tool call, regardless of timing.

Proposed Change

Add last_assistant_message (or equivalent, e.g. assistant_text) to the PreToolUse hook input JSON, containing the text content blocks from the current assistant message. This field already exists on Stop/SubagentStop hooks, so the data is available in the CC process.

Workaround

Without this field, PreToolUse gates that need to verify assistant text must either:

  1. Accept that the first non-exempt tool call per turn is always denied (the denial flushes the transcript, making the text visible on retry)
  2. Move text verification entirely to Stop hooks (which have last_assistant_message but cannot block individual tool calls)

Both workarounds add latency and complexity that would be unnecessary if the text were passed directly.

Environment

  • Claude Code v2.1.195
  • Hooks: PreToolUse (command type)

View original on GitHub ↗