claude-code - 💡(How to fix) Fix [FEATURE] BeforeResponse Hook

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

Later investigation revealed: the Anthropic API error doesn't distinguish model-specific vs provider-wide overloads, and different

Code Example

{
  "hooks": {
    "BeforeResponse": [{
      "matcher": { "minLength": 100 },
      "command": "python3 verify_response.py"
    }]
  }
}
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing requests and this feature hasn't been requested yet
  • 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_sending hooks 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

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING