Skip to main content

Hooks

Hooks are Claude Code's lifecycle automation system. They fire shell commands at precise moments — before or after tool calls — giving you programmatic control over agent behavior without touching the agent itself.

Why Hooks Matter

Most developers discover hooks when they want auto-formatting. That's the tip of the iceberg. Hooks are the mechanism for building deterministic guardrails around non-deterministic agent behavior. They're how you enforce invariants that prompts alone can't guarantee.

When to Use Hooks vs. Alternatives

NeedUse
Enforce a rule on every tool callHook
Teach the agent a reusable workflowSkill
Give the agent a one-time instructionCLAUDE.md
Block dangerous operationsHook (PreToolUse)
Format code after editsHook (PostToolUse)

What's Inside

Explore the sub-pages for deep expertise:

  • Mental Model — How hooks fit into Claude Code's execution lifecycle
  • Playbook — Production-ready hook configurations with rationale
  • Compositions — Hooks combined with skills, agents, and MCP
  • Pitfalls — Silent failures, ordering surprises, and performance traps