- Symptom
- PreToolUse:Bash hook error notice with 'Failed with non-blocking status code:' and the command still runsA mistyped hook path shows '/bin/sh: ... No such file or directory' and the action goes aheadA policy hook that prints JSON with a typo lets the action through
- Cause
- Only exit code 2 blocks. Exit 1, any other code, a script that cannot start, or stdout JSON that fails to parse is a non-blocking error, so the action proceeds.
- Fix
- Exit 2 with the reason on stderr to block, or return a JSON decision. On Claude Code v2.1.295 or later, set onFailure to block on policy hooks so a broken or missing script fails closed; older versions ignore the field.
- Apply
# hook script echo "Blocked: force push is not allowed" >&2 exit 2 # settings.json hook entry { "type": "command", "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/policy.sh", "onFailure": "block" }- Affected
- Claude Code hooks, as of 2026-10; onFailure requires v2.1.295 or later
- Sources
Last verified 2026-10-15 · Confirmed by 0 builders