Dev.to
7/13/2026

Your CLAUDE.md says "always run tests" — hooks are how you actually mean it
Short summary
Explains why CLAUDE.md rules files are advisory and lose attention contests over long sessions, and how Claude Code hooks solve this by running shell commands at fixed lifecycle points outside the model. Covers PreToolUse and PostToolUse events, exit-code-based blocking with stderr feedback, and five practical hooks including main-branch guards, secret scanning, and test gates.
- •CLAUDE.md rules are advisory; hooks are enforcement gates that run outside the model
- •PreToolUse hooks can block tool calls and feed stderr back to the agent for self-correction
- •Five practical hooks: main-branch guard, secret scan, test gate, and more
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



