Feature request: Add last_assistant_message to PreToolUse hook input
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.187Zwithtranscript_lines=933 - The text block (containing protocol tags) has timestamp
08:03:05.661Zbut 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
PreToolUsecompletes
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:
- Accept that the first non-exempt tool call per turn is always denied (the denial flushes the transcript, making the text visible on retry)
- Move text verification entirely to
Stophooks (which havelast_assistant_messagebut 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)