#!/bin/bash # PreToolUse hook for Edit|Write|MultiEdit. Exit code 2 blocks the call and sends stderr to Claude. INPUT=$(cat) TOOL=$(echo "$INPUT" | jq -r '.tool_name // empty') FILE=$(echo "$INPUT" | jq -r '.tool_input.file_path // empty') # Production config is never edited by the agent. case "$FILE" in *application-prod.*|*/.env|*/.env.*) echo "Blocked: $FILE is production configuration. Ask the user to change it." >&2 exit 2 ;; esac # An applied Flyway migration is immutable. Creating a new V file is fine, changing an existing one is not. case "$FILE" in */db/migration/V*.sql) if [ "$TOOL" != "Write" ] || [ -e "$FILE" ]; then echo "Blocked: $FILE is an existing Flyway migration. Add a new V__*.sql file instead." >&2 exit 2 fi ;; esac exit 0