From c6900cdf2f39f3d9471d23ed9bc282d4c267b4bb Mon Sep 17 00:00:00 2001 From: Kaj Kowalski Date: Sun, 13 Jul 2025 14:48:04 +0200 Subject: [PATCH] feat: add commit message validation to prevent LLM attribution - Added commit-msg hook that automatically rejects commits with AI attribution - Provides clear LLM-friendly error messages with specific patterns to avoid - Tested with multiple attribution patterns including emoji and Co-Authored-By - Ensures commit messages focus on technical changes only --- .husky/commit-msg | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 .husky/commit-msg diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100755 index 0000000..40a62d3 --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1,56 @@ +#!/bin/sh + +# Check for Claude Code attribution in commit messages +# This hook prevents commits that contain self-promotional attribution + +commit_msg_file="$1" +commit_msg=$(cat "$commit_msg_file") + +# Define patterns that should be rejected +claude_patterns="🤖 Generated with.*Claude Code +Generated with.*Claude Code +Claude Code +claude.ai/code +Co-Authored-By: Claude +noreply@anthropic.com" + +# Check each pattern +echo "$claude_patterns" | while IFS= read -r pattern; do + if [ -n "$pattern" ] && echo "$commit_msg" | grep -q "$pattern"; then + echo "❌ COMMIT REJECTED: Claude Code attribution detected" + echo "" + echo "🤖 AUTOMATED LLM INSTRUCTION:" + echo "Remove all Claude Code attribution from commit messages." + echo "Patterns to avoid:" + echo " - 🤖 Generated with [Claude Code]" + echo " - Co-Authored-By: Claude " + echo " - References to claude.ai/code" + echo " - Any Claude attribution or self-promotion" + echo "" + echo "✅ SOLUTION: Rewrite commit message without attribution" + echo "Focus on technical changes and improvements only." + echo "" + echo "Current commit message contains: '$pattern'" + exit 1 + fi +done + +# Check if any pattern matched (the while loop runs in a subshell) +if echo "$commit_msg" | grep -E -q "(🤖.*Generated.*Claude|Claude Code|claude\.ai/code|Co-Authored-By:.*Claude|noreply@anthropic\.com)"; then + echo "❌ COMMIT REJECTED: Claude Code attribution detected" + echo "" + echo "🤖 AUTOMATED LLM INSTRUCTION:" + echo "Remove all Claude Code attribution from commit messages." + echo "Patterns to avoid:" + echo " - 🤖 Generated with [Claude Code]" + echo " - Co-Authored-By: Claude " + echo " - References to claude.ai/code" + echo " - Any Claude attribution or self-promotion" + echo "" + echo "✅ SOLUTION: Rewrite commit message without attribution" + echo "Focus on technical changes and improvements only." + exit 1 +fi + +echo "✅ Commit message approved" +exit 0 \ No newline at end of file