🪝 Free tool

Claude Code hooks generator

Pick what you want Claude Code to do automatically, copy one file. Every hook is tested on macOS, Linux and Windows. Or check the hooks you already have. Free, and nothing leaves your browser.

What should happen automatically?

Your computer
Customize protected files, test command, merge into your settings
Guide

What are Claude Code hooks?

Hooks are commands Claude Code runs on its own at set moments: before it uses a tool, after it edits a file, when it needs you, when it finishes. They turn "please always do X" into something that actually happens every time.

That's the difference from CLAUDE.md. A line like "run Prettier after editing" is advice: Claude usually follows it, but it can forget. A hook is code: it runs whether Claude remembers or not. Use CLAUDE.md for guidance and hooks for rules that must hold.

The events you'll use most

EventRuns whenGood for
PreToolUseBefore a tool runs; can block itBlocking dangerous commands, protecting files
PostToolUseAfter a tool succeedsFormatting edited files, logging commands
UserPromptSubmitWhen you send a prompt, before Claude sees itBlocking pasted secrets, adding context
NotificationWhen Claude needs your permission or inputDesktop notifications
StopWhen Claude finishes a replyRunning tests, "done" notifications
SessionStartWhen a session starts, resumes or is compactedLoading context, reminders after compaction
PreCompact / PostCompactAround context compactionSaving notes before details are summarized
SessionEndWhen the session closesQuick cleanup (it gets 1.5 seconds by default)

There are more (SubagentStop, PermissionRequest, PostToolUseFailure, ConfigChange, FileChanged…). Our checker knows all of them.

How the settings.json is laid out

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          { "type": "command", "command": "your command here" }
        ]
      }
    ]
  }
}

How a hook says yes or no

Exit codeMeans
0All good, carry on. On SessionStart and UserPromptSubmit, anything printed is added to Claude's context.
2Block it. The text written to stderr goes to Claude as the reason, so write something it can act on.
Anything elseThe hook failed, but Claude carries on. You see a "hook error" notice.

For finer control a hook can print JSON instead, for example to answer a permission prompt with allow, deny or ask. The generator sticks to exit codes, which are simpler and work everywhere.

Where the file goes

FileApplies to
~/.claude/settings.jsonAll your projects on this computer
.claude/settings.jsonThis project, for everyone (commit it)
.claude/settings.local.jsonThis project, just you (keep it out of git)

Hooks from all of these files run together. Changes are usually picked up without a restart; type /hooks in Claude Code to see what it loaded and from which file.

Hooks on Windows

Claude Code runs hook commands with sh on macOS and Linux, and with Git Bash on Windows (or PowerShell when Git Bash isn't installed). Most examples online pipe the input through jq, which Windows doesn't have. Add "shell": "powershell" to a hook and it always runs in PowerShell, which reads JSON natively with ConvertFrom-Json. Pick Windows in the generator and every hook is written that way, with nothing to install.

Stop hooks that never stop

A Stop hook that exits with 2 keeps Claude working, which is how "run the tests before finishing" works. If the tests keep failing, Claude keeps trying. Claude Code gives each Stop hook a stop_hook_active field that's true when it's already continuing because of a Stop hook: exit 0 when it's true, and Claude gets one retry instead of a loop. Our test hook does this, and the checker warns when yours doesn't.

Keep hooks safe

Sources: Claude Code: Hooks reference, Claude Code: Get started with hooks, Claude Code: Settings, Claude Code: Tools reference. Every command in the generator was run on macOS/Linux (sh) and Windows (PowerShell) with test input. Checked November 2026.

Next: give Claude your project's rules

Hooks enforce the must-never-happen rules. For everything else (the test command, the code style, the gotchas) write an AGENTS.md and CLAUDE.md. To connect Claude to GitHub, a browser or your database, use the MCP config generator.

FAQ

What are Claude Code hooks?

Hooks are commands that Claude Code runs automatically at set moments: before a tool runs, after a file is edited, when Claude finishes, when it needs your attention, and more. Unlike instructions in CLAUDE.md, which Claude can forget or skip, a hook runs every time.

Where do I put hooks?

In a settings file under a top-level "hooks" key. ~/.claude/settings.json applies to all your projects, .claude/settings.json applies to one project and is committed for your team, and .claude/settings.local.json is for one project and only you.

How does a hook block something?

Exit with code 2. For PreToolUse that stops the tool call, for UserPromptSubmit it blocks the prompt, and for Stop it makes Claude keep working. Whatever the hook writes to stderr is passed to Claude as the reason. Exit 0 means carry on; any other exit code is a non-blocking error.

Why doesn't my hook run?

The usual causes: a matcher with the wrong case ("bash" instead of "Bash"), an event name with the wrong case, a relative script path, a script that isn't executable (chmod +x), or jq not being installed. Type /hooks in Claude Code to see which hooks loaded. Paste your settings.json into the checker on this page to find the rest.

Do hooks work on Windows?

Yes. Claude Code runs hook commands in Git Bash on Windows, or in PowerShell when Git Bash isn't installed. Adding "shell": "powershell" makes a hook always run in PowerShell, which can read the hook's JSON input without jq. This generator writes PowerShell versions when you pick Windows.

Are hooks safe?

Hooks run with your full user permissions, without asking. Only add hooks you understand, and look at .claude/settings.json in any repo you clone before you trust the folder: Claude Code holds hooks back until you accept the workspace trust dialog.

Does this tool upload anything?

No. The generator and the checker run entirely in your browser. Nothing you type or paste is sent anywhere.

Esc

↑↓ moveEnter open