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 →