Block Prompts That Reference a Disallowed External Domain
For a locked-down environment where outbound fetches should only ever go to a known small set of domains (an internal wiki, a specific data vendor), this catches the request at the prompt level — before the model even has a chance to decide whether to call a fetch tool.
1. Save this as the hook script
#!/usr/bin/env python3
"""UserPromptSubmit hook — blocks a prompt referencing a URL outside an
allowlist of domains."""
import json, re, sys
data = json.load(sys.stdin)
prompt = data.get("user_prompt", "")
ALLOWED_DOMAINS = ("sec.gov", "federalreserve.gov", "claudefinancelab.com", "finskilz.com")
urls = re.findall(r"https?://([^/\s]+)", prompt)
for host in urls:
if not any(host.endswith(d) for d in ALLOWED_DOMAINS):
print(f"BLOCKED: prompt references {host}, which is outside the "
f"allowed domain list for this project.", file=sys.stderr)
sys.exit(2)
sys.exit(0)
Save to a path inside your project, e.g. .claude/hooks/block-prompts-disallowed-domain.sh, then chmod +x it.
2. Wire it into .claude/settings.json
{
"hooks": {
"UserPromptSubmit": [
{
"hooks": [
{"type": "command", "command": "python3 .claude/hooks/block-prompts-disallowed-domain.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