Use hooks for anything that must happen every time
Instructions are suggestions; hooks are guarantees. Use Claude Code hooks to auto-lint after edits or block dangerous commands.
Hooks are shell commands Claude Code runs at fixed points in its lifecycle. Unlike a line in your prompt, they don’t depend on the model choosing to follow them.
Good uses
- Run your formatter or linter after every file edit.
- Block specific commands before they run: a
PreToolUsehook can inspect a tool call and exit with code 2 to deny it. - Send a notification when a long task finishes.
When you need judgment
For checks that need reasoning rather than a fixed rule, Claude Code also supports prompt-based and agent-based hooks that ask a model to evaluate the condition.
Rule of thumb from Anthropic: if it should happen deterministically, it’s a hook, not a prompt.