5.1 — Stochastic vs Deterministic: why hooks exist
Since the start of this training, you've been configuring Claude Code with CLAUDE.md files, project instructions, and team conventions. All of that works — most of the time. The fundamental problem: CLAUDE.md is advisory. Claude reads it, interprets it, and does its best. But "its best" is not a guarantee. An LLM can forget an instruction, misinterpret it, or decide it doesn't apply in a given context.
Hooks solve this problem. They are shell commands or LLM prompts that run automatically at precise points in the Claude Code lifecycle. They aren't "suggested" — they are executed. When you configure a hook that blocks file deletions, that hook will run on every attempt, no exceptions.
Think of the difference between a "speed limit 50 km/h" sign (CLAUDE.md) and an automated speed camera that systematically flashes (hooks). The first informs, the second enforces.
Hooks are configured in JSON in your settings files (.claude/settings.json for the project, ~/.claude/settings.json for global) and trigger on precise lifecycle events: session start, tool use, stop, context compaction, notification. Each event is an interception point where you can wire one or more hooks.
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "echo '{\"decision\": \"deny\", \"reason\": \"Command blocked by hook\"}'",
"timeout": 5
}
]
}
]
}
}
Two types of hooks are available: command (deterministic shell script) and prompt (contextual LLM evaluation). The first is fast and predictable, the second is capable of semantic judgment. Picking between the two depends on the nature of the check.
Key takeaways
• CLAUDE.md = advisory (Claude tries to comply); hooks = deterministic (execution guaranteed)
• Two types of hooks: command (shell) and prompt (LLM)
• JSON configuration in settings files (project or global)
• Hooks are Claude Code's professional enforcement mechanism