Skip to content

Commit b6cc6d9

Browse files
committed
Add commit hook to prevent Claude attribution
Adds shell-based git hook that validates commit messages and rejects any containing Claude attribution patterns. Configured git to use .husky directory for hooks.
1 parent b3e439c commit b6cc6d9

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

.husky/commit-msg

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/sh
2+
3+
# Husky commit-msg hook to prevent Claude attribution in commit messages
4+
# This is a shell script version that works without Node.js
5+
6+
if [ -z "$1" ]; then
7+
echo "❌ Error: No commit message file provided"
8+
exit 1
9+
fi
10+
11+
COMMIT_MSG_FILE="$1"
12+
13+
if [ ! -f "$COMMIT_MSG_FILE" ]; then
14+
echo "❌ Error: Commit message file not found: $COMMIT_MSG_FILE"
15+
exit 1
16+
fi
17+
18+
# Read the commit message
19+
COMMIT_MSG=$(cat "$COMMIT_MSG_FILE")
20+
21+
# Define patterns to detect Claude attribution (using grep -E for extended regex)
22+
CLAUDE_PATTERNS="🤖 Generated with.*Claude|Generated with.*Claude Code|Co-Authored-By: Claude|claude\.com/claude-code|@anthropic\.com|Claude Code.*anthropic|Generated with \[Claude Code\]|\[Claude Code\]\(https://claude\.com/claude-code\)"
23+
24+
# Colors for console output
25+
RED='\033[31m'
26+
YELLOW='\033[33m'
27+
GREEN='\033[32m'
28+
RESET='\033[0m'
29+
30+
# Check for Claude attribution patterns
31+
if echo "$COMMIT_MSG" | grep -iE "$CLAUDE_PATTERNS" >/dev/null 2>&1; then
32+
FOUND_ATTRIBUTION=true
33+
MATCH=$(echo "$COMMIT_MSG" | grep -iE "$CLAUDE_PATTERNS" | head -1)
34+
else
35+
FOUND_ATTRIBUTION=false
36+
fi
37+
38+
if [ "$FOUND_ATTRIBUTION" = true ]; then
39+
echo "${RED}❌ COMMIT REJECTED${RESET}"
40+
echo "${YELLOW}⚠️ Commit message contains Claude attribution.${RESET}"
41+
echo ""
42+
echo "Found Claude attribution pattern:"
43+
echo " • Match: \"$MATCH\""
44+
echo ""
45+
echo "Please edit your commit message to remove Claude attribution."
46+
echo "Use: git commit --amend -m \"your new message\""
47+
echo ""
48+
exit 1
49+
fi
50+
51+
echo "${GREEN}✅ Commit message validated - no Claude attribution detected${RESET}"
52+
exit 0

0 commit comments

Comments
 (0)