← Back to the A-Z glossary
AI glossary · P1

Hook

A hook triggers an automatic action before or after certain moves the agent makes.

Automation 4 min read Updated 2026-05-22
— Definition

Hook, in plain words

A hook triggers an automatic action before or after certain moves the agent makes.

Present the hook as a silent reflex: before a commit, after a tool use, and so on.

A concrete example

I wire up a PostToolUse hook that formats the code after every edit. Claude no longer has to think about it, it just happens.

Why it matters

Hooks make the agent reliable. They bake in rules you don't want to keep reminding it about by hand.

You see it in Claude Code, to block a command, run a formatter, or check a file that just changed.

Don't mix it up with

Claude Code: Claude Code is Claude's agent: it reads a project, edits files, and runs commands with your approval.

CLAUDE.md: CLAUDE.md is the file where you write down a project's rules so Claude doesn't start from scratch.

Common mistakes

  • Putting slow code in a hook and dragging down every action.
  • Forgetting a hook can block an action by returning an error.
  • Storing secrets in a hook instead of a .env file.

Quick checklist

  • First I check whether the word names a concept, a tool, a risk, or a metric.
  • I tie it to a concrete case: I wire up a PostToolUse hook that formats the code after every edit. Claude no longer has to think about it, it just happens.
  • I keep the main trap in mind: Putting slow code in a hook and dragging down every action.

Quick questions

What is Hook in AI?

A hook triggers an automatic action before or after certain moves the agent makes.

Where will I run into Hook?

You see it in Claude Code, to block a command, run a formatter, or check a file that just changed.

Which word should I read next?

Start with Claude Code, CLAUDE.md, Slash command.

Want to keep going in order?

Head back to the full glossary, search a word, then open only the pages that deserve more than a short definition.

Open the AI glossary