What are Hooks? (in Claude Code)

What they are: Small scripts that run automatically before or after Claude Code takes certain actions — without you having to ask.
Who they’re for: Anyone using Claude Code who wants to add consistent, automatic behavior to their AI workflow.
Best if: You want something to happen every time the AI does a particular thing — format a file after editing, check content before sending, log actions to a record.
Skip if: You’re using AI only for one-off tasks that don’t need any automated follow-through.

Most people use AI by asking it to do things. Hooks let you set up behaviors that happen automatically, whether you ask or not.

In Claude Code, a hook is a script — a small piece of automation — that fires at a specific moment. That moment is called a trigger. Claude Code supports two types:

  • Pre-action hooks — run before the AI does something. A pre-action hook might check a file for sensitive content before the AI sends it anywhere.
  • Post-action hooks — run after the AI does something. A post-action hook might auto-format a file after the AI has finished editing it, so the code is always clean.

You write a hook once. After that, it runs silently every time the trigger fires. You don’t need to remind the AI to do the hook thing — it happens in the background, like a rule baked into the system rather than a request you repeat each session.

A few practical examples:

  • A hook that runs after any file edit to automatically run a formatting tool
  • A hook that runs before any message is sent to log it to a record
  • A hook that runs when Claude Code stops to post a summary to Slack

Hooks are the “if this, then that” layer sitting underneath your AI’s actions. They’re how you turn a capable AI into a consistent, automated workflow.

Related

Get Smarter About AI Every Morning

Free daily newsletter — one story, one tool, one tip. Plain English, no jargon.

Free forever. Unsubscribe anytime.

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