Log Every Prompt for a Model-Risk Session Register

The audit-log hooks elsewhere in this catalog record what the agent *did*; this records what the human *asked for*, independent of the transcript file. An SR 11-7-style review of a regulated session often needs both halves of that record kept separately.

Prompt & Input Safety Event: UserPromptSubmit Claude Code Open source · Free

1. Save this as the hook script

#!/usr/bin/env python3
"""UserPromptSubmit hook — logs every prompt to an independent register."""
import json, sys, datetime
from pathlib import Path

data = json.load(sys.stdin)
log_path = Path(data.get("cwd", ".")) / ".claude" / "prompt_register.jsonl"
log_path.parent.mkdir(parents=True, exist_ok=True)

entry = {
    "ts": datetime.datetime.utcnow().isoformat() + "Z",
    "session_id": data.get("session_id"),
    "prompt_id": data.get("prompt_id"),
    "user_prompt": data.get("user_prompt", "")[:2000],
}

with open(log_path, "a") as f:
    f.write(json.dumps(entry) + "\n")

sys.exit(0)

Save to a path inside your project, e.g. .claude/hooks/log-every-prompt-model-risk-register.sh, then chmod +x it.

2. Wire it into .claude/settings.json

{
  "hooks": {
    "UserPromptSubmit": [
      {
        "hooks": [
          {"type": "command", "command": "python3 .claude/hooks/log-every-prompt-model-risk-register.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