Claude Code hooks builder
Tick what you want Claude Code to block, tell you or do. Copy one command to install it.
Runs in your browser. Nothing is sent anywhere.
1 · Pick your hooks
Bash commands
Files
Tell me
Automate
2 · Where
Goes in ~/.claude/settings.json, on your machine only.
Your hooks
mkdir -p ~/.claude/hooks
cat > ~/.claude/hooks/guard-bash.sh <<'CORAL_GUARD'
#!/bin/bash
# guard-bash.sh · a Claude Code PreToolUse hook for the Bash tool, from usecoral.app/tools/claude-code-hooks.
# It reads the command Claude wants to run and denies it, asks you first, or lets Claude Code's normal
# permission check decide. It matches text, so it's a seatbelt, not a wall: a script file or an alias can get
# past it. Pair it with deny rules and the sandbox. Needs jq.
set -u
# Fail closed: a safety hook that can't read the command must not let it through.
if ! command -v jq >/dev/null 2>&1; then
echo "guard-bash.sh: jq is not installed, so this command was blocked. Install jq (brew install jq / apt install jq)." >&2
exit 2
fi
input=$(cat)
if ! cmd=$(printf '%s' "$input" | jq -r '.tool_input.command // empty' 2>/dev/null); then
echo "guard-bash.sh: couldn't read the hook input, so this command was blocked." >&2
exit 2
fi
cwd=$(printf '%s' "$input" | jq -r '.cwd // empty' 2>/dev/null)
[ -z "$cmd" ] && exit 0
# Print Claude Code's PreToolUse answer and stop.
decide() {
jq -n --arg d "$1" --arg r "$2" \
'{hookSpecificOutput: {hookEventName: "PreToolUse", permissionDecision: $d, permissionDecisionReason: $r}}'
exit 0
}
# a download piped into a shell (checked on the whole command, since the pipe splits it)
if printf '%s\n' "$cmd" | grep -Eq '(curl|wget)[^|]*\|[[:space:]]*(sudo[[:space:]]+)?(ba|z|da)?sh([[:space:]]|$)'; then
decide deny "Blocked by your hook: piping a download into a shell. Download it, show the user, then run it."
fi
# One line per shell command: split on ; && || | and newlines, so `cd x && rm -rf y` checks both.
segments=$(printf '%s\n' "$cmd" | awk '{ gsub(/&&|\|\||;|\|/, "\n"); print }')
while IFS= read -r seg; do
seg=$(printf '%s' "$seg" | sed -E 's/^[[:space:]]+//; s/[[:space:]]+$//; s/^(sudo|command|exec|env)[[:space:]]+//')
[ -z "$seg" ] && continue
# rm with both -r and -f, unless every target is a folder a build or install recreates
if printf '%s' "$seg" | grep -Eq '^rm[[:space:]]'; then
flags=$(printf '%s' "$seg" | grep -Eo '(^|[[:space:]])-[A-Za-z-]+' | tr -d ' \n')
if printf '%s' "$flags" | grep -Eq '(r|R|--recursive)' && printf '%s' "$flags" | grep -Eq '(f|--force)'; then
targets=$(printf '%s' "$seg" | tr ' ' '\n' | sed '1d' | grep -Ev '^-')
[ -z "$targets" ] && decide deny "Blocked by your hook: rm -rf with no target."
while IFS= read -r t; do
printf '%s' "$t" | grep -Eq '^(\./)?(node_modules|dist|build|out|\.next|\.turbo|\.cache|coverage|target|tmp|\.pytest_cache|__pycache__)/?$' ||
decide deny "Blocked by your hook: rm -rf $t. Delete files one by one, or ask the user to run it."
done <<< "$targets"
fi
fi
# git push: never force, never straight to main or master
if printf '%s' "$seg" | grep -Eq '^git([[:space:]]+-C[[:space:]]+[^[:space:]]+)?[[:space:]]+push([[:space:]]|$)'; then
printf '%s' "$seg" | grep -Eq '[[:space:]](-f|--force|--force-with-lease)([[:space:]=]|$)|[[:space:]]\+[^[:space:]]+' &&
decide deny "Blocked by your hook: force push. Push a new branch and open a pull request."
printf '%s' "$seg" | grep -Eq '[[:space:]](main|master)([[:space:]]|$)|:(main|master)([[:space:]]|$)' &&
decide deny "Blocked by your hook: push to main or master. Push a branch and open a pull request."
# fsmonitor off, so a hostile repo's git config can't make this check run a program
branch=$(git -c core.fsmonitor=false -C "${cwd:-.}" symbolic-ref --short HEAD 2>/dev/null)
if [ "$branch" = "main" ] || [ "$branch" = "master" ]; then
printf '%s' "$seg" | grep -Eq '^git([[:space:]]+-C[[:space:]]+[^[:space:]]+)?[[:space:]]+push([[:space:]]+(-u|--set-upstream))?([[:space:]]+origin)?[[:space:]]*$' &&
decide deny "Blocked by your hook: this push goes to $branch. Create a branch first."
fi
fi
# production env files
printf '%s' "$seg" | grep -Eq '\.env\.(prod|production)([^[:alnum:]_.-]|$)' &&
decide deny "Blocked by your hook: production env file. Agents work with development keys only."
# changes that throw away uncommitted work
printf '%s' "$seg" | grep -Eq '^git([[:space:]]+-C[[:space:]]+[^[:space:]]+)?[[:space:]]+(reset[[:space:]]+--hard|clean[[:space:]]+-[a-zA-Z]*f|checkout[[:space:]]+--[[:space:]]+\.|restore[[:space:]]+\.)' &&
decide ask "Your hook: this throws away uncommitted work."
done <<< "$segments"
exit 0
CORAL_GUARD
chmod +x ~/.claude/hooks/guard-bash.sh
cat > ~/.claude/hooks/protect-files.sh <<'CORAL_FILES'
#!/bin/bash
# protect-files.sh · a Claude Code PreToolUse hook for the Edit and Write tools, from
# usecoral.app/tools/claude-code-hooks. It blocks edits to the files below. Claude can still reach them through
# Bash, so add a deny rule for that. Needs jq.
set -u
if ! command -v jq >/dev/null 2>&1; then
echo "protect-files.sh: jq is not installed, so this edit was blocked. Install jq (brew install jq / apt install jq)." >&2
exit 2
fi
f=$(jq -r '.tool_input.file_path // .tool_input.notebook_path // empty' 2>/dev/null) || {
echo "protect-files.sh: couldn't read the hook input, so this edit was blocked." >&2
exit 2
}
[ -z "$f" ] && exit 0
case "$(basename -- "$f")" in
.env|.env.*)
echo "Blocked by your hook: $f is a secrets file. Ask the user to change it." >&2
exit 2
;;
esac
exit 0
CORAL_FILES
chmod +x ~/.claude/hooks/protect-files.sh
h=$(cat <<'CORAL_HOOKS'
{"PreToolUse":[{"matcher":"Bash","hooks":[{"type":"command","command":"\"$HOME\"/.claude/hooks/guard-bash.sh # usecoral.app/tools/claude-code-hooks","timeout":10}]},{"matcher":"Edit|Write|MultiEdit|NotebookEdit","hooks":[{"type":"command","command":"\"$HOME\"/.claude/hooks/protect-files.sh # usecoral.app/tools/claude-code-hooks","timeout":10}]}],"Notification":[{"matcher":"permission_prompt|idle_prompt","hooks":[{"type":"command","command":"osascript -e 'display notification \"Claude Code needs you\" with title \"Claude Code\"' # usecoral.app/tools/claude-code-hooks"}]}]}
CORAL_HOOKS
)
f=~/.claude/settings.json; [ -s "$f" ] || echo '{}' > "$f"; cp "$f" "$f.bak" && jq --argjson h "$h" --arg m "# usecoral.app/tools/claude-code-hooks" '.hooks = (((.hooks // {}) | map_values(map(.hooks |= map(select(((.command // "") | endswith($m)) | not))) | map(select((.hooks | length) > 0))) | with_entries(select((.value | length) > 0))) as $old | reduce ($h | to_entries[]) as $e ($old; .[$e.key] = ((.[$e.key] // []) + $e.value)))' "$f.bak" > "$f" || cp "$f.bak" "$f"
Paste it in a terminal. It backs up ~/.claude/settings.json, keeps your other hooks, and replaces hooks from this page if you run it again. Needs jq.
Then restart Claude Code and run /hooks to see them listed.
Hooks run as you, with no prompt. Read any hook before you install it, these included. More in the hooks guide →
Questions
What are Claude Code hooks?
Shell commands Claude Code runs at set points: before and after a tool, when it needs you, when it stops. Unlike a line in CLAUDE.md, a hook runs every time.
Where do Claude Code hooks go?
In a hooks object in a settings file: ~/.claude/settings.json for all your projects, .claude/settings.json for one repo and your team, or .claude/settings.local.json for you in one repo. Hooks from every file run together.
How does a hook block a command?
A PreToolUse hook either exits with code 2, and its message goes to Claude, or prints JSON with permissionDecision set to deny or ask. The guard here uses the JSON, so it can also ask you first.
Can a hook stop every dangerous command?
No. It matches the command’s text, so a script file or an alias can get past it. Pair it with deny rules, the sandbox, and production keys the agent never sees.
How do I check my hooks are working?
Restart Claude Code and run /hooks: it lists every hook and the file it came from. Start with claude --debug to see what ran and why.
Checked against Anthropic’s hooks reference, November 2026. Every hook here is installed and run against real commands in our tests. The Bash guard comes from coral-safety-kit.
Coral isn’t affiliated with Anthropic.