Claude Code hooks, explained

Hooks are shell commands Claude Code runs automatically on lifecycle events. They turn conventions you keep repeating into deterministic automation — the machine enforces them, not a markdown reminder.

The events

PreToolUse
Runs before a tool call. Can block it — e.g. refuse a destructive git command or an edit outside the project.
PostToolUse
Runs after a tool succeeds. Great for auto-formatting a file Claude just wrote, or running the type checker.
Stop
Runs when Claude finishes a turn. Use it to run tests, or to display a summary.
Notification / UserPromptSubmit
React to prompts and notifications — log commands, inject context, or gate actions.

Common uses

Where they live
Hooks are configured in your settings (.claude/settings.json). A hook can block an action, inject context, or just run a command. Because they are deterministic, they are the reliable way to enforce guardrails.
Ready-made hooks

Browse Claude Code hooks and other configs on ConfigDeck and install into .claude/ in one click.

Browse the marketplace →

FAQ

How does a hook block a tool call?
If the hook script exits with code 2, the tool call is refused before it runs.
Where are hooks configured?
In settings.json (project or ~/.claude/), under hooks.<EventName>.
What event types exist?
PreToolUse, PostToolUse, Stop, SessionStart, SubagentStop and UserPromptSubmit, among others.
Are hooks enough for safety on their own?
No — pair them with permissions (allow/deny) for defense in depth.