Log Every Access to an MNPI-Tagged Path

An information-barrier review needs to answer "who or what accessed this deal room" with certainty. This logs every tool call touching a configured MNPI/deal-room path to a register separate from the general audit log, and sets a session-scoped flag the companion hook below reads.

Financial & Model-Risk Controls Event: PostToolUse Claude Code Open source · Free

1. Save this as the hook script

#!/usr/bin/env python3
"""PostToolUse hook — logs access to an MNPI-tagged path and sets a
session flag for the outbound-block companion hook. Wire with
matcher "*"."""
import json, re, sys, datetime
from pathlib import Path

data = json.load(sys.stdin)
path = (data.get("tool_input") or {}).get("file_path", "")
session_id = data.get("session_id", "unknown")

if not re.search(r"(?i)(/mnpi/|/deal-room/)", path):
    sys.exit(0)

log_path = Path(data.get("cwd", ".")) / ".claude" / "mnpi_access_log.jsonl"
log_path.parent.mkdir(parents=True, exist_ok=True)
entry = {"ts": datetime.datetime.utcnow().isoformat() + "Z",
         "session_id": session_id, "path": path, "tool_name": data.get("tool_name")}
with open(log_path, "a") as f:
    f.write(json.dumps(entry) + "\n")

flag_path = Path(data.get("cwd", ".")) / ".claude" / f"mnpi_touched_{session_id}.flag"
flag_path.touch()
sys.exit(0)

Save to a path inside your project, e.g. .claude/hooks/log-mnpi-tagged-path-access.sh, then chmod +x it.

2. Wire it into .claude/settings.json

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "*",
        "hooks": [
          {"type": "command", "command": "python3 .claude/hooks/log-mnpi-tagged-path-access.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

← All hooks
FEEDBACK