โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ANATOMY OF A HOOK โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ EVENT PreToolUse / PostToolUse โ
โ MATCHER Bash, Write|Edit, ... โ
โ INPUT JSON payload on stdin โ
โ OUTPUT exit 0 = allow โ
โ exit 2 = BLOCK + message โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
A hook is a script wired to a Claude Code
lifecycle event.
EVENT When it fires (PreToolUse fires
BEFORE the agent runs a tool).
MATCHER Which tools trigger it (Bash,
Write|Edit).
PAYLOAD The tool call arrives as JSON
on stdin.
VERDICT exit 0 allows. exit 2 blocks and
shows the agent your message.
No AI involved. No judgment. Just code
that runs every single time.