Summary
Claude Code’s hook system lets developers move beyond formatting suggestions and into hard enforcement — rules the agent cannot bypass regardless of what it infers from context. This official Anthropic tutorial walks through the roughly 30 hook events available in Claude Code, focusing on the four developers will reach for most: `pre-tool-use` (fires before any tool call, the primary enforcement point), `post-tool-use` (fires after a successful call, the natural place for auto-lint or auto-format), `stop` (fires when Claude wants to end its turn, allowing a hook to refuse), and `session-start` with the compact matcher (runs immediately after conversation compaction to re-inject preserved context).
The video is precise about the exit code contract that governs hook behavior: exit 0 signals success, exit 2 is a blocking error that feeds stderr back to Claude as context, and — critically — exit 1 does not block, meaning Claude runs the tool anyway. Hooks that return JSON can include a `permission` field set to `allow`, `deny`, `ask`, or `defer`, or can return an `updated_input` object to rewrite the tool call in place without stopping it.
Two patterns get extended treatment: a secret-redaction guardrail that uses `updated_input` on the bash tool to strip credentials before a command executes, and a context-preservation hook tied to the compact event that prints a short summary of in-progress files back into Claude’s context window. Together they represent the practical ceiling of what the hook system enables — deterministic enforcement on runs no one is watching.
📺 Source: Claude · Published September 03, 2026
🏷️ Format: Tutorial Demo







