Skills & Workflow

Hook

A hook is a piece of code or a check that runs automatically at a defined point in an agent's action lifecycle, typically just before or just after the agent does something.

Before actionHookAction runs
A hook runs at the checkpoint before the action executes.

Agents take actions — running a command, editing a file, calling a tool. A hook is a way to intercept that lifecycle at a specific point without changing the agent's own reasoning: a shell command or script that the harness runs automatically before an action executes, after it completes, or at another defined lifecycle point.

Hooks are commonly used for things the agent itself shouldn't have to reason about every time: logging every command run, formatting a file after it's edited, or requiring confirmation before a risky command executes. Because a hook runs deterministically (not via the model deciding to do it), it's a reliable place to put behavior that must always happen, or must never be skipped.

Claude Code's hooks are a concrete real-world example: they're configured in settings (matching on events like a tool being about to run, or having just run) and can inspect, log, or block the action they're attached to.

How it works

A hook is registered against a lifecycle event — before a specific type of action, after one completes, and so on. When that event occurs, the harness runs the hook's command and, depending on the hook's design, may use its output or exit status to decide whether to proceed, modify what happens next, or simply record what occurred.

Example

A hook configured to run before any file-editing tool executes might block edits to files under secrets/, returning an error that stops the action rather than letting the agent write to that path.

How it differs

Hook vs. trigger: a trigger starts an entirely new agent run from an external event; a hook runs inside an already-active run, intercepting one specific action within it.

Common misconceptions

Often assumed: Hooks can only log or observe, not change what happens.
Actually: Depending on the implementation, a hook can also block an action outright or ask for human confirmation before it proceeds — it isn't limited to passive logging.

FAQ

What is a hook in Claude Code?
A command that runs automatically before or after a specific kind of action, configured in settings — used for things like logging, formatting, or blocking risky actions.
What's the difference between a hook and a trigger?
A trigger starts a new agent run from an external event; a hook runs inside a run that's already active, around one specific action.

Last checked: 2026-08-28

Related terms