Hook event: PreModelResponse (inject context before model plans)
Summary
Claude Code's hook system currently has four events: SessionStart, PreToolUse, PostToolUse, and PreCompact. None of these fire between when a user submits a prompt and when the model begins generating its response. This gap prevents injecting pre-computed context that the model needs for its first planning step.
Use Case
I maintain a directive/knowledge-base system with gate hooks that enforce loading context-specific directives before code operations. The current flow is:
- User submits prompt ("fix the null pointer in FooService")
- Model plans and emits a tool call (e.g.,
Read FooService.java) - PreToolUse hook fires, detects missing Java directives, blocks the call
- Model reads the block message, calls
load_bundleto load directives - Model retries the original tool call
- PreToolUse hook passes (markers now present)
This costs 2-6 extra turns per gate miss (activity directives, tool knowledge, repo context can cascade). Each round-trip burns tokens for the block message, the load call, the response, and the retry.
I've built a gate predictor that can determine what directives a prompt will need before the model sees it, using session history, project context, and keyword analysis. The predictor can call load_bundle and have the content ready. But there's no hook event where I can inject that content into the conversation before the model starts planning.
Proposed Event: PreModelResponse (or PrePromptProcess)
Fires after the user's prompt is submitted and before the model begins generating. The hook receives the prompt text and can return:
{
"hookSpecificOutput": {
"hookEventName": "PreModelResponse",
"additionalContext": "Injected system-level context the model sees before planning."
}
}
The additionalContext string would appear as a system message in the model's context, similar to how PreToolUse's additionalContext works but positioned before the model's first response to the prompt rather than alongside a tool call.
Why Existing Events Don't Work
- PreToolUse: fires after the model has already planned and committed to a tool call. The model's initial reasoning doesn't benefit from the injected context. Also requires the model to make a tool call at all; pure-text responses never trigger it.
- PostToolUse: fires after a tool completes; too late for pre-loading.
- SessionStart: fires once at session start, not per-prompt.
- PreCompact: fires before compaction, unrelated.
Impact
Without this event, the only way to pre-load context is the block-retry pattern, which:
- Wastes 2-6 turns of model output per gate miss
- Burns tokens on block messages, retry logic, and duplicate tool calls
- Adds user-visible latency (each blocked call is a full model round-trip)
- Cannot be optimized away by prediction since there's no injection point
With this event, a hook could pre-satisfy all gates in a single synchronous call before the model starts, eliminating the round-trip overhead entirely.