In the age of AI-assisted development, maintaining professional commit history has become a new challenge. While AI tools like Claude, GitHub Copilot, and ChatGPT are invaluable for development, including AI attribution in commit messages can make your repository look unprofessional and clutter your git history.
This comprehensive guide shows you how to implement Git hooks that automatically prevent AI references from entering your commit messages, ensuring clean, professional git history that focuses on what changed, not how it was created.
The Problem with AI Attribution in Commits
Common AI Attribution Patterns
π€ Generated with Claude
Co-Authored-By: Claude <noreply@anthropic.com>
AI-assisted refactoring of user service
feat: add login form (with ChatGPT help)
Generated with [Claude Code](https://claude.ai/code)
Why This Matters
- Professional Appearance: Client-facing repositories should maintain professional commit history
- Legal Clarity: Removes ambiguity about code authorship
- Focus on Changes: Commits should describe what changed, not the development process
- Historical Context: Future developers care about the change, not the tool used
- Compliance: Some organizations require clean commit attribution
Implementing AI Reference Prevention
The commit-msg Hook Solution
The most effective approach uses a commit-msg
Git hook that scans commit messages for AI-related patterns and blocks commits containing them.
Create your .githooks
directory structure:
# Create the hooks directory
mkdir .githooks
# Create the commit message hook
cat > .githooks/commit-msg << 'EOF'
#!/bin/bash
# Pre-commit hook to prevent Claude/AI references in commit messages
# This hook blocks commits that mention Claude, AI assistance, or similar references
commit_message_file=$1
commit_message=$(cat "$commit_message_file")
# List of patterns to block (case-insensitive)
blocked_patterns=(
"claude"
"anthropic"
"Generated with"
"Co-Authored-By: Claude"
"π€"
"AI-generated"
"AI assisted"
"noreply@anthropic"
"claude.ai"
"Claude Code"
"ChatGPT"
"GPT-4"
"GitHub Copilot"
"AI helped"
"with AI"
"using AI"
)
# Check for blocked patterns
for pattern in "${blocked_patterns[@]}"; do
if echo "$commit_message" | grep -qi "$pattern"; then
echo "β Commit blocked: Found reference to '$pattern' in commit message"
echo ""
echo "Your commit message contains AI/Claude references that should not be included."
echo "Please rewrite your commit message without any AI attribution."
echo ""
echo "Blocked commit message:"
echo "------------------------"
echo "$commit_message"
echo "------------------------"
exit 1
fi
done
# If we get here, the commit message is clean
exit 0
EOF
# Make it executable
chmod +x .githooks/commit-msg
Installation Script for Team Setup
Create an installation script that team members can run:
cat > .githooks/install.sh << 'EOF'
#!/bin/bash
# Install script for git hooks
# This script installs the commit-msg hook to prevent AI/Claude references
echo "Installing git hooks..."
# Get the git directory
GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)
if [ -z "$GIT_DIR" ]; then
echo "β Error: Not in a git repository"
exit 1
fi
# Copy the commit-msg hook
cp .githooks/commit-msg "$GIT_DIR/hooks/commit-msg"
chmod +x "$GIT_DIR/hooks/commit-msg"
echo "β
Git hooks installed successfully!"
echo ""
echo "The following hook has been installed:"
echo " - commit-msg: Prevents commits with AI/Claude references"
echo ""
echo "To test the hook, try committing with a message containing 'Claude' or 'π€'"
EOF
chmod +x .githooks/install.sh
Documentation for Your Team
Create a README for the hooks:
cat > .githooks/README.md << 'EOF'
# Git Hooks
This directory contains git hooks to maintain commit message quality and prevent AI attribution in commit messages.
## Installation
Run the install script to set up the hooks:
```bash
bash .githooks/install.sh
Or manually copy the hooks:
cp .githooks/commit-msg .git/hooks/commit-msg
chmod +x .git/hooks/commit-msg
Hooks Included
commit-msg
Prevents commits that contain references to AI assistance, including:
- Claude, Anthropic, ChatGPT, GPT-4
- AI-generated, AI assisted
- π€ emoji
- Co-authored-by AI attributions
- Generated with [tool] messages
- GitHub Copilot references
Testing
To test that the hook is working, try to commit with a blocked pattern:
git commit -m "This was generated with Claude"
# Should fail with an error message
Bypassing (Emergency Only)
If you absolutely need to bypass the hook in an emergency:
git commit --no-verify -m "Your message"
Note: This should only be used in exceptional circumstances.
Writing Professional Commit Messages
Instead of:
π€ Generated with Claude Code: Add user authentication
Write:
feat: add user authentication with session management
Focus on:
- What changed
- Why it changed (if not obvious)
- Impact of the change
Avoid mentioning:
- Tools used to create the code
- AI assistance
- Development process details
EOF
## Advanced Pattern Detection
### Comprehensive Blocked Patterns List
Extend your hook to catch more sophisticated AI references:
```bash
# Extended list of blocked patterns
blocked_patterns=(
# Direct AI tool mentions
"claude"
"anthropic"
"chatgpt"
"gpt-4"
"gpt-3"
"github copilot"
"copilot"
"bard"
"gemini"
# AI attribution patterns
"Generated with"
"Created with"
"Built with AI"
"AI-generated"
"AI assisted"
"AI helped"
"with AI"
"using AI"
"AI-powered"
# Specific attribution formats
"Co-Authored-By: Claude"
"Co-Authored-By: ChatGPT"
"noreply@anthropic"
"claude.ai"
"openai.com"
"Claude Code"
# Emojis and symbols
"π€"
"π§ "
"β‘.*AI"
"π.*generated"
# URLs and links
"claude.ai/code"
"chat.openai.com"
"github.com/features/copilot"
# Common phrases
"machine learning"
"neural network"
"language model"
"large language model"
"LLM"
)
Case-Insensitive and Regex Support
Make the hook more robust with regex pattern matching:
#!/bin/bash
commit_message_file=$1
commit_message=$(cat "$commit_message_file")
# Array of regex patterns to block
blocked_regex_patterns=(
"[Cc]laude"
"[Aa]nthropic"
"[Gg]enerated with.*"
"[Cc]o-[Aa]uthored-[Bb]y:.*[Cc]laude"
"π€"
"[Aa][Ii][\s-]*(generated|assisted|helped|powered)"
"[Cc]hat[Gg][Pp][Tt]"
"[Gg][Pp][Tt][-]?[0-9]"
"[Cc]opilot"
)
# Check each pattern
for pattern in "${blocked_regex_patterns[@]}"; do
if echo "$commit_message" | grep -E "$pattern" > /dev/null; then
echo "β Commit blocked: Found AI reference matching pattern '$pattern'"
echo ""
echo "Please rewrite your commit message focusing on WHAT changed, not HOW it was created."
echo ""
echo "Blocked commit message:"
echo "------------------------"
echo "$commit_message"
echo "------------------------"
echo ""
echo "Suggestion: Focus on the business impact and technical changes instead."
exit 1
fi
done
exit 0
Team Implementation Strategies
Onboarding New Developers
Add hook installation to your project setup documentation:
# Development Setup
After cloning the repository:
1. Install dependencies:
```bash
npm install
-
Set up Git hooks:
bash .githooks/install.sh
-
Test the setup:
git commit --allow-empty -m "Test commit with Claude"
# Should fail and show blocked message
This ensures all commits maintain professional standards.
### CI/CD Integration
Add a check in your CI pipeline to catch any commits that slip through:
```yaml
# .github/workflows/commit-quality.yml
name: Commit Quality Check
on: [push, pull_request]
jobs:
check-commits:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Check commit messages for AI references
run: |
# Check all commits in PR
blocked_patterns="claude|anthropic|chatgpt|π€|ai-generated|generated with"
if git log --oneline origin/main..HEAD | grep -iE "$blocked_patterns"; then
echo "β Found AI references in commit messages"
echo "Please rewrite commit messages to focus on what changed"
exit 1
fi
echo "β
All commit messages are professional"
Global Git Hook Setup
For developers who want this across all repositories:
# Create global hooks directory
mkdir -p ~/.git-templates/hooks
# Copy your commit-msg hook
cp .githooks/commit-msg ~/.git-templates/hooks/commit-msg
chmod +x ~/.git-templates/hooks/commit-msg
# Configure Git to use template
git config --global init.templatedir ~/.git-templates
# For existing repos, copy manually or use:
git config --global core.hooksPath ~/.git-templates/hooks
Best Practices for Professional Commit Messages
What TO Include
# Good examples:
git commit -m "feat: add user authentication with JWT tokens"
git commit -m "fix: resolve memory leak in image processing"
git commit -m "refactor: extract payment logic into service layer"
git commit -m "docs: update API documentation for v2 endpoints"
What NOT to Include
# Bad examples that would be blocked:
git commit -m "π€ Generated with Claude: Add user auth"
git commit -m "feat: add login (ChatGPT helped with validation)"
git commit -m "AI-assisted refactoring of payment service"
git commit -m "Claude suggested this approach for user management"
Writing Guidelines
- Use Conventional Commits:
type(scope): description
- Focus on business impact: What problem does this solve?
- Be specific: Avoid vague descriptions like "fix stuff"
- Keep it concise: Aim for 50 characters or less
- Use imperative mood: "add feature" not "added feature"
Troubleshooting and Common Issues
Hook Not Running
# Check if hook exists and is executable
ls -la .git/hooks/commit-msg
# If missing, reinstall
bash .githooks/install.sh
# Verify git hooks path
git config --get core.hooksPath
False Positives
If legitimate words are being blocked, refine your patterns:
# Instead of blocking "AI" (too broad), be more specific:
blocked_patterns=(
"AI-generated" # Specific AI attribution
"AI assisted" # Specific AI attribution
# Don't block "AI" alone - could be "AI algorithms" or "AI field"
)
Emergency Bypass
For urgent fixes when the hook blocks legitimate commits:
# Temporary bypass (use sparingly)
git commit --no-verify -m "hotfix: critical security patch"
# Or set environment variable
NO_VERIFY=1 git commit -m "emergency deployment fix"
Testing Your Hooks
Create a test script to verify your hook works:
#!/bin/bash
# test-hooks.sh
echo "Testing commit message hook..."
test_messages=(
"feat: add user auth" # Should pass
"π€ Generated with Claude" # Should fail
"fix: resolve login issue with AI help" # Should fail
"docs: update Claude integration guide" # Should fail
"refactor: improve authentication flow" # Should pass
)
for msg in "${test_messages[@]}"; do
echo "Testing: $msg"
if echo "$msg" | .githooks/commit-msg /dev/stdin 2>/dev/null; then
echo " β
Passed"
else
echo " β Blocked"
fi
echo
done
Conclusion: Maintaining Professional Git History
Implementing AI reference prevention in your Git hooks is a simple but effective way to maintain professional standards in your repository. This approach:
- Enforces consistency: All team members follow the same standards
- Prevents embarrassment: No AI attribution in client-facing repositories
- Focuses on value: Commits describe business impact, not development process
- Maintains legal clarity: Clear human authorship attribution
- Automates quality: No manual review needed for commit message standards
Key takeaways:
- Automate prevention rather than relying on manual review
- Document the process so team members understand why
- Provide clear feedback when commits are blocked
- Allow emergency bypasses for critical situations
- Test thoroughly to avoid false positives
Your git history is a professional reflection of your development process. By preventing AI attribution in commit messages, you ensure that your repository maintains the highest standards of professionalism while still benefiting from AI assistance during development.
The goal isn't to hide the use of AI toolsβit's to ensure that your git history remains focused on what matters: the changes made and their business impact.
Start implementing these hooks today, and your future self (and your team) will thank you for the clean, professional commit history.