CLAUDER — Prompts
Verbatim Excerpt 1: prevent-unsafe-commands.py (Hook)
# Define validation rules as a list of (regex pattern, message) tuples
VALIDATION_RULES = [
# File deletion commands
(
r"(^|\s&\s)unlink\b",
"unlink can delete files. Use 'git rm' for tracked files or request a human to run this command, clearly highlighting risks.",
),
(
r"(^|\s&\s)shred\b",
"shred permanently destroys files. This operation is irreversible. Request a human to run this command, clearly highlighting risks.",
),
# Git destructive operations
(
r"(^|\s&\s)git\s+reset\b",
"git reset can cause data loss. Request a human to run this command, clearly highlighting risks.",
),
(
r"(^|\s&\s)git\s+push\s+[-\w]*\s*--force\b",
"git push --force can overwrite remote history. Request a human to run this command, clearly highlighting risks.",
),
Technique: regex-based PreToolUse blocking — each rule is a (pattern, message) pair. Messages explain why the block occurred and suggest safe alternatives, feeding the agent context to self-correct.
Verbatim Excerpt 2: trace-event.py (SQLite audit hook)
"""
Log events to a local SQLite database file, for auditing and debugging.
This script is called on all Claude operations.
"""
def init_database_if_needed(db_path):
"""Initialize the SQLite database with the trace table only if it doesn't exist."""
if not db_path.exists():
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE trace_logs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp TEXT NOT NULL,
operation_type TEXT,
data TEXT NOT NULL,
created_at TEXT DEFAULT CURRENT_TIMESTAMP
)
''')
Technique: audit-first logging — every PreToolUse event writes a trace log entry before any check can block it, ensuring even blocked operations have a complete audit record.
Verbatim Excerpt 3: Settings.json (Hook Wiring)
{
"hooks": {
"PreToolUse": [
{"matcher": "", "hooks": [{"type": "command", "command": "python3 $CLAUDE_PROJECT_DIR/.claude/hooks/trace-event.py"}]},
{"matcher": "Edit|MultiEdit|Write|mcp|Bash|Read|Grep", "hooks": [{"type": "command", "command": "python3 $CLAUDE_PROJECT_DIR/.claude/hooks/check-ignore-patterns.py"}]},
{"matcher": "Edit|MultiEdit|Write|mcp|Bash", "hooks": [{"type": "command", "command": "python3 $CLAUDE_PROJECT_DIR/.claude/hooks/check-immutable-patterns.py"}]},
{"matcher": "Bash", "hooks": [{"type": "command", "command": "python3 $CLAUDE_PROJECT_DIR/.claude/hooks/prevent-unsafe-commands.py"}]},
{"matcher": "mcp__supabase", "hooks": [{"type": "command", "command": "python3 $CLAUDE_PROJECT_DIR/.claude/hooks/require-human-approval.py"}]}
]
}
}
Technique: layered hook ordering — hooks fire in order from broadest (all tools) to most specific (mcp__supabase). The trace hook fires first on every call, ensuring logging precedes blocking.