A script you configure to run automatically in response to lifecycle events inside Claude Code - for example, before Claude executes a shell command, after it writes a file, or when a session ends. Hooks let you enforce project rules, post-process output, log activity, or trigger downstream actions without having to ask the model to remember to do them. A common use case is a pre-tool hook that blocks Claude from running certain destructive commands in production environments.

A hook is a script that Claude Code runs automatically when a specific event happens during a session - before it executes a shell command, after it edits a file, when a session starts or ends, and so on. Hooks turn 'please remember to do X' into 'X always happens', because they are enforced by the tool rather than relying on the model to remember an instruction. That distinction matters: a rule you write in CLAUDE.md is a strong suggestion, but a hook is a guarantee.

The most valuable use of hooks is guardrails. A pre-tool hook can inspect a command Claude is about to run and block it if it matches something dangerous - dropping a production database, force-pushing to main, deleting a directory. Because the hook runs deterministically before the command executes, it catches the action whether or not the model 'intended' it. Hooks are also used for post-processing (auto-formatting every file Claude writes), logging (recording every command for an audit trail), and triggering downstream work (kicking off a test run after an edit).

Hooks are configured in your Claude Code settings, where you map an event type to a command to run. They pair naturally with headless mode and automated pipelines: when Claude Code is running unattended in CI or a cron job, hooks are how you keep it inside safe boundaries with no human watching. For teams, a shared set of hooks is the simplest way to make sure every member's Claude Code sessions follow the same safety and quality rules.

Related terms

Put it to work

Learn it by building it

Definitions get you oriented. The club gets you shipping. Join Claude Code Club for $9/month.

Related: the full glossary, the learn hub, and our guides.