Hooks in Claude Code

Hooks in Claude Code

More

Descriptions:

This official video from Anthropic’s Claude channel explains hooks — one of Claude Code’s most powerful but least understood features. Unlike instructions given in a CLAUDE.md file or system prompt, hooks are deterministic: they execute every single time a specified event fires, regardless of what the model decides to do. That distinction makes them the right tool for anything that must happen without exception.

The video walks through the five hook event types available in Claude Code: `UserPromptSubmit`, `PreToolUse`, `PostToolUse`, `Notification`, and `Stop`. Configuration lives in `settings.json`, with optional matchers to scope hooks to specific tools. The exit code contract is clearly explained — exit code 0 means proceed, exit code 2 blocks the action and feeds the stderr message back to Claude so it can understand why it was stopped and adjust. This enables hard enforcement rules like blocking writes to production config directories or preventing `rm -rf` commands entirely.

Practical use cases covered include auto-formatting on file edits (running Prettier for TypeScript, `gofmt` for Go, Ruff for Python), compliance logging of all executed commands, and team-wide enforcement by checking hooks into the repository. The `CLAUDE_PROJECT_DIR` environment variable is highlighted as the right way to reference project scripts portably. For any team using Claude Code in a shared or regulated environment, this feature offers a level of behavioral guarantees that prompt-based instructions simply cannot.


📺 Source: Claude · Published May 07, 2026
🏷️ Format: Tutorial Demo

1 Item

Channels