EVERY SPOKEN WORD
2 min read · 456 words- 0:00 – 0:02
Intro
- SPSpeaker
[upbeat music]
- 0:02 – 0:33
What hooks are in Claude Code: deterministic automation
- SPSpeaker
Hooks let you run commands at different points in Claude Code's lifecycle. The key difference between hooks and everything else we covered is that hooks are deterministic. They always run. So put it this way, you can tell Claude in your claude.md file to run prettier after every file edit, and most of the time it will do that, but sometimes it won't. It's not perfect. But a
- 0:33 – 0:48
Practical use cases: formatting, compliance logging, safety blocks, notifications
- SPSpeaker
hook makes it happen every single time with no exceptions. Common use cases could include auto-formatting after file edits, logging all executed commands for compliance, blocking dangerous operations like modifying production files, and sending yourself
- 0:48 – 1:03
How hooks are configured: events, matchers, commands (settings.json)
- SPSpeaker
notifications when Claude finishes a task. Hooks are configured in your settings.json file. You pick an event, optionally set a matcher for which tools it applies to, and provide a command to run. User
- 1:03 – 1:18
Lifecycle events overview: prompt submit, pre/post tool use, notification, stop
- SPSpeaker
prompt submit runs when you submit a prompt before Claude processes it. Pre tool use, which runs before a tool call. Post tool use runs after a tool call completes. Notification runs when Claude sends a notification. And stop runs when Claude finishes responding.
- 1:18 – 1:33
Auto-formatting pattern: post-tool-use hook for edits
- SPSpeaker
The most common hook, auto-formatting after edits. You set a post tool use hook with a matcher of edit or multi-edit, right? So it fires whenever Claude
- 1:33 – 1:48
Formatter selection by file type: Prettier, gofmt, Ruff, etc.
- SPSpeaker
modifies a file. The command checks the file extension and runs the appropriate formatter. This could be prettier for TypeScript, go format for Go, rough for Python, whatever your project uses.
- 1:48 – 2:03
Blocking unsafe actions: pre-tool-use hooks with stdin JSON
- SPSpeaker
Pre tool use hooks can block tool calls before they execute. So your hook receives a tool name and input as JSON on stdin. If it exits with code two, the action is blocked, and the stderr message gets fed back to
- 2:03 – 2:13
Exit codes as control flow: proceed vs block with feedback to Claude
- SPSpeaker
Claude as feedback so Claude knows why it was blocked and can adjust. Exit code zero means proceed. Exit code two means block. This is how you enforce hard rules.
- 2:13 – 2:23
Examples of enforceable rules: production writes, rm -rf, main branch commits
- SPSpeaker
Block writes to a production config directory, block batch commands that contain RM-RF, block commits to main, whatever your team needs to be guaranteed, not suggested.
- 2:23 – 2:33
Team-wide setup: project-level hooks in .claude/settings.json
- SPSpeaker
Hooks configured in .claude/settings.json are project level and can be checked into your repo. This means that your entire team gets
- 2:33 – 3:21
Robust scripting: use Claude project dir environment variable
- SPSpeaker
the same hooks automatically. Use the Claude project dir environment variable in your commands to reference scripts stored in your project so they work regardless of Claude's current working directory. [upbeat music] Hooks gives you deterministic control over Claude Code's behavior. Use post tool use for auto-formatting and logging. Use pre tool use to block dangerous operations. Configure them in the /hooks or in settings.json, and check them into your repository so your team gets them too. If something needs to happen every time without fail, don't put it in a prompt. Put it in a hook. [upbeat music]
Episode duration: 3:21
Install uListen for AI-powered chat & search across the full episode — Get Full Transcript
Transcript of episode IkaPHiMDazM
