#!/bin/bash # PreToolUse(Write|Edit): block writes to raw/ directory # Karpathy LLM Wiki rule #1: raw/ is immutable json=$(cat) # Extract file_path from JSON (works for Write, Edit, MultiEdit tools) path=$(printf '%s' "$json" | grep -o '"file_path"[[:space:]]*:[[:space:]]*"[^"]*"' | head -1 | sed 's/.*"file_path"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/') if [ -z "$path" ]; then exit 0 fi # Normalize Windows backslashes to forward slashes path_norm=$(printf '%s' "$path" | tr '\\' '/') case "$path_norm" in */raw/*|raw/*) cat <<'EOF' { "hookSpecificOutput": { "hookEventName": "PreToolUse", "permissionDecision": "deny", "permissionDecisionReason": "raw/ is immutable (Karpathy LLM Wiki rule #1). Edit or place new sources via manual copy only." } } EOF exit 0 ;; esac exit 0