PRODUCTION SCENARIO
Your PreToolUse hook script prints JSON with permissionDecision set to allow for approved database commands. A stray error path makes the script exit with code 2 after printing, and engineers see those approved commands blocked, with the script's stderr text given as the reason.
What explains the blocked commands?
Answering here is anonymous. Nothing is saved unless you sign in.
Show answer and explanation
Answer: Exit code 2 blocks on blockable events whatever the JSON says, so the script must exit 0 to allow
On events that can block, exit code 2 is a blocking error whether or not the hook printed JSON, and even an allow decision cannot override it; the reason shown is the stderr text because the JSON made no blocking decision. Exit 0 is the intended code when a hook prints JSON for structured control, and a hook that times out does not block the call.
Official Source: https://code.claude.com/docs/en/hooks ↗