Free tool

Claude Code hooks generator: build the hooks block for settings.json

Claude Code hooks generator: pick a hook event, a matcher and a shell command, and get a valid hooks block for settings.json to merge into your file.

  • Free, no sign-up
  • Runs in your browser
  • Nothing uploaded

Start from a recipe

Your hooks


    

If the file already has settings, merge the "hooks" key into it. Run /hooks in Claude Code to check what loaded.

Runs in your browser. Nothing you type or upload is sent to our server.

Hooks are shell commands (or HTTP calls, MCP tool calls or model prompts) that Claude Code runs at fixed points in its lifecycle, such as before a tool runs or when Claude finishes a reply. Unlike instructions in CLAUDE.md, a hook always runs. This tool writes the JSON for you so the nesting and field names are right.

How do I use this tool?

  1. Choose an event, for example PostToolUse.
  2. If the event supports matchers, enter one, such as Edit|Write. Leave it empty to match everything.
  3. Enter the command and an optional timeout in seconds.
  4. Add more handlers or events if needed, or load a recipe.
  5. Copy the JSON into the right settings file and run /hooks in Claude Code to confirm it appears.

What does the hooks JSON look like?

The structure has three levels: event, then a list of matcher groups, then a list of handlers.

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          { "type": "command", "command": "jq -r '.tool_input.file_path' | xargs npx prettier --write", "timeout": 60 }
        ]
      }
    ]
  }
}

Handler types are command, http, mcp_tool, prompt and agent (agent is experimental). The default timeout is 600 seconds for command, http and mcp_tool, 30 for prompt and 60 for agent. Hook input arrives on stdin as JSON with fields such as tool_name and tool_input.

Which events accept a matcher?

EventMatcher filters
PreToolUse, PostToolUse, PostToolUseFailure, PermissionRequest, PermissionDeniedTool name, e.g. Bash, Edit|Write, mcp__.*
SessionStartstartup, resume, clear, compact, fork
SessionEndclear, resume, logout, prompt_input_exit, other
NotificationType, e.g. permission_prompt, idle_prompt
SubagentStart, SubagentStopAgent type
PreCompact, PostCompactmanual, auto
FileChangedLiteral filenames, e.g. .envrc|.env
Stop, UserPromptSubmit, PostToolBatch, CwdChanged and othersNo matcher, fires every time

The tool lists all 33 documented events. A matcher made only of letters, digits, _, -, spaces, commas and | is an exact name or list. For FileChanged and StopFailure, only letters, digits, _ and | count as an exact list, so separate values with |. Anything else is an unanchored JavaScript regex, so Edit.* also matches NotebookEdit. A matcher on an event without matcher support is ignored. Full details are in the hooks reference.

What do exit codes mean?

  • 0: success. If stdout is a single JSON object it is parsed for fields such as decision, continue or hookSpecificOutput.
  • 2: blocking error. On PreToolUse the tool call is blocked and stderr goes to Claude as the reason. On Stop Claude keeps working.
  • Any other code: non-blocking error. The action goes ahead. Exit 1 does not block, unless a command or http hook sets "onFailure": "block" (Claude Code v2.1.295 or later).

Where do I put the hooks block?

Use ~/.claude/settings.json for all your projects, .claude/settings.json to share with your team through git, or .claude/settings.local.json for this project only. Managed policy settings apply to a whole organisation. Settings precedence from highest is managed, command line, local project, shared project, then user. Claude Code reloads settings files when they change, so most hook edits apply without a restart. In commands, use "$CLAUDE_PROJECT_DIR" to reach scripts in your repository.

Recipes included

  • Format after edit: PostToolUse, matcher Edit|Write, runs Prettier on the edited file.
  • Block edits to .env: PreToolUse, matcher Edit|Write, runs a script that exits 2 when the path contains .env.
  • Notify when Claude needs you: Notification with osascript on macOS, notify-send on Linux or a PowerShell message box on Windows.
  • Run tests before stopping: Stop hook that runs your test command and exits 2 on failure, after checking stop_hook_active.
  • Git status at session start: SessionStart, matcher startup|resume, runs git status --short --branch. Its stdout is added as context.

Common mistakes

  • Using exit 1 to block. Only exit 2 or a JSON decision blocks, unless you set onFailure to block.
  • A Stop hook that never checks stop_hook_active. Claude Code overrides a Stop hook after eight blocks in a row with no tool call in between, but your hook should exit early itself.
  • Forgetting chmod +x on hook scripts on macOS and Linux.
  • A bare mcp__memory matcher. It matches nothing; use mcp__memory__.*.
  • Assuming jq is installed. The official recipes use it to read stdin.

Hooks work best next to a clear CLAUDE.md and well-scoped skills. For the step-by-step guide, see the official hooks guide. Need hooks wired into CI or your internal tools? See our custom software development service.

Last updated: October 19, 2026

Questions, answered

Questions about the Claude Code Hooks Generator.

Still unsure? Ask the developer directly on a free 30-minute call.

Book a free consultation
What are Claude Code hooks?

Hooks are commands that Claude Code runs automatically at set points, such as before a tool runs or when Claude finishes. They always run, so they suit rules that must be enforced.

Where do I add hooks in Claude Code?

Add a hooks block to ~/.claude/settings.json for all projects, .claude/settings.json to share with your team, or .claude/settings.local.json for yourself only.

What does exit code 2 mean in a hook?

Exit code 2 is a blocking error. On PreToolUse it blocks the tool call and sends stderr to Claude as the reason.

Does exit code 1 block an action?

No. Any exit code other than 0 or 2 is a non-blocking error and the action goes ahead, unless the hook sets onFailure to block. Use exit 2 to enforce a rule.

What is the default hook timeout?

Command, http and mcp_tool hooks default to 600 seconds. Prompt hooks default to 30 seconds and agent hooks to 60 seconds.

How do I match more than one tool?

Separate tool names with a pipe character or a comma, for example Edit and Write joined by a pipe. Leave the matcher empty or use an asterisk to match every tool.

How do I check that my hook is loaded?

Type /hooks at the Claude Code prompt to open the hooks browser and look for your hook under its event.

Why does my Stop hook keep Claude running?

A Stop hook that exits 2 tells Claude to keep working. Read stop_hook_active from the input and exit 0 when it is true to avoid a loop.

Your developer Jamshaid Ali Founder, Handicraft Marketing

Need a tool like this built for your business?

We build fast WordPress sites, custom calculators and software that run your daily work. Tell us what you need and get a clear plan within 24 hours.

  • Reply within 24 hours
  • Free plan, no obligation
  • Talk directly to the developer
Direct WhatsApp
Book Free Consultation