⌨️Hook Exit Code
Also known as exit code 2, exit 2 hook
The number a hook ends with: 0 goes ahead, 2 blocks, others warn.
Think of it like
It is like a traffic light. Green goes, red stops, and a flashing light just warns.
Example
Lucy's first hook exited 1 to block a command. Nothing was blocked. She changes it to exit 2, and it works.
Why it matters
One digit decides if your guard works. Most broken hooks use the wrong one.
Definition
Example code
bash
#!/bin/bash
cmd=$(jq -r '.tool_input.command')
if [[ "$cmd" == *"rm -rf"* ]]; then
echo "rm -rf is not allowed here" >&2
exit 2
fi
exit 0Common mistake
Key takeaways
- 10 goes ahead. JSON is read.
- 22 blocks. stderr is the reason.
- 3Others warn. Action goes on.