Video summary
Hooks in Claude Code
Main summary
Key takeaways
Key technological concept: Deterministic “hooks” in Claude Code
- Hooks let you run commands at specific points in Claude Code’s lifecycle.
- Unlike “regular” prompt instructions or other behaviors, hooks are deterministic: they always run with no exceptions.
- Example: telling Claude in
claude.mdto run Prettier after edits may be inconsistent, but a hook will run every time.
- Example: telling Claude in
Common use cases highlighted
- Auto-formatting after file edits (e.g., run different formatters based on file type/extension).
- Logging all executed commands for compliance/audit purposes.
- Blocking dangerous operations (enforce hard safety rules).
- Sending notifications when Claude finishes a task.
How hooks are configured
- Hooks are configured in
settings.json(also mentioned as.Claude/settings.json). - Configuration includes:
- Selecting an event
- Optionally setting a matcher to choose which tool(s) the hook applies to
- Providing the command to run
Hook events described
- User prompts: runs when a user submits a prompt before Claude processes it.
- Pre-tool use: runs before a tool call.
- Post-tool use: runs after a tool call completes.
- Notification: runs when Claude sends a notification.
- Stop: runs when Claude finishes responding.
Tutorial/guide examples
-
Auto-format after edits (most common hook)
- Use a
post-tool usehook with a matcher likeeditormulti-edit. - The command checks file extension and runs the appropriate formatter:
- prettier for TypeScript
- go format for Go
- ruff/rough for Python (as stated)
- Use a
-
Blocking operations with
pre-tool use- A pre-tool hook can prevent tool execution before it happens.
- The hook receives:
- the tool name
- the input as JSON on stdin
- Exit codes control behavior:
- Exit code
0→ proceed - Exit code
2→ block the action
- Exit code
- The STDERR message is returned to Claude as feedback so Claude can understand why it was blocked and adjust.
Team/project-level sharing
- Hooks in
.Claude/settings.jsonare project-level, so they can be checked into the repo. - This ensures the whole team gets identical enforcement.
- Suggested practice: use the
Claude project direnvironment variable in commands so scripts run correctly regardless of Claude’s current working directory.
Main takeaway / recommendation
- If something must happen every time (formatting, compliance logging, safety enforcement), put it in a hook, not in a prompt.
Main speakers/sources
- Unspecified (no named speaker provided in the subtitles).