Course/Scale/Lesson 1

Lesson 3.1: Introduction to Hooks

Duration: 20 min

Learning Objectives

  • Understand what Claude Code hooks are and when they add value
  • Know four common hook types and what triggers each one
  • Identify hook opportunities in your own workflow
🎯 What You'll Learn: What hooks are, what business problem they solve, and how to spot opportunities to use them in your work
⏱️ Time Required: 20 minutes
πŸ’‘ Beginner clarification:

In this course, hooks refer to Claude Code automation workflows triggered by files and events, not advanced API webhook infrastructure. You won't configure any hooks yourself, that's Claude's job. Your job is to recognise when one would help.

Riley's Problem

Riley's Monday margin report skill has been running for three weeks. But she noticed something unsettling:

"Every time Claude edits one of my data files, I have no record of what changed. And once, it overwrote a file I hadn't backed up. I also realised: if something goes wrong overnight, I'd have no audit trail. In a regulated environment, that's a problem."
β€” Riley Harper

This is exactly the problem hooks solve.


What a Hook Looks Like in Practice

When something happens inside a Claude session, Claude can automatically react to it.

For example, every time Claude writes a file:

  • Log the file name and timestamp
  • Send you a notification
  • Trigger a follow-on task
  • Create an audit record for compliance
  • This automatic reaction to an event is called a hook.

    Claude writes a file
           ↓
    Hook fires automatically
           ↓
    File name + timestamp logged
           ↓
    You have a full audit trail
           ↓
    Compliance team is happy
    

    What Hooks Actually Are

    Hooks are standing rules that apply to everything Claude does during a session, before or after Claude takes an action, when a task finishes, or when Claude sends you a message.

    Once set up, they run without you thinking about them.

    The key difference from skills and agents:

    Skills / AgentsHooks
    What they doTell Claude what to accomplishReact automatically to what Claude does
    Who triggers themYou ask Claude to use themFire automatically, no prompting needed
    Best forGetting work doneLogging, validation, notifications, chaining

    Four Hook Types Worth Knowing

    PreToolUse, fires before Claude takes an action

    Good for: checking something is safe before it happens, logging what Claude is about to do.

    PostToolUse, fires after Claude takes an action

    Good for: recording what changed, triggering follow-on steps, notifying you when something specific happens.

    Notification, fires when Claude sends you a status message

    Good for: routing Claude's updates to Slack, email, or a log file instead of just the terminal.

    Stop, fires when Claude finishes responding

    Good for: triggering the next step in a pipeline, sending a completion alert, archiving outputs.

    These four cover the most common needs. Claude Code has more hook events (for example, one that fires before context is compacted, or when a subagent finishes). You don't need them now, ask Claude what's available when a specific need comes up.

    Business Use Cases

    Hooks are particularly valuable in regulated, high-accountability environments:

    Audit and compliance

    Every time Claude edits a file β†’ log the file name, timestamp, and session ID. Your compliance team gets a full record of what changed and when, without anyone maintaining it manually.

    Notifications

    When a long-running automation finishes β†’ send a Slack message. You find out the moment it's done, not when you remember to check.

    Chaining automations

    When one task finishes β†’ automatically start the next. Riley's pipeline: report runs β†’ validation runs β†’ notification sends. Nobody pressed a button.

    Safety checks

    Before Claude touches a critical file β†’ verify a backup exists. If not, stop and alert you first.


    Exercise: Spot Your Hook Opportunities

    ⏱️ Total Time: 20 minutes

    This is a thinking exercise, not a technical one. Your goal is to describe what you'd want, not to build it.

    Step 1: Work through these questions (10 min)

    After Claude does something:

  • When Claude finishes a task, would you want to know immediately, via Slack, email, or a log?
  • Are there actions Claude takes where you'd want a permanent record?
  • Is there anything that should automatically happen after Claude finishes?
  • Before Claude does something:

  • Are there critical files or systems where you'd want a safety check before Claude touches them?
  • When Claude sends you a message:

  • Are there notifications you'd rather receive somewhere other than your terminal?
  • Step 2: Write your hook opportunities in plain English (10 min)

    For each opportunity you identified, write one sentence. Clear enough to hand to Claude or a developer.

    Riley's examples:

  • "Every time Claude writes a file, log the file name and timestamp to ~/audit-log.txt."
  • "When Claude finishes any session, send me a Slack message saying the task is complete."
  • "Before Claude runs any shell command, log the command so I have a compliance record."
  • Yours:

  • Hook 1: _______________
  • Hook 2: _______________
  • Hook 3 (optional): _______________
  • πŸ’‘ To set up a hook: Take your plain-English description to Claude Code and say: "I want to add a hook that does this: [your description]. Can you add it to my settings?" Claude writes the configuration, you verify it makes sense.

    βœ… Success Criteria:

    You can explain these four common hook types and give one example use case for each
    You've identified at least two hook opportunities in your own workflow
    You've written a plain-English description of each, clear enough to hand to Claude

    What Riley Learned

    "Hooks aren't about telling Claude what to do differently, they're about what happens around Claude's actions. The audit log gave me back confidence: I can see exactly what changed, when, and whether anything went wrong. In a regulated environment, that's not a nice-to-have. It's required."

    Want to Go Deeper?

    This lesson covers hooks at the conceptual level, enough to use them confidently in your work.

    If you want to understand the full technical implementation, shell commands, JSON configuration, environment variables, Anthropic Academy covers that ground.


    Next Up

    Lesson 3.2: Scheduled Automation

    Hooks respond to events inside a Claude session. Scheduling handles something different: making Claude run automatically at a specific time, Monday 8am, daily at 9am, whenever you need it, without anyone pressing a button.

    AI Automation Academy is an independent course created by Mercedes Perez-Capilla. It is not affiliated with, endorsed by, or produced by Anthropic. Claudeβ„’ is a trademark of Anthropic. All tool references are for educational purposes.