Claude Hooks
Shell commands Claude Code runs automatically at lifecycle events (before/after a tool call, on session start, on stop) to enforce policies or automate work.
Hooks are configured in ~/.claude/settings.json (global) or .claude/settings.json (per-project) under the hooks key. Each entry has a matcher (event name + tool pattern) and a command. The runtime executes the command synchronously and waits for it to finish before continuing.
Common patterns: auto-format on PostToolUse Edit (run biome/prettier after every file edit), block destructive commands on PreToolUse Bash (exit 1 if you spot rm -rf), inject context on SessionStart (cat docs/CONTEXT.md), notify Slack on Stop (curl webhook). A PreToolUse hook that exits with code 1 blocks the tool call, and the error message is surfaced to Claude so it can adjust its plan.
Hooks run with your user's permissions — they can read, write and execute anything you can. Keep them fast (a few seconds max), since a hung hook hangs Claude.