
A Claude Code stop hook error usually means your hook script printed something Claude Code could not use. If the message says Hook JSON output validation failed, your script printed valid JSON with a wrong field or value, such as a decision other than "approve" or "block". If it says JSON Parse error, the JSON itself is broken, most often by quotes inside a string you built by hand.
The fix in both cases is the same: build the output with a JSON tool such as jq, exit with code 0, and test the script by piping sample input into it. If the message instead shows your own text, such as a missing file or a crashed command, the script exited with a code other than 0 or 2, and Claude Code treated it as a non-blocking error.
We broke six hooks on purpose across the Stop, SessionStart and UserPromptSubmit events and recorded every message. This guide shows each one, what it means and the exact fix.
Browse all our Claude Code tutorials for more fixes and how-tos.
Tested with Claude Code v2.1.332 on macOS on December 3, 2026. All hooks lived in a throwaway project’s .claude/settings.json, and we started Claude Code with project and local settings only, so nothing outside the demo was changed. Items marked as coming from the docs follow Anthropic’s official hooks reference.
Quick Summary: Claude Code Hook Error Messages and Fixes
Find the message you see in the first column. The first six rows are failures we triggered ourselves, so the wording is exactly what v2.1.332 printed.
| Message you see | What it means | Fix | How we checked it |
|---|---|---|---|
Hook JSON output validation failed — decision: Invalid option | The decision value is not allowed | Use "block", or leave the field out | Tested in the terminal |
additionalContext: expected string, received number | A field has the wrong type | Send text, not a number or object | Tested in the terminal |
Hook output looks like a JSON object but is not valid JSON | Broken quotes or braces | Build the JSON with jq | Tested in the terminal |
No such file or directory | The script path is wrong | Fix the path in settings | Tested in the terminal |
Stop hook failed plus your own text | The script exited 1 | Exit 0, or exit 2 to block | Tested in the terminal |
Stop hook reported a problem | The hook blocked on purpose | Check stop_hook_active | Tested in the terminal |
| Warning that the Stop hook blocked too many times | The block cap of eight was hit | Check stop_hook_active | From the official docs |
| JSON has no effect, no error shown | Shell profile text or a field at the wrong level | Silence profile output, move the field | From the official docs |
What a Claude Code Hook Error Means
A hook is a command Claude Code runs at a set moment, such as when Claude finishes a reply (Stop), when a session opens (SessionStart) or when you send a prompt (UserPromptSubmit). The script talks back in three ways: its exit code, what it prints to stdout and what it prints to stderr. If you are new to hooks, our hooks guide covers the basics.
The official hooks reference sorts every run into three outcomes. Exit 0 is success, exit 2 is a blocking error, and any other exit code, a script that fails to start or output that fails to parse is a non-blocking error. A non-blocking error means the action goes ahead anyway.
The docs call the notice a “hook error”. In our version the red heading read Stop hook failed or UserPromptSubmit hook failed, while the debug log used the words Hook Stop (Stop) error. They are the same thing, so search for either.

A hook error is almost never about Claude. It is about what your script printed and how it exited, and you can test both without starting a session.
How We Reproduced These Hook Errors
We made a tiny project called todo-app with one Python file and a .claude/hooks/ folder. Each test copied a different settings file into place, then started Claude Code with a debug log, like this:
claude --setting-sources project,local --debug-file debug-a.logEvery test used the same one-line prompt, “Reply with the single word: done”, so the hooks were the only thing that changed. In total we sent five short prompts. The first session loaded three broken hooks at once, one per event.
{
"hooks": {
"SessionStart": [
{ "hooks": [ { "type": "command", "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/session-note.sh" } ] }
],
"UserPromptSubmit": [
{ "hooks": [ { "type": "command", "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/prompt-check.sh" } ] }
],
"Stop": [
{ "hooks": [ { "type": "command", "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/stop-check.sh" } ] }
]
}
}
Fix 1: “Hook JSON Output Validation Failed”
This is the message people search for most. It means your hook printed JSON that parsed fine, but a field breaks the rules. Claude Code tells you which field and why, then prints your output and the full expected schema below it.
A Stop hook with an invalid decision
Our Stop hook tried to make Claude run tests by printing this:
echo '{"decision": "retry", "reason": "Run the tests first"}'Claude Code replied with Stop hook failed and Hook JSON output validation failed — decision: Invalid option: expected one of "approve"|"block". The word retry is not a valid decision, so the whole output was thrown away and Claude simply stopped.
The Stop section of the docs lists "block" as the value that keeps Claude working, together with a required reason. To let Claude stop, leave the decision field out.
A SessionStart hook with the wrong type
Our SessionStart hook sent a number where text belongs:
echo '{"hookSpecificOutput": {"hookEventName": "SessionStart", "additionalContext": 42}}'The notice read SessionStart:startup hook failed with hookSpecificOutput.additionalContext: expected string, received number. Claude never saw the context. The fix is to send a string, and the safest way is to let jq build it:
jq -n --arg c "Open tasks: 3" \
'{hookSpecificOutput: {hookEventName: "SessionStart", additionalContext: $c}}'One more detail from the docs: when a hook exits 0 with output that fails validation, the action still goes ahead. When it exits 2, the hook still blocks, and Claude Code uses your stderr as the reason while the validation failure goes to the debug log.
Fix 2: “JSON Parse Error” From Hand-Built JSON
The second session focused on Stop hooks. One of them built its JSON with string concatenation, and the message it carried contained quotes:
MSG='Run "pytest" first'
echo "{\"decision\": \"block\", \"reason\": \"$MSG\"}"The output started with { and ended with }, so Claude Code tried to read it as JSON. The inner quotes broke it, and the notice said: Hook output looks like a JSON object but is not valid JSON — JSON Parse error: Expected '}'. Claude Code even suggested the fix in the same message: use a JSON encoder such as jq rather than string concatenation.

Here is the fixed script. jq escapes the quotes for you, so any message is safe:
#!/bin/bash
INPUT=$(cat)
if [ "$(jq -r '.stop_hook_active' <<<"$INPUT")" = "true" ]; then
exit 0 # already continued once, allow the stop
fi
jq -n --arg r 'Run "pytest" first, then stop' '{decision: "block", reason: $r}'If you write hooks in Python or Node.js, json.dumps or JSON.stringify does the same job. The rule is simple: never glue JSON together from strings.
Fix 3: “Hook Failed” With a Missing File or Exit Code 1
The same screenshot shows two more Stop hook errors that have nothing to do with JSON.
- The first hook pointed at
.claude/hooks/run-tests.sh, a file that did not exist. The notice ended inNo such file or directory, and the debug log showedfinished with status 127, the shell’s code for a missing command. - The third hook printed
stop-crash: pytest is not installedto stderr and exited 1. Claude Code showed that text underStop hook failedand let Claude stop as normal.
Both are non-blocking errors. The docs state that exit 1 is not a decision, so a hook that exits 1 never stops anything. Use exit 0 when the hook is just reporting, and exit 2 or a "block" decision when it must stop the action.
For a missing script, fix the path and reference scripts through "$CLAUDE_PROJECT_DIR" so the path works from any folder. The docs add one Stop-specific rule: if stdout is blank and stderr contains No such file, Claude Code assumes a missing script, so even exit 2 is treated as non-blocking. Our hooks not working guide covers permission errors and other reasons a script never starts.
The UserPromptSubmit hook in the first session failed the same way. It printed prompt-check: config file not found and exited 1, so the notice appeared under our prompt, and Claude answered anyway.
Fix 4: A Stop Hook That Keeps Claude Working
Sometimes the hook works too well. Our third session ran a Stop hook that always printed a valid block:
echo '{"decision": "block", "reason": "Run the tests before you stop"}'This time the notice was yellow, not red: Stop hook reported a problem, followed by our reason. That is not an error. Claude did what the hook asked, started looking for tests and asked to run a command, so the turn kept going.

The risk is a hook that blocks every time. The hooks guide says Claude Code overrides a Stop hook after it blocks eight times in a row with no tool call from Claude in between, and then ends the turn with a warning that the Stop hook blocked too many consecutive times. We did not run a full loop to the cap, so that wording comes from the docs.
The fix is the stop_hook_active field. Claude Code sets it to true in the hook’s input when Claude is already continuing because of a Stop hook. Exit 0 when it is true, as the fixed script above does.
If your hook truly needs more rounds, the docs name the CLAUDE_CODE_STOP_HOOK_BLOCK_CAP environment variable to raise the limit.
The docs also describe a softer option. Returning hookSpecificOutput.additionalContext on a Stop hook keeps the conversation going, but the transcript labels it Stop hook feedback and shows no hook error. For ready-made patterns, see our Stop hook examples.
Fix 5: Valid JSON That Has No Effect
This case has no error at all, which makes it hard to spot. The hooks guide lists two causes, and both come from the docs rather than our test.
- Extra output before the JSON. If your shell profile prints a line such as a greeting, the output no longer starts with
{, so Claude Code reads it as plain text and ignores your decision. Wrap profileecholines inif [[ $- == *i* ]]; then ... fiso they only run in interactive shells. - A field at the wrong level.
permissionDecisionandadditionalContextbelong insidehookSpecificOutput. At the top level they are silently ignored.
The debug log tells them apart. Search it for Hook output does not start with { for the first cause and Hook JSON output had unrecognized keys for the second.
Test a Hook Script Without Starting Claude Code
You can find most of these errors in seconds from your normal terminal. Pipe sample input into the script, then print the exit code, as the official guide suggests. We ran our broken and fixed scripts this way.

echo '{"stop_hook_active":false}' | .claude/hooks/stop-parse.sh | jq .
echo '{"stop_hook_active":true}' | .claude/hooks/stop-fixed.sh; echo "exit code: $?"
grep -o 'Hooks: Stop.*' debug-b.log- If
jq .prints a parse error, Claude Code will showJSON Parse errortoo. - If
echo $?prints anything other than 0 or 2, expect a non-blockinghook failednotice. - The
Hooks:lines in the debug log list every hook with its exit status and time, such asfinished with status 127 (10ms).

The result after fixing every hook
Our last session used the fixed SessionStart, UserPromptSubmit and Stop hooks. No red notices appeared. Claude read the session context, and the Stop hook’s reason arrived with its quotes intact, so Claude moved on to run pytest.

Try It Yourself
Make a scratch folder, add one Stop hook that prints {"decision": "maybe"}, and send a short prompt. You will see the validation message for yourself. Then paste this prompt into Claude Code in that folder to have it check your hooks:
Read .claude/settings.json and every script in .claude/hooks/.
For each hook, tell me: the event, whether the script exists and is executable,
what it prints to stdout, and its exit code. Flag any JSON built by string
concatenation, any decision value other than "block", and any Stop hook that
does not check stop_hook_active. Do not edit files.Compare its answer with what you get from piping JSON into each script yourself.
Common Mistakes
- Building JSON with
echoand quotes. One apostrophe or quote in the message breaks it. - Inventing decision values such as
retryorcontinue. Stop hooks accept"block", or no decision at all. - Exiting 1 to block. Exit 1 is a non-blocking error, so the action goes ahead.
- Printing debug text to stdout next to the JSON. Send it to stderr with
>&2. - Forgetting
stop_hook_active, so a Stop hook blocks over and over. - Putting
additionalContextat the top level instead of insidehookSpecificOutput.
Pro Tips
- Start Claude Code with
claude --debug-file debug.logwhile you build hooks. The docs note that--debugwrites to a file and does not print on screen. - Press
Ctrl+Oto expand a collapsed hook notice in the transcript. - Check every hook script with
jqbefore you wire it up. Ifjq .accepts the output, the parse step is safe. - For hooks that enforce a rule, the docs describe
"onFailure": "block", which blocks the action when the hook fails instead of letting it pass. - Start from tested scripts. Our ready-to-copy hooks already use exit codes the right way.
- If the problem is the settings file itself, our settings.json fixes and the doctor command guide will help, and our list of Claude Code common errors covers messages outside hooks.
Cheat Sheet

Frequently Asked Questions
What does “Hook JSON output validation failed” mean in Claude Code?
Your hook printed valid JSON, but a field has a value or type Claude Code does not accept. The message names the field, for example decision or additionalContext, and prints the expected schema. Fix that one field and the error goes away.
Why do I get a Claude Code stop hook error after every reply?
Stop hooks run every time Claude finishes responding, not only at the end of a task. A script that crashes, has a wrong path or prints broken JSON will fail on every reply. Pipe sample JSON into it from your terminal to find the cause.
Does a hook error stop Claude Code from working?
Usually not. Parse failures, validation failures on exit 0 and exit codes other than 0 or 2 are non-blocking, so the action goes ahead. In our tests Claude still answered every prompt.
How do I stop a Stop hook from looping?
Read stop_hook_active from the hook’s input and exit 0 when it is true. Claude Code also overrides a Stop hook after eight blocks in a row with no tool call in between, according to the docs.
Where can I see full hook error details?
Start Claude Code with claude --debug-file debug.log and search the file for Hooks: lines and the word error. You can also run /debug in a running session. Learn more about the assistant behind it on our Claude AI page.
Conclusion
Most Claude Code hook errors come down to the script’s output and exit code. A validation failure means a field is wrong, a parse error means the JSON was glued together by hand, and a plain hook failed with your own text means the script exited with a code other than 0 or 2. Build JSON with jq, exit 0 to report and 2 or "block" to stop, check stop_hook_active in every Stop hook that blocks, and test each script by piping sample JSON into it before Claude Code runs it. The debug log fills in the rest, and the official hooks guide lists more troubleshooting cases.


