PulseAugur
EN
LIVE 10:04:24

Claude Code Hooks Fail Open on Error, Blocking Requires Exit Code 2

A user discovered that Claude Code's PreToolUse hooks do not block commands by default when they exit with an error code of 1. Instead, only an exit code of 2 is recognized as a blocking error by Claude Code, allowing the tool call to proceed while displaying the error message. To ensure safety hooks function correctly, users must explicitly configure them to exit with code 2 for any blocking condition, or implement a mechanism to trap other non-zero exit codes and convert them to exit code 2. This is crucial because a crashing hook or one with a non-blocking error code will fail open, allowing potentially harmful commands to execute. AI

IMPACT Users of Claude Code must adjust their safety hook configurations to ensure commands are properly blocked.

RANK_REASON User-discovered behavior in a specific product feature.

Read on dev.to — Claude Code tag →

AI-generated summary · Google Gemini · from 1 sources. How we write summaries →

Claude Code Hooks Fail Open on Error, Blocking Requires Exit Code 2

COVERAGE [1]

  1. dev.to — Claude Code tag TIER_1 English(EN) · jidonglab ·

    Claude Code Hook Exit Codes: exit 1 Let 19 'Blocked' Commands Run

    <p>My guard hook printed <code>BLOCKED: rm -rf outside project</code> nineteen times in three weeks. I felt great about it. Then I lined the hook log up against the session transcripts and found that all nineteen commands had run anyway.</p> <p>The hook did exactly what I told it…