Rules the agent can’t forget.
CLAUDE.md is a request the agent usually follows. Hooks are commands that run automatically at set moments, every time, whatever it decides.
Four Useful Moments
PreToolUse
Before a tool runs: block edits to .env
PostToolUse
After an edit: run the code formatter
Stop
When it finishes: run the tests
SessionStart
At the start: load today's context
Handle with care
Hooks run with your permissions.
Read any hook before you copy it.
Keep them fast, or every step slows down.
Source: Anthropic Claude Code Docs ↗
CLAUDE.md asks. Hooks enforce.