Exchange
Four hook scripts
1 file4 KB
A look inside
The first lines of hooks.zip. The whole file is in your library once you get it.
# ABOUTME: PreToolUse hook for Bash: blocks any command that runs `rm`, by exiting with code 2.
# ABOUTME: A seatbelt, not a lock: use permission rules to enforce a hard deny.
import json
import re
import sys
event = json.load(sys.stdin)
command = event.get("tool_input", {}).get("command", "")
# `rm` at the start, or after ; && || | or sudo
if re.search(r"(^|[;&|]\s*|\bsudo\s+)rm(\s|$)", command.strip()):
print("Blocked: this project does not let the agent run rm. Ask the user to delete files.",
file=sys.stderr)
sys.exit(2) # exit 2 = block the tool call; stderr is shown to Claude
sys.exit(0)What is inside
- hooks.zip4 KB
How to use it
Four hook scripts for Claude Code (a secret guard, a block on rm, lint after an edit, and tests when it stops) and the settings.json that wires them in.
Copy the .py files into .claude/hooks/, merge settings.json into .claude/settings.json, and set LINT_CMD and TEST_CMD to your own commands (the defaults are npx eslint and npm test).
Run before it was listed
Tested 2026-11-27: python3 -I -m unittest: 12 tests passed, piping sample hook input to each script. A live run inside Claude Code is still owed.