Require Confirmation for Production Commands
Blocks any Bash command matching your production SSH host, a service restart, a destructive rsync, or an unguarded SQL DROP/DELETE. This is the same pattern as a standing deploy-approval policy written into project instructions — except enforced by the hook layer, not just by Claude choosing to follow the instruction.
1. Save this as the hook script
#!/usr/bin/env python3
"""PreToolUse hook — blocks shell commands that touch a named production host or
run a destructive-sounding deploy action, forcing a human-in-the-loop check.
Wire this to the Bash matcher. Edit PROD_HOST and PROD_MARKERS for your own infrastructure."""
import json, re, sys
data = json.load(sys.stdin)
command = (data.get("tool_input") or {}).get("command", "")
PROD_HOST = r"(root@|ssh\s+.*)(YOUR_PROD_IP_OR_HOSTNAME)" # e.g. [email protected]
PROD_MARKERS = [
r"systemctl\s+(restart|stop)\s+\S+",
r"rsync\s+.*(--delete)",
r"DROP\s+TABLE",
r"DELETE\s+FROM\s+\w+\s*;?\s*$", # no WHERE clause
]
if re.search(PROD_HOST, command) or any(re.search(p, command, re.IGNORECASE) for p in PROD_MARKERS):
print("BLOCKED: this command matches a production-impact pattern.", file=sys.stderr)
print("Confirm with a human before re-running, or add an explicit allow-list entry to this hook.", file=sys.stderr)
sys.exit(2)
sys.exit(0)
Save to a path inside your project, e.g. .claude/hooks/require-confirmation-for-prod-commands.sh, then chmod +x it.
2. Wire it into .claude/settings.json
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{"type": "command", "command": "python3 .claude/hooks/require-confirmation-for-prod-commands.py"}
]
}
]
}
}
Before you use this
A hook runs with your local shell's permissions — review the script above before adding it, the same way you'd review any script you didn't write yourself. See our guide on hook security risks for the specific CVEs this category of feature has already produced.
Related hooks