Claude Code Hooks Not Working: Fix a Hook That Won't Fire
Returns a numbered diagnosis of your Claude Code hook (location, event, matcher, exit code, stdout, onFailure, path), the named cause, a corrected entry and a one-command test.
You get: Numbered diagnosis, cause found and corrected hook entry and script as diffs. Wait for my OK…
The prompt
mkdir -p .agents/skills/claude-code-hooks-not-working-fix-a-hook-that-won-t-fire && curl -sL "https://prompts-gpt.com/prompts/claude-code-hooks-not-working-fix-a-hook-that-won-t-fire/raw" -o .agents/skills/claude-code-hooks-not-working-fix-a-hook-that-won-t-fire/SKILL.mdYou are a Claude Code engineer debugging hook configuration in this repository. My hook should: . It either does not fire or fires but does not block.
Inspect the repo first. Run claude --version and check --help or the hooks docs for anything below your installed version may not support. Ask at most 3 short numbered questions, in one message, only for what you cannot find.
Rules:
1. Read every hook location: ~/.claude/settings.json, .claude/settings.json, .claude/settings.local.json, managed settings, plugin hooks/hooks.json, and skill or subagent frontmatter. Compare them with the read-only /hooks list and the source it shows for each hook.
2. Check the event fits the goal. Use PreToolUse to block: exit 2 blocks with stderr as the reason, and exit 1 does not block. PostToolUse can only react after the tool ran. UserPromptSubmit, Stop and PostToolBatch silently ignore matchers.
3. Check the matcher. Only letters, digits, _, -, spaces, commas and | mean an exact match or list. Any other character makes it an unanchored regex: Edit.* also matches NotebookEdit, so use ^Edit$. MCP tools are named mcp__server__tool, and a bare mcp__memory matches nothing.
4. Check that stdout is only the JSON object. Check onFailure (if unset, a failed or timed-out hook lets the action proceed), the timeout (default 600 s), the script's executable bit, and an absolute path built from $CLAUDE_PROJECT_DIR.
5. Every finding cites file:line or command output. Mark anything else as a gap.
Output format:
1. Numbered diagnosis: check, finding, pass/fail.
2. Cause found, in one line.
3. Corrected hook entry and script as diffs. Wait for my OK before saving, then say where you saved them. Never commit or push.
4. A one-command manual test with the expected exit code and output.
End with what you could not confirm, and how to verify it with claude --debug or /debug.Example output
Tips and common edits
Why this works
- It reads every settings location and the /hooks source list, so a hook defined in the wrong file is caught before any other debugging.
- It names the specific traps: exit 1 vs 2, unanchored regex matchers, bare mcp__ names and events that ignore matchers.
- The fix ends with a one-command test that pipes fake hook input into the script, so you can verify it without waiting for Claude to trigger it.
Use in Claude Code at the repo root when a hook silently does nothing or lets a blocked action through. Follows the hooks reference as of Claude Code 2.1.329. Have the hook's goal ready and know whether you edited any user-level settings.
Common edits
- Second example, ready to paste: set {hook_goal} = "run prettier on the changed file after every Edit or Write, but not NotebookEdit".
- Change the goal to a PostToolUse hook such as auto-formatting, and ask the agent to drop the blocking checks.
- Ask the agent to also check plugin hooks/hooks.json in a specific plugin folder you name.
Reuse it: Use in a workflowAdapt in the builder
Prompt details
- By
- Prompts-GPT editors
- Published
Did this prompt work?
More like this
Generate Reproducible Bug Fix Specs for Coding Agents
Get a standalone reproduction test script and a precise technical plan to fix a bug, ensuring your AI agent stays focused and avoids unnecessary file changes.
Cursor Call Graph Trace Before You Change a Function
Cursor maps who calls a function and what it calls, with file and line for every step, the callers your planned change could break and the exact tests to run, before any code is edited.
Claude Code Permission Allowlist and Deny Rules for This Repo in settings.json
Has Claude Code read your repo's scripts and CI, then propose allow, ask and deny permission rules with a reason for each, split into shared and local settings files, plus commands to test them.
Root-Cause Bug Fix With a Failing Test and a Minimal Patch
Get a reproduced bug, a regression test that fails before the fix and passes after it, the smallest patch and a log of the commands Claude Code actually ran.
Debug an Error From the Message and the Code Around It
Finds the most likely cause of an error from the message and the relevant code, ranks other possible causes, and gives the smallest fix plus a way to prove it worked.
Claude Code Hook Writer: Auto-Run Lint, Typecheck or Tests After Edits
Produces a PostToolUse hook entry for settings.json, the script it calls and a concrete procedure to test that the check runs after file edits.
- Paste a Bug Report, Get a Test-First Fix in Any AI Chat
- Block Dangerous Bash Commands: PreToolUse Hook With Tests
- Systematic Debugging: Agent Skill (SKILL.md) for Claude Code, Codex and Cursor
- Test-First Bug Fix Skill: Reproduce, Fix, Prove (SKILL.md)
- Codex CI Failure Triage: Reproduce, Classify, Fix or Hand Off
- Cursor Agent Bug Triage: Reproduce, Root-Cause, Fix, and Regression Test