Git hooks that prevent AI indicators from being committed to your repository.
The hooks scan for AI references including:
- AI tool names (Claude, Cursor, Copilot, ChatGPT, Gemini, etc.)
- AI-related phrases ("ai-generated", "ai-assisted", "generated with", etc.)
- Model names (GPT-4, Claude Sonnet, Claude Code, etc.)
- Company names (OpenAI, Anthropic, etc.)
- Co-authorship markers (Co-Authored-By: Claude, [email protected], etc.)
Install pre-commit:
pip install pre-commit-
Navigate to your repository:
cd /path/to/your/repo -
Create or update
.pre-commit-config.yaml:repos: - repo: local hooks: - id: ai-pre-commit name: Block AI indicators in staged files entry: python3 .config/ai-hooks/ai_guard.py pre-commit language: system pass_filenames: false stages: [pre-commit] - id: ai-commit-msg name: Block AI indicators in commit messages entry: python3 .config/ai-hooks/ai_guard.py commit-msg language: system stages: [commit-msg]
-
Install the hooks:
pre-commit install
- Runs when you create a commit
- Scans the commit message for AI indicators
- Blocks the commit if any indicators are found
- Runs before the commit is created
- Scans all staged files for AI indicators
- Blocks the commit if any indicators are found in the code
To remove the hooks from a repository:
cd /path/to/your/repo
rm .git/hooks/commit-msg .git/hooks/pre-commit .git/hooks/ai_guard.pyTo verify the hooks are working:
-
Create a test file with AI indicators:
echo "Generated with Claude Code" > test.txt git add test.txt git commit -m "test"
-
You should see an error message blocking the commit
-
Clean up:
git reset HEAD test.txt rm test.txt
In rare cases where you need to commit content with AI indicators, you can bypass the hooks using the --no-verify flag:
git commit --no-verify -m "your commit message"- These hooks are repository-specific and must be installed in each repo where you want them active
- Git hooks are not tracked by git itself (they live in
.git/hooks/) - If you have existing hooks, the installer will create
.backupcopies - All pattern matching is case-insensitive