#!/usr/bin/env bash # Blocks edits to secrets, lockfiles and merged migrations before Claude makes them. # Exit code 2 cancels the tool call and sends stderr back to Claude as the reason. set -euo pipefail file=$(jq -r '.tool_input.file_path // empty') if [ -z "$file" ]; then exit 0; fi case "$file" in *.env.example) ;; *.env | *.env.* | */.git/*) echo "Blocked: $file holds secrets or git internals. Ask the user to change it." >&2 exit 2 ;; *package-lock.json | *pnpm-lock.yaml | *yarn.lock | *bun.lock) echo "Blocked: $file is generated. Change package.json and run the install command." >&2 exit 2 ;; */migrations/*) if git -C "$CLAUDE_PROJECT_DIR" ls-files --error-unmatch "$file" >/dev/null 2>&1; then echo "Blocked: $file is a committed migration. Add a new migration instead." >&2 exit 2 fi ;; esac exit 0