Require a Validation Reference Before Overwriting a Model Output File

A model's output file silently overwritten with a new run breaks the link back to whichever validation review signed off on the version it's replacing. This requires a validation-ID reference (e.g. VAL-2026-014) to be present before a configured model-output path can be overwritten.

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

1. Save this as the hook script

#!/usr/bin/env python3
"""PreToolUse hook — blocks overwriting a model-output file unless a
validation-ID reference is present. 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 = json.dumps(tool_input)

if "model_output" not in path.lower():
    sys.exit(0)

if not re.search(r"\bVAL-\d{4}-\d{2,4}\b", content):
    print(f"BLOCKED: overwrite of {path} has no validation-ID reference "
          f"(expected VAL-YYYY-NNN).", file=sys.stderr)
    sys.exit(2)

sys.exit(0)

Save to a path inside your project, e.g. .claude/hooks/require-validation-ref-model-output-overwrite.sh, then chmod +x it.

2. Wire it into .claude/settings.json

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [
          {"type": "command", "command": "python3 .claude/hooks/require-validation-ref-model-output-overwrite.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