Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b86yyhhudsSLnwNUFY
23 lines
797 B
Bash
Executable File
23 lines
797 B
Bash
Executable File
#!/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<n> 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<next>__*.sql file instead." >&2
|
|
exit 2
|
|
fi ;;
|
|
esac
|
|
exit 0
|