Hooks
Custom scripts that run automatically at specific moments — guardrails that don't spend AI tokens or need supervision.
Some rules should just always apply, deterministically, without asking an AI model to decide each time (and without spending tokens on the decision). Hooks are how you do that: a script that fires automatically at a defined trigger point — the video's examples are auto-formatting a file every time Claude saves one, and logging every command Claude runs.
What's grown since the video: hooks now fire on a much wider range of events — session start/end, before/after any tool use, before/after a model switch, when a file changes on disk, when a subagent starts or stops, and more — and a hook handler can be a shell command, an HTTP request, a call to an MCP tool, or even an LLM prompt used purely for a yes/no decision. Hooks can also actively block an action (exit code 2) rather than just observing it, which makes them a genuine enforcement layer, not just logging.
Real-life use cases
Blocking a genuinely dangerous command
A hook inspects every Bash command before it runs and hard-blocks anything matching rm -rf patterns — a rule that applies unconditionally, regardless of what Claude Code itself decides is safe in the moment.
Auto-formatting on every save
A PostToolUse hook runs the project's linter/formatter automatically after every file edit, so code style is always consistent without Claude needing to be reminded or without a human running a separate formatting pass.
Source
- Source video: “Claude Code Explained” — 27 concepts in 27 minutes (YouTube)https://www.youtube.com/watch?v=ZlDnsf_DOzg
- Hookshttps://code.claude.com/docs/en/hooks