Block Writing Raw Account Numbers to a Shared Scratch Path
A scratch file is often the quiet leak path: a debugging dump that lands somewhere shared (a repo, a synced folder) rather than a private, session-scoped scratchpad. This blocks the write if the content looks like raw account numbers and the destination isn't under a configured private-scratch prefix.
1. Save this as the hook script
#!/usr/bin/env python3
"""PreToolUse hook — blocks writing account-number-shaped content outside
a private scratch path. Wire to Write|Edit."""
import json, re, sys
data = json.load(sys.stdin)
tool_input = data.get("tool_input") or {}
path = tool_input.get("file_path", "")
content = tool_input.get("content") or tool_input.get("new_string") or ""
PRIVATE_SCRATCH_PREFIX = "/tmp/claude-"
if re.search(r"\b\d{13,19}\b", content) and not path.startswith(PRIVATE_SCRATCH_PREFIX):
print(f"BLOCKED: content matches an account-number shape and {path} is "
f"not under the private scratchpad prefix.", file=sys.stderr)
sys.exit(2)
sys.exit(0)
Save to a path inside your project, e.g. .claude/hooks/block-account-numbers-to-shared-scratch.sh, then chmod +x it.
2. Wire it into .claude/settings.json
{
"hooks": {
"PreToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{"type": "command", "command": "python3 .claude/hooks/block-account-numbers-to-shared-scratch.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