Skip to content
Lesson 7 of 1164% of the course

Add Claude Code hooks from ready-made recipes

Use the hook recipes in Config Studio for Claude Code to format every edit, run tests, refuse dangerous commands, guard secrets and get notified, in Bash, Python or Node.js, and check a hook fires before you install it.

Video coming soonAdd Claude Code hooks from ready-made recipesUntil then, the lesson below walks through every step.

A hook is your own script, run by Claude Code at a chosen moment: before a tool call, after an edit, when it is waiting for you, when a session starts. Hooks that run before something can refuse it. That makes them the most powerful part of a setup, and the easiest to get subtly wrong. Config Studio for Claude Code builds them from tested recipes.

Understand events and matchers

Every hook has an event (when it runs) and, for many events, a matcher (which cases it runs for). The events the recipes use include:

EventWhen it runs
PreToolUseBefore a tool call, and it can block it
PostToolUseAfter a tool call, for example after an edit
UserPromptSubmitWhen you send a prompt, before Claude sees it
NotificationWhen Claude Code needs your attention
StopWhen Claude finishes its turn
SessionStart and SessionEndWhen a session begins and ends
PreCompactBefore the history is summarised
SubagentStopWhen a subagent finishes

For tool events the matcher is compared with the tool's name, like Bash or Edit|Write. Edit|Write is a list of exact names: it does not match MultiEdit.

Pick a recipe

The library groups the 23 recipes by the event they run on.

Open Hooks. First pick What you work in (the language of your project), so recipes that run a formatter or type checker use the right one. Then add recipes. There are 23, for example:

  • Refuse dangerous commands and Keep secrets out of reach
  • Format every file Claude edits
  • Typecheck after an edit, and tell Claude what broke, and Run the tests after an edit
  • Stop yourself pasting a key, which checks your prompt before it is sent
  • Tell me when Claude is waiting and Tell me when the turn is finished
  • Tell Claude which branch you are on and Load project context when a session starts
  • Keep a log of every command and Save the transcript before it is summarised

Each recipe says what it does and what it risks. Some only read and report; others write a file they own.

Change a recipe to fit

Open a recipe to change its fields: the file patterns to format, the commands to refuse, the test command, and Matching, the matcher. Written in switches the generated script between Bash, Python and JavaScript. The patterns are written so they behave the same in all three.

Each hook has its own include box, so you can keep a recipe in the list but leave it out of the plan while you think.

Check the hook would run

A hook that never fires says nothing about it. Open Try it and pick Would this hook run? Choose the event, type the matcher, and what is happening (a tool name like Edit, or startup or resume for a session start). It answers whether the hook runs, and why not.

Know what a hook can do to your session

Hooks run without asking, with your permissions. Before you install one:

  • Read the generated script in the file preview. It is short
  • Prefer recipes that only report, until you trust the ones that act
  • Remember a project's .claude/settings.json can carry hooks too, so cloning a repository can bring hooks with it

Take it away

The hooks are registered in ~/.claude/settings.json and each script is written to ~/.claude/hooks/. Open Changes to see every file, then install with the script, as in the last lesson of this course.

The next lesson is about making your own agents, skills and commands.

Your progress stays in this browser only.
Contact