What Are Claude Code Hooks? — AI Glossary

What it is: Claude Code hooks are shell commands that fire automatically at 25 lifecycle points (PreToolUse, PostToolUse, Stop, etc.). They enforce deterministic guardrails — run tests after every edit, block dangerous commands, gate session completion on verification.
Who it is for: Developers using Claude Code who want guardrails that always fire, not advisory rules.
Best if: You want a one-page reference for the hook types and what they’re for.
Skip if: You haven’t installed Claude Code yet. Start with Claude Code Beginners Guide first. Want one practical AI workflow every morning? Subscribe to our free daily newsletter.

What is Claude Code Hooks?

Claude Code hooks are shell commands that fire automatically at specific lifecycle points during a Claude Code session. They are configured in .claude/settings.json or via the /hooks command. As of May 2026, Claude Code exposes 25 hook lifecycle points including PreToolUse (before any tool runs), PostToolUse (after a tool runs), Stop (when the agent claims done), SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, and Notification.

Why does Claude Code Hooks matter?

Anthropic’s official rule, from the Claude Code best-practices doc: “Unlike CLAUDE.md instructions which are advisory, hooks are deterministic and guarantee the action happens.” If you absolutely need something to fire every time — run the test suite after every edit, block rm -rf, alert when context utilization passes 75% — a hook is the right tool. CLAUDE.md instructions are easy for the model to bend; hooks are not. The single highest-value hook for most projects is a PostToolUse that runs your test command. It converts “agent says done” from a subjective claim into an objective yes/no signal.

How does Claude Code Hooks work?

Each hook is defined as a shell command paired with a trigger condition. Example PostToolUse hook that runs the test suite after any file edit:

{
  "hooks": [
    {
      "event": "PostToolUse",
      "matcher": "Edit|Write",
      "command": "npm test"
    }
  ]
}

If the command exits non-zero, the agent gets the failure as feedback. Hooks can also block actions (returning a non-zero exit from PreToolUse), notify external systems, or log to your observability platform.

Related terms

Learn more on Beginners in AI

Sources and further reading

Last reviewed: May 2026. AI terminology evolves quickly — verify specifics on the official source pages above.

Get Smarter About AI Every Morning

Free daily newsletter — one term, one tool, one tip. Plain English.

Free forever. Unsubscribe anytime.

You may also like

Two ways to go further

The AI Prompt Library

1,000+ ready-to-use prompts for Claude, ChatGPT, and Gemini. Stop staring at a blank box.

Get it for $39 →

2-Hour Live AI Crash Course

A private, beginner-friendly session across Claude, ChatGPT, Gemini, and the wider landscape.

Book for $125 →

Discover more from Beginners in AI

Subscribe now to keep reading and get access to the full archive.

Continue reading