Claude Code hooks can enforce rules that CLAUDE.md may miss

Rules written in CLAUDE.md act more like guidance for Claude than hard limits. Instructions such as “never run the deploy script,” “do not touch the migrations folder,” and “always run the formatter before committing” may work most of the time, but they are not guaranteed. In , with a full or several subagents involved, a rule can become just one more line competing for the model’s attention.

Claude Code hooks work differently. A hook is a registered in , and it runs as code at a fixed point outside the model’s judgment. The runs before a tool is executed and receives the full tool call as JSON, including the exact Bash command about to run.

If the command is unsafe, the hook can block it before it happens, and Claude is then told the action was blocked so it can adjust.

Key points

  • CLAUDE.md rules are prompt guidance, not guaranteed enforcement.
  • and crowded context can make the model miss written rules.
  • Claude Code hooks run outside the model at fixed moments in the workflow.
  • PreToolUse can inspect a Bash command before it executes.
  • Hooks are useful for blocking risky deploy, migration, or formatting mistakes.
Read original