Claude Code Hook Errors: “JSON Validation Failed” and Other Hook Failures

Claude Code Hook Errors: “JSON Validation Failed” and Other Hook Failures

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 seeWhat it meansFixHow we checked it
Hook JSON output validation failed — decision: Invalid optionThe decision value is not allowedUse "block", or leave the field outTested in the terminal
additionalContext: expected string, received numberA field has the wrong typeSend text, not a number or objectTested in the terminal
Hook output looks like a JSON object but is not valid JSONBroken quotes or bracesBuild the JSON with jqTested in the terminal
No such file or directoryThe script path is wrongFix the path in settingsTested in the terminal
Stop hook failed plus your own textThe script exited 1Exit 0, or exit 2 to blockTested in the terminal
Stop hook reported a problemThe hook blocked on purposeCheck stop_hook_activeTested in the terminal
Warning that the Stop hook blocked too many timesThe block cap of eight was hitCheck stop_hook_activeFrom the official docs
JSON has no effect, no error shownShell profile text or a field at the wrong levelSilence profile output, move the fieldFrom 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.

Decision ladder showing how Claude Code treats hook output: parse error, validation failed, non-blocking failure, blocking problem or silent success
Match what your script printed to the message Claude Code shows.

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.log

Every 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" } ] }
    ]
  }
}
Claude Code terminal showing SessionStart hook failed, UserPromptSubmit hook failed and Stop hook failed with JSON output validation failed
One session, three broken hooks: two validation failures and one crashed script.

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.

Three Stop hook failed notices in Claude Code: missing script path, JSON parse error and a script that exited 1
Three Stop hooks, three different failures in one turn.

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 in No such file or directory, and the debug log showed finished with status 127, the shell’s code for a missing command.
  • The third hook printed stop-crash: pytest is not installed to stderr and exited 1. Claude Code showed that text under Stop hook failed and 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.

Stop hook reported a problem in Claude Code, followed by Claude listing files and preparing a command instead of stopping
A valid block sends Claude back to work instead of ending the turn.

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.

  1. 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 profile echo lines in if [[ $- == *i* ]]; then ... fi so they only run in interactive shells.
  2. A field at the wrong level. permissionDecision and additionalContext belong inside hookSpecificOutput. 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.

Terminal showing jq parse error from the broken Stop hook, valid JSON from the fixed hook, exit codes and Hooks: Stop lines from the debug log
Piping JSON into each script shows the parse error and exit codes before Claude Code ever runs.
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 show JSON Parse error too.
  • If echo $? prints anything other than 0 or 2, expect a non-blocking hook failed notice.
  • The Hooks: lines in the debug log list every hook with its exit status and time, such as finished with status 127 (10ms).
Four-step flow for fixing a Claude Code hook error: read the notice, test the script, fix the output, confirm in the debug log
The same four steps fix a Stop, SessionStart or UserPromptSubmit hook error.

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.

Claude Code session with fixed hooks: Claude reads the SessionStart context and the Stop hook reason shows quotes correctly
With jq-built output, the context reaches Claude and the Stop reason is readable.

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 echo and quotes. One apostrophe or quote in the message breaks it.
  • Inventing decision values such as retry or continue. 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 additionalContext at the top level instead of inside hookSpecificOutput.

Pro Tips

  • Start Claude Code with claude --debug-file debug.log while you build hooks. The docs note that --debug writes to a file and does not print on screen.
  • Press Ctrl+O to expand a collapsed hook notice in the transcript.
  • Check every hook script with jq before you wire it up. If jq . 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

Cheat sheet of Claude Code hook error messages with their meaning and the commands to fix and check them
Hook error messages and fixes on one card.

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.

Newsletter

New AI tools in your inbox

The best new tools and the AI news that matters, in one short email. Unsubscribe any time.

Free · No spam · Unsubscribe any time

✓ Looks like you’re subscribed

Loading Google’s sign-up form…

Looks like you’re already subscribed

Thanks for reading! New AI tools and the AI news that matters will land in your inbox.

Not subscribed yet? Refresh the page to load the sign-up form.

The sign-up form couldn’t load. If you use an ad or content blocker, allow news.google.com and reload the page.

Free instant check before you pay. Takes a few seconds.

Scroll to Top