Hooks
Hooks are scripts the agent runtime runs automatically on events, such as before or after a tool call, to enforce rules or automate steps.
Hooks are scripts the agent runtime runs automatically at points in a session, such as before a tool runs, after a file is edited, or when a session ends. Because the runtime runs them, not the model, they fire every time rather than when the agent remembers to.
In Claude Code, hooks live in .claude/settings.json, keyed to events. The main ones are PreToolUse and PostToolUse around each tool call, plus UserPromptSubmit, SessionStart and Stop. This one runs a formatter after every edit:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{ "type": "command", "command": "npx prettier --write ." }
]
}
]
}
}
Swap the command for a linter, a test run, or a PreToolUse hook that denies a dangerous tool call outright.
Checked against Hook events and configuration (2026-10-23) .