Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/hooks/bash_command_validator_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def main():
input_data = json.load(sys.stdin)
except json.JSONDecodeError as e:
print(f"Error: Invalid JSON input: {e}", file=sys.stderr)
# Exit code 1 shows stderr to the user but not to Claude
# Exit code 1 is a non-blocking hook error; the tool call continues.
sys.exit(1)

tool_name = input_data.get("tool_name", "")
Expand All @@ -75,7 +75,7 @@ def main():
if issues:
for message in issues:
print(f"• {message}", file=sys.stderr)
# Exit code 2 blocks tool call and shows stderr to Claude
# Only exit code 2 blocks the tool call and sends stderr to Claude.
sys.exit(2)


Expand Down
5 changes: 5 additions & 0 deletions plugins/plugin-dev/skills/hook-development/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ Execute when Claude sends notifications. Use to react to user notifications.
- `2` - Blocking error (stderr fed back to Claude)
- Other - Non-blocking error

**Warning:** Only exit code `2` blocks tool execution. Exit code `1` and
all other non-zero codes are treated as non-blocking errors, so the tool call
continues. Use `exit 2` or `sys.exit(2)` for enforcement hooks that must
prevent an action.

## Hook Input Format

All hooks receive JSON via stdin with common fields:
Expand Down
2 changes: 2 additions & 0 deletions plugins/plugin-dev/skills/hook-development/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ Check:
### Hook fails silently

- Check exit codes (should be 0 or 2)
- Use exit code `2` for blocking enforcement; exit code `1` is non-blocking
and the tool call continues
- Ensure errors go to stderr (`>&2`)
- Validate JSON output structure

Expand Down