Page languageFrançaisEnglish
Teacher area
Laurent PoupetClaude trainer and artificial intelligence architectStudent area

Category · Development and code

What are hooks in Claude Code?

Hooks are scripts that Claude Code runs at precise moments. For example, a hook can block a tool call before it runs, or run the tests after every edit. Another one stops the agent from finishing while the tests fail.

By , Claude trainer and artificial intelligence architect · Updated

How it works

  • A hook receives the tool call in JSON (JavaScript Object Notation), with the tool name and its arguments. It decides by reading these fields, then answers with its exit code or with a document.
  • Other moments exist, such as submitting a request or starting a session. A startup hook can add context, for example the target environment or the rules of the day.
  • A hook that blocks wins over allow rules, but a hook that allows never lifts a deny rule. Denial always comes first.

The trap to avoid

The trap is a slow or fragile hook, run on every tool call. Keep it short, with a maximum timeout set, and test it like production code.

A concrete example

A hook placed before every tool call reads the command Claude Code is about to run. If it sees a folder deletion outside the project, it answers with exit code 2 and the command does not run. A second hook, placed after every file change, formats the code without you having to ask.

What is the difference with an instruction written in CLAUDE.md?

CriterionHooks in a coding assistantan instruction written in CLAUDE.md
NatureA script that runsA text the model reads
StrengthBlocks every timeThe model follows it most of the time
Good fitA ban that must always holdA habit, a convention

Related terms

Where this is taught

Lesson content (step-by-step instructions, exercises with solutions, quizzes) is for students only, with an access code received after the first lesson.

See the full program

Sources

All glossary terms

Trial lesson · 30 min · $20

Book (new tab)