Free hooks builder · Runs in your browser

Claude Code hooks, without the JSON pain

Hooks are the most powerful (and most mistyped) feature in Claude Code. Pick an event, set a matcher and command, and get a valid settings.json — auto-format on save, block dangerous edits, log every command, get notified.

Hook 1
Valid hooks config — paste into .claude/settings.json
{
  "hooks": {
    "PostToolUse": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "jq -r '.tool_input.file_path' | { read f; [[ \"$f\" == *.ts || \"$f\" == *.tsx ]] && npx prettier --write \"$f\"; } || true"
          }
        ],
        "matcher": "Edit|Write"
      }
    ]
  }
}

100% client-side · hooks run shell commands — only use commands you understand

The events

Nine places to intercept Claude Code

Hooks turn "please always run prettier" from a hope in CLAUDE.md into a guarantee — the app runs your command every time, deterministically.

🛡️

PreToolUse

Runs before a tool call and can block it: exit code 2 stops the action and sends stderr back to Claude. The place for guardrails — protect .env, block rm -rf, enforce your deploy process.

🪄

PostToolUse

Runs after a tool succeeds. The classic: match Edit|Write and auto-format the touched file. Also great for type-checking, test-triggering, and change logs.

💬

UserPromptSubmit & Stop

Inject context or validation when you submit a prompt; run cleanup, linters, or notifications when Claude finishes a response (or a subagent does).

🔄

Session & compaction

SessionStart loads context when you begin or resume; PreCompact fires before Claude compresses history; SessionEnd is your teardown hook.

Recipes

The four hooks everyone ends up wanting

Auto-format every edit

PostToolUse on Edit|Write → read the file path from the event JSON with jq, run prettier/ruff/gofmt on it. Claude's edits always land formatted.

Protect sensitive files

PreToolUse on Edit|Write → if the path matches .env, keys, or lockfiles, exit 2 with a reason on stderr. Claude sees why and works around it.

Audit every bash command

PreToolUse on Bash → append the command + description to a log file. A complete audit trail of everything Claude ran, for free.

Ping when it needs you

Notification → osascript (macOS) or notify-send (Linux). Walk away from long sessions; get pinged the moment Claude is waiting on you.

FAQ

Hooks questions

What data does my hook command receive?+
The event payload as JSON on stdin — session id, tool name, and tool_input (for tool events the exact arguments, like .tool_input.file_path or .tool_input.command). jq is the standard way to pull fields out.
What's the difference between exit codes 0, 2, and others?+
0 = success (stdout shown in transcript; for UserPromptSubmit it's added as context). 2 = blocking error — stops the action and feeds stderr to Claude. Anything else = non-blocking error shown to you.
Which settings file should I use?+
.claude/settings.json for team-shared project hooks (committed), .claude/settings.local.json for personal project hooks (gitignored), ~/.claude/settings.json for hooks you want everywhere.
Why isn't my hook firing?+
Check: the JSON is under a top-level hooks key, the event name is exact (case-sensitive), the matcher matches the real tool name, and you restarted Claude Code — hooks are snapshotted at startup, so run /hooks to verify what's loaded.
Can hooks run scripts instead of inline commands?+
Yes, and for anything non-trivial you should: point the command at a script ("$CLAUDE_PROJECT_DIR"/.claude/hooks/check.sh) so it's versioned, testable, and readable instead of a one-line jq puzzle.
Go further

Hooks are one piece of the setup

The ClaudeThings kits ship complete Claude Code environments — agents, skills, and commands engineered to work together, hooks-friendly out of the box.

🛠️
Most popular

Engineering Kit

Battle-tested Claude skills & workflows for builders.

  • 58 agents · 61 skills · 159 commands
  • Security, testing & code-review skills
  • Every skill formatted to spec
  • Lifetime updates
Get the Engineering Kit
📣
For founders

Marketing Kit

Turn Claude into your growth team.

  • 31 agents · 42 skills · 32 commands
  • Content, SEO & email-sequence skills
  • Landing-page & funnel templates
  • Lifetime updates
Get the Marketing Kit

Or grab all 89 agents, 103 skills & 181 commands in the Complete Bundle →