Block Outbound Calls From an MNPI-Touched Session
The ethical-wall counterpart to the logging hook above: once the session-scoped MNPI flag is set, this blocks every outbound-looking action — a Bash mail/curl command, or any external `mcp__` call — for the remainder of that session, enforcing the same information barrier a human trading desk is expected to observe.
1. Save this as the hook script
#!/usr/bin/env python3
"""PreToolUse hook — blocks outbound-looking calls once a session has
touched an MNPI path. Wire to matcher "Bash|mcp__.*"."""
import json, re, sys
from pathlib import Path
data = json.load(sys.stdin)
tool_name = data.get("tool_name", "")
session_id = data.get("session_id", "unknown")
flag_path = Path(data.get("cwd", ".")) / ".claude" / f"mnpi_touched_{session_id}.flag"
if not flag_path.exists():
sys.exit(0)
command = (data.get("tool_input") or {}).get("command", "")
is_outbound = tool_name.startswith("mcp__") or re.search(r"(?i)(mail|curl|wget|scp)\b", command)
if is_outbound:
print(f"BLOCKED: this session touched an MNPI-tagged path earlier — "
f"outbound calls ({tool_name}) are blocked for the rest of the session.", file=sys.stderr)
sys.exit(2)
sys.exit(0)
Save to a path inside your project, e.g. .claude/hooks/block-outbound-from-mnpi-touched-session.sh, then chmod +x it.
2. Wire it into .claude/settings.json
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash|mcp__.*",
"hooks": [
{"type": "command", "command": "python3 .claude/hooks/block-outbound-from-mnpi-touched-session.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