Module 09 of 11

Hooks

Lessons

About This Module

A rule in CLAUDE.md is a request. Claude usually follows it, but it can forget or skip it. A hook is different: it is code that Claude Code runs at a fixed point in its lifecycle, every time, whether or not the model remembers. Prompts say what Claude should do. Hooks enforce what it must do.

This module covers the hook events such as PreToolUse, PostToolUse, UserPromptSubmit, Stop, and Notification. It explains the JSON a hook receives and how exit codes decide the outcome, where exit 2 blocks and exit 1 does not. You will see practical hooks that block dangerous commands, protect secret files, auto-format edits, and alert you when Claude needs you. Because hooks run real code with your credentials, you will also learn to review them like any other script.

Watch the lessons in order, then continue on to Git, GitHub & CI/CD.

Lessons

4 videos
01

Claude Code Hooks Explained: Automate Development Tasks

A beginner lesson from STEP BY STEP CODING that introduces hooks for actions such as formatting code, running tests, and checking commands. It is Part 7 of a beginner Claude Code course, so it is a gentle starting point.

02

Claude Code Hooks: What a Hook Is, PreToolUse vs PostToolUse and Exit Codes

Part 1 of the ambariCloud Hooks & guardrails series. It separates "should" in prompts from "must" in hooks, shows the JSON a PreToolUse hook receives on stdin, and explains why only exit 2 blocks a tool. The demo runs four hooks: two PreToolUse guards, a PostToolUse formatter, and a Notification alert.

03

Claude Code Hooks: Explained & Demoed

TechXion sets up four hooks from scratch and demos each one: a PreToolUse hook that blocks rm -rf and writes to .env, a hook that auto-formats every file Claude touches, a Stop hook that makes Claude verify tests pass, and an async desktop notification. It also covers hook events, handler types, and where hooks are configured.

04

Claude Code Hooks Explained in 5 Minutes

A quick tour of all the Claude Code hook features and how they work, with a companion repository that implements all 13 hooks using audio feedback so you can hear them fire. Use it as a fast review of the full set of events after the earlier lessons.