Claude Code Hooks Generator
Pick lifecycle events and actions to generate valid Claude Code hooks JSON plus example hook scripts.
It writes the settings that run your own checks before and after the AI acts.
What this tool does
Claude Code hooks run shell commands at lifecycle events such as PreToolUse, PostToolUse, and Stop. The JSON shape with matchers and hook arrays is easy to get wrong. This generator builds the settings block and starter scripts for common patterns like blocking dangerous commands or logging tool use.
- Block risky shell commands before they run
- Run a formatter or linter after every file edit
- Log agent activity or send notifications when a session stops
Tool-name regex (e.g. Bash, Edit|Write). Leave empty to match all tools.
Shell command to run. Exit 0 allows or continues; exit 2 blocks on PreToolUse.
| Event | Matcher | Command | |
|---|---|---|---|
|
Paste the hooks block into
.claude/settings.json (project) or
~/.claude/settings.json (user). Hooks run with your full
user permissions, so review every command before saving.
Blocking PreToolUse hook script. Reads JSON from stdin, checks the Bash
command for rm -rf, prints to stderr and exits 2 to block.
Hook definitions and scripts are generated entirely in your browser. Nothing is uploaded or stored on a server.
Claude Code hooks run shell commands at lifecycle events such as
PreToolUse, PostToolUse, and Stop. The settings live under the
hooks key in settings.json, grouped by event
with optional tool matchers and command entries.
PreToolUse and PostToolUse accept a matcher regex to target specific tools. Exit code 2 on PreToolUse blocks the tool call and feeds stderr back to Claude. Use this generator to assemble valid JSON, then save hook scripts locally and point commands at those paths.