Expose the current turn's assistant text to PreToolUse hooks (validate "text before tool_use")

Open 💬 0 comments Opened Jul 13, 2026 by itboat

What

A PreToolUse hook cannot see the assistant text that precedes the tool_use block in the same turn. The hook stdin payload has session_id, transcript_path, cwd, prompt_id, permission_mode, effort, tool_name, tool_input, tool_use_id — but not the current turn's text blocks. Reading transcript_path doesn't help either: at PreToolUse fire time the current assistant message has not yet been flushed to the transcript (verified empirically — the tail holds only the previous user prompt + attachment records; the assistant turn lands on disk later).

Why it matters

This blocks a whole class of behavioral guardrails that depend on what the model said right before it called a tool. Concrete case: enforcing "the model must write an explanatory preamble/context before calling AskUserQuestion." A hook cannot check whether such a preamble exists, so the only workaround is a reconsideration-deny (deny the first call, allow the retry) — which a model can trivially game by asserting "I already gave the preamble" and re-calling without one.

Request

Include the current turn's preceding text blocks in the PreToolUse hook stdin — e.g. current_message_text (concatenated text blocks before this tool_use), or the pending content array. Even a minimal preceding_text string would unlock preamble / tone / format validation.

Environment

Claude Code CLI, PreToolUse hook, AskUserQuestion matcher.

View original on GitHub ↗