claude-code - 💡(How to fix) Fix Feature request: PreResponse hook event type [2 comments, 2 participants]

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…
GitHub stats
anthropics/claude-code#53392Fetched 2026-04-26 05:17:01
View on GitHub
Comments
2
Participants
2
Timeline
6
Reactions
0
Timeline (top)
labeled ×3commented ×2closed ×1

Code Example

{
  "hooks": {
    "PreResponse": [
      {
        "hooks": [
          {
            "type": "command",
            "command": ".claude/hooks/pre_response_reminder.sh"
          }
        ]
      }
    ]
  }
}

---

#!/bin/bash
# .claude/hooks/pre_response_reminder.sh
INPUT=$(cat)
MSG=$(echo "$INPUT" | python3 -c "import sys,json; print(json.load(sys.stdin).get('message','').lower())" 2>/dev/null)

# Detect knowledge/how-to questions
if echo "$MSG" | grep -qE '(how would|how do|how to|walk.*through|what.s the best way|explain how)'; then
  echo "REMINDER: Rule Zero — run ./lift find <keywords> before answering this question."
fi
exit 0
RAW_BUFFERClick to expand / collapse

Problem

Hooks currently only fire on tool use (PreToolUse, PostToolUse). This means there's no way to inject guidance or enforcement before the agent starts generating a text response.

Real-world example

I have a CLI toolkit (./lift find) that indexes all available commands, skills, and workflows. My CLAUDE.md says "run ./lift find before doing anything." Hooks enforce this when the agent tries to use tools (Bash, Write, Edit) — the PreToolUse hook catches violations.

But when a user asks "how would you do X?", the agent answers from memory without calling any tool. No tool use = no hook fires = no enforcement. The agent skips the tool discovery step entirely and gives a stale or incomplete answer.

Why existing hooks don't solve this

HookWhy it doesn't help
PreToolUseOnly fires when a tool is called — the problem is the agent answering without calling tools
PostToolUseSame — requires a tool call to exist

Proposed solution

A new hook event type — PreResponse (or PreAssistantTurn) — that fires after the user submits a prompt and before the agent generates its response. The hook's stdout would be injected as a system-level reminder, similar to how PreToolUse hook output is treated.

{
  "hooks": {
    "PreResponse": [
      {
        "hooks": [
          {
            "type": "command",
            "command": ".claude/hooks/pre_response_reminder.sh"
          }
        ]
      }
    ]
  }
}

The hook script receives the user's message as input (JSON) and can:

  • Exit 0 with stdout → stdout is injected as a system reminder before the agent responds
  • Exit 0 with no stdout → no injection, agent responds normally
  • Exit 2 → block the response entirely (same semantics as PreToolUse)

Example use case

#!/bin/bash
# .claude/hooks/pre_response_reminder.sh
INPUT=$(cat)
MSG=$(echo "$INPUT" | python3 -c "import sys,json; print(json.load(sys.stdin).get('message','').lower())" 2>/dev/null)

# Detect knowledge/how-to questions
if echo "$MSG" | grep -qE '(how would|how do|how to|walk.*through|what.s the best way|explain how)'; then
  echo "REMINDER: Rule Zero — run ./lift find <keywords> before answering this question."
fi
exit 0

This would let project maintainers enforce "check before you answer" patterns that CLAUDE.md instructions alone can't reliably enforce (especially after context compaction in long sessions).

Alternatives considered

  • CLAUDE.md instructions only — unreliable after context compaction in long sessions
  • Feedback memory — helps across conversations but still soft enforcement
  • Custom slash command (/how-to) — requires user to remember to use it
  • PreToolUse catch-all — doesn't fire when no tool is called

extent analysis

TL;DR

Implement a new PreResponse hook to inject guidance or enforcement before the agent generates a text response.

Guidance

  • Introduce a PreResponse hook event type that fires after the user submits a prompt and before the agent generates its response.
  • Use the hook's stdout to inject system-level reminders, similar to how PreToolUse hook output is treated.
  • Implement a hook script that receives the user's message as input and can exit with stdout to inject a reminder or exit without stdout to allow the agent to respond normally.
  • Consider using a script like .claude/hooks/pre_response_reminder.sh to detect knowledge/how-to questions and provide reminders to run ./lift find before answering.

Example

#!/bin/bash
# .claude/hooks/pre_response_reminder.sh
INPUT=$(cat)
MSG=$(echo "$INPUT" | python3 -c "import sys,json; print(json.load(sys.stdin).get('message','').lower())" 2>/dev/null)

# Detect knowledge/how-to questions
if echo "$MSG" | grep -qE '(how would|how do|how to|walk.*through|what.s the best way|explain how)'; then
  echo "REMINDER: Rule Zero — run ./lift find <keywords> before answering this question."
fi
exit 0

Notes

The proposed solution requires changes to the existing hook system, and it's unclear if this is feasible without modifying the underlying architecture. Additionally, the example script assumes a specific format for the user's message, which may not always be the case.

Recommendation

Apply the proposed PreResponse hook workaround to inject guidance or enforcement before the agent generates a text response, as it provides a more reliable way to enforce "check before you answer" patterns.

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

claude-code - 💡(How to fix) Fix Feature request: PreResponse hook event type [2 comments, 2 participants]