[FEATURE] BeforeResponse Hook
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
When Claude Code makes confident but incorrect factual claims about infrastructure, APIs, or system behavior, there's no way to catch them before they reach the user. The only mechanism is CLAUDE.md rules ("verify before responding"), but the model that generates the claim is the same one that would verify it — so it doesn't work reliably.
In ops/infrastructure work, a wrong claim acted on can cause hours of debugging. User attention is the scarce resource — extra latency from verification is a worthwhile tradeoff when correctness matters.
Proposed Solution
Add a BeforeResponse hook that runs before Claude's text output is displayed. The hook receives the response text on stdin, can modify it (stdout), flag it, or block it (non-zero exit).
Example config in .claude/settings.json:
{
"hooks": {
"BeforeResponse": [{
"matcher": { "minLength": 100 },
"command": "python3 verify_response.py"
}]
}
}
This enables: fact-checking via a second LLM call, confidence tagging, response filtering, and redaction — deterministically via code, not advisory prompt instructions.
Alternative Solutions
- CLAUDE.md rules saying "verify before responding" — doesn't reliably work, model self-validates
- Subagent review after the fact — user already saw and potentially acted on the wrong info
- OpenClaw has
message_sendinghooks for outbound channel messages, but Claude Code has no equivalent for TUI output
Priority
Medium - Would be very helpful
Feature Category
API and model interactions
Use Case Example
Over a 3-day ops session, Claude confidently stated "opus-4-6 and 4-7 share the same Anthropic infrastructure, so if one is
overloaded the other will be too — don't bother adding 4-6 as a fallback." The user accepted this and configured only haiku as
fallback. When asked "are you sure?", Claude doubled down instead of verifying.
Later investigation revealed: the Anthropic API error doesn't distinguish model-specific vs provider-wide overloads, and different
model versions can run on different clusters. Adding 4-6 as an intermediate fallback costs zero latency (attempts are immediate, no
wait between fallbacks) and could have prevented multiple failed requests during a 45-minute Anthropic outage earlier that day.
This is one example from a session that produced multiple similar incidents — wrong assumptions about plugin manifest filenames,
incorrect claims about SSH process persistence, and unverified assertions about cron scheduler behavior — each costing 30-60
minutes of debugging. The common pattern: Claude states something as fact, user acts on it, it turns out wrong, recovery is
expensive.
A BeforeResponse hook running a verifier prompt ("cite evidence or mark as assumption") would catch these before the user sees
them. The extra latency (~2-3 seconds for a haiku verification call) is trivial compared to the hours lost acting on wrong
information. User attention is the scarce resource, not tokens or latency.
Additional Context
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗