Free Claude Code Hooks Generator
A Claude Code hooks generator creates ready-to-paste settings.json fragments for automating Claude Code events. Pick an event, add tool matchers when needed, write the shell command, and copy a valid hook config for project or user scope.
Start from a hook template
Generates local JSON only - no API call.Hook
.claude/settings.json
PreToolUse hook · tool matched
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "set -euo pipefail; mkdir -p .claude/logs && jq -r 'now | todate + \" \" + (.tool_input.command // \"\")' >> .claude/logs/bash-commands.log",
"timeout": 15
}
]
}
]
}
}mkdir -p .claude
node <<'NODE'
const fs = require('fs');
const path = ".claude/settings.json".replace(/^~\//, process.env.HOME + '/');
const incoming = {
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "set -euo pipefail; mkdir -p .claude/logs && jq -r 'now | todate + \" \" + (.tool_input.command // \"\")' >> .claude/logs/bash-commands.log",
"timeout": 15
}
]
}
]
}
};
const current = fs.existsSync(path) ? JSON.parse(fs.readFileSync(path, 'utf8')) : {};
current.hooks = current.hooks || {};
for (const [event, entries] of Object.entries(incoming.hooks)) {
current.hooks[event] = [...(current.hooks[event] || []), ...entries];
}
fs.writeFileSync(path, JSON.stringify(current, null, 2) + '\n');
NODEHow to create a Claude Code hook
- Pick a hook event. Choose when Claude Code should run the command, such as PreToolUse, PostToolUse, Stop, UserPromptSubmit, or SessionStart.
- Choose scope and matchers. Use project scope for repository hooks or user scope for personal hooks. Add matchers for PreToolUse and PostToolUse events.
- Write the command. Enter the shell command that should receive the hook payload on stdin. Keep the command fast, deterministic, and easy to inspect.
- Copy the JSON or merge snippet. Copy the generated settings.json fragment, download it, or use the generated Node snippet to merge it into the selected settings file.
- Verify with /hooks. Open Claude Code, run /hooks, confirm the hook is registered, and test it on the matching event.
Anatomy of a hook config
Hooks are grouped by event under the hooks key. Tool events can include a matcher so the command only runs for specific tools.
PreToolUse- runs before matched tools such as Bash, Edit, or Write.PostToolUse- runs after a matched tool completes successfully.command- shell command that receives the hook payload as JSON on stdin.timeout- per-command execution limit in seconds.
Frequently Asked Questions
What are Claude Code hooks?
+
Claude Code hooks are shell commands that run at defined lifecycle events, such as before a tool runs, after a tool succeeds, when a prompt is submitted, or before Claude finishes a response.
Where do Claude Code hook settings go?
+
Project hooks go in .claude/settings.json inside a repository. User hooks go in ~/.claude/settings.json and apply across projects on that machine.
Which hooks use matchers?
+
PreToolUse and PostToolUse hooks use matchers to target tools like Bash, Edit, Write, Read, or Task. Events such as Stop, Notification, SessionStart, and UserPromptSubmit do not need a matcher.
What input does a hook command receive?
+
Claude Code sends hook commands JSON on stdin. The payload includes session information, the hook event name, and event-specific fields such as tool input for tool hooks.
Can a Claude Code hook block an action?
+
Yes. Hooks can use exit codes or structured JSON output to block specific actions, add context, or ask Claude to continue before stopping. Blocking behavior depends on the hook event.
Hooks automate moments. Tornic automates workflows.
Claude Code hooks are useful checkpoints. Tornic turns your Claude, Codex, or Cursor CLI subscription into repeatable workflow runs with clear steps, stable handoffs, and no surprise API bills.
Try Tornic