CLAUDE.md guidance is strong, but long sessions can dilute adherence. Hooks enforce behavior at execution time.
Semantics
- exit 0: allow
- exit 2: block
- stderr: feedback to Claude
- stdout: inject context
Common production patterns
-
PreToolUse dangerous command block (
rm -rf, destructive SQL) - SessionStart re-injection after compaction
- PreCompact async backups
- StatusLine token visibility
- PostToolUse auto-format/lint
Use CLAUDE.md for “what to do.”
Use hooks for “what must never happen.”
One
exit 2is often more reliable than 100 lines of “please don’t.”
Top comments (1)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.