loading
loading
Shell commands Claude Code runs automatically at lifecycle events like before a tool call or after the agent stops.
Hooks are configured in settings.json (events like PreToolUse, PostToolUse, Stop) and the harness — not the model — executes them deterministically, which is why automation like 'always run prettier after an edit' belongs here rather than in a memory or prompt. A PreToolUse hook can even block a tool call by exiting non-zero, giving you a hard gate the model can't talk its way past. Example: a PostToolUse hook on Edit that runs eslint --fix on the changed file, or a Stop hook that pings you when the agent finishes. Because they're code, they're reliable in a way 'please remember to...' instructions never are.
Plainly
Think of Hooks as a tool from the builder toolbox. Shell commands Claude Code runs automatically at lifecycle events like before a tool call or after the agent stops.
In practice
Use it when you are installing, editing, testing, reviewing, or shipping code. In practice, define the owner, input, output, and failure mode before you rely on it.