Vibe Coder · Unit 9: Claude Code Commands and Extensions · Lesson 7 of 10

Hooks

Engineers: hooks run your own commands at set moments, so formatting, checks and guards happen every time without relying on the model.

Read the short notes and pictures.Do everything inside a blue frame.

Deterministic behaviour

A model follows instructions most of the time. Hooks are for the things that must happen every time. They are shell commands that Claude Code runs at defined points in its loop, regardless of what the model decides.

A 3D scene of coloured blocks and cards. Moments: before a tool, after an edit, on stop.
Before a tool, after an edit, on stop.

Useful hooks

Format on edit

Run your formatter on every file the agent changes.

Guard

Refuse edits to migrations, generated code or environment files.

Verify on stop

Run type-check and tests before the agent reports back.

Notify

Tell you when a long task finishes.

A 3D scene of coloured blocks and cards. Use them to: format edited files, block protected paths, run tests at the end.
Format, block and test automatically.

Writing one safely

  1. Start with one

    Formatting is a good first hook.

  2. Keep it fast

    It runs often.

  3. Make failure clear

    Return a message the agent can act on.

  4. Review it like code

    A hook runs with your permissions.

ActivityBuild stepYour Claude Code setup

Add a formatting hook and a guard

Add a hook that formats files after edits and one that blocks changes to your environment files. Prove both by asking the agent to do each thing.

Done when

Add a stop hook for your checks when you have tests.

Keep these

  • Hooks run your commands at set moments.
  • Use them for what must always happen.
  • Keep them fast and reviewed.