Claude Code Hooks: Turn "Usually Follows" Into "Cannot Skip" — Transcript
Full transcript
- 0:03A hook is a deterministic code at a
- 0:05fixed point in the loop, which means it
- 0:07can guarantee far more than formatting
- 0:09on a run you're not watching.
- 0:10>> [music]
- 0:10>> It turns a rule from Claude usually
- 0:12listens into Claude can't skip it.
- 0:15Claude code fires around 30 hook events.
- 0:17The handful you'll reach for is pre-tool
- 0:20use, which fires before a tool call, the
- 0:22enforcement primitive. Post-tool use,
- 0:24which fires after a successful tool
- 0:26call. This is usually where like
- 0:27auto-formatting or an auto-lint would
- 0:29go. Stop, which fires when Claude wants
- 0:31to end his turn.
- 0:33Refuse if conditions aren't met.
- 0:34Sub-agent stop is the same signal, but
- 0:36for sub-agent finishing. Pre-compact and
- 0:38post-compact fire before and after
- 0:40compaction. To re-inject context after
- 0:42compaction, use session start with the
- 0:44compact matcher, not post-compact.
- 0:46Instructions loaded fires when a
- 0:48claude.md or rule file loads. Audit what
- 0:51made it into context. Session start
- 0:53primes the environment. Check source
- 0:54startup to run only on fresh starts.
- 0:58For pre-tool use, return JSON on exit
- 1:00zero with a permission decision field
- 1:02allow, deny, or ask. There's a fourth
- 1:04value defer, but it only applies to
- 1:06non-interactive-p runs, where a calling
- 1:09process pauses the tool and resumes it
- 1:10later. So, you'll rarely reach for it.
- 1:13You can also return updated input to
- 1:15modify the tool call without blocking,
- 1:17which can be useful for redacting
- 1:18secrets out of a bash command. One catch
- 1:20is that updated input replaces the whole
- 1:22input object. So, echo back the fields
- 1:24that you aren't changing.
- 1:26For hooks that don't return JSON, exit
- 1:28codes work, too. So, here's the three
- 1:30numbers that matter. Zero is a success,
- 1:33so if the standard out is JSON, Claude
- 1:35parses it. Plain text is ignored on most
- 1:37events, but on session start, user
- 1:39prompt submit, and user prompt
- 1:40expansion, it gets added to context,
- 1:42which is exactly what makes the state
- 1:44preserver work. Two is a blocking error,
- 1:47so standard error gets fed back to
- 1:49Claude as a context. This is the
- 1:51blocking exit code almost everywhere,
- 1:53where the lone exception work tree
- 1:55create aborts any non-zero code. Watch
- 1:57out because exit one feels like an
- 1:59error, but it actually does not block.
- 2:01So, Claude runs the command anyway. And
- 2:02then anything else is non-blocking and
- 2:04is locked. Exit two can block stop,
- 2:06which is how you say no, you're not
- 2:08done. Post tool use fires after the tool
- 2:10already ran. So, it's too late to stop
- 2:12the call, though it can still feed text
- 2:14back to Claude. A few events ignore
- 2:16blocking like notification, session
- 2:18start, and file change show your
- 2:20standard error and carry on.
- 2:23A pre-tool use guardrail that redacts
- 2:25instead of blocking. The matcher picks
- 2:27the tool to watch, say bash, and an
- 2:29optional if clause narrows it to a
- 2:31specific command. So, returning deny
- 2:34stops a dangerous call. The lesser known
- 2:36move is return updated input to rewrite
- 2:38the call, which is how you strip a
- 2:40secret out of a command and still let it
- 2:42run.
- 2:44When Claude compacts a long
- 2:45conversation, it drops a lot of details.
- 2:48But, a session start hook with the
- 2:49compact matcher runs right after a print
- 2:52short summary of the files you've been
- 2:54working on. That summary goes back into
- 2:56context, so Claude picks up where it was
- 2:57instead of starting cold.
- 3:01Hooks turns a rule Claude usually
- 3:03follows into one that it always follows.
- 3:08Reach past auto formatting, guard tools
- 3:10with pre-tool use, gate the turn with
- 3:12stop, and preserve state across compact.
- 3:14The setup pays back the first time it
- 3:16catches something on a run you weren't
- 3:18watching.
About this transcript
This page contains the full transcript of Claude Code Hooks: Turn "Usually Follows" Into "Cannot Skip" by Claude, generated from the public captions YouTube serves with the video. The transcript has 607 words across 96 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.