Best Claude Hooks
Claude Code hooks for automation, safety, and custom behavior.
What are Claude Code Hooks?
Claude Code hooks are shell commands the runtime executes at specific lifecycle events, before a tool runs (PreToolUse), after a tool runs (PostToolUse), when Claude stops (Stop), when the session starts (SessionStart) and so on. They let you automate guardrails, validations, formatters and notifications without modifying Claude itself.
Common patterns: auto-format code after every Edit (PostToolUse → biome/prettier), block dangerous commands before they run (PreToolUse → fail if rm -rf), notify Slack when Claude stops a long task (Stop → curl webhook), inject context at the start of every session (SessionStart → cat file). Hooks are configured in ~/.claude/settings.json or per-project .claude/settings.json.
The directory below catalogues 25+ open-source hook collections, guardrails, formatters, observability, dispatch, ranked by stars and Trust Score.
Questions about Hooks
Where do I configure Claude Code hooks?+
Two places: ~/.claude/settings.json (global) and .claude/settings.json (per-project). Each hook entry has a matcher (event name + tool pattern) and a command. Run claude config to see the current resolved config.
Can a hook block Claude from running a tool?+
Yes. A PreToolUse hook that exits with code 1 blocks the tool call. The error message is surfaced to Claude so it can adjust its plan. This is how guardrails like 'no rm -rf in production' or 'never edit prod config files' are implemented.
Do hooks run synchronously?+
Yes. Claude Code waits for each hook to finish before continuing. Keep them fast (under a few seconds) or wrap slow work in a background process. A hung hook hangs Claude.
Can I share hooks across teammates?+
Yes, commit your project's .claude/settings.json. Anyone cloning the repo gets the same hooks. For shell scripts referenced by hooks, also commit them under .claude/scripts/ or similar so the references resolve.
What's the most useful hook to add first?+
Auto-format on PostToolUse Edit. It's small (3-5 lines of JSON), it fixes a recurring annoyance (Claude's whitespace), and it costs zero CPU. From there, add a PreToolUse Bash hook to block destructive commands. Those two cover 80% of hook value.