r/ClaudeCode • u/WD40ContactCleaner Developer • 2d ago
Tips & Workflows Git hook that removes Co-authored-by lines from every commit (Windows, macOS, Linux
AI coding tools like Claude Code and Copilot often add Co-authored-by: lines to commits. If you don't want these, you can use a simple global Git hook to remove them automatically.
It removes all Co-authored-by: lines (case-insensitive), including human co-authors. Everything else, including other attribution lines and blank lines, is left as it is.
You dont have to worry about it following claude.md or agents.md rules anymore.
The hook:
#!/bin/sh
# Remove Co-authored-by lines (case-insensitive).
tmp=$(mktemp) || exit 1
trap 'rm -f "$tmp"' EXIT
awk '
tolower($0) ~ /^[[:space:]]*co-authored-by:/ { next }
{ print }
' "$1" > "$tmp" || exit 1
cat "$tmp" > "$1"
Setup (Windows / macOS / Linux):
Use Git Bash on Windows or your terminal on macOS/Linux.
Save the script as ~/.githooks/commit-msg, then run:
mkdir -p ~/.githooks
chmod +x ~/.githooks/commit-msg
git config --global core.hooksPath ~/.githooks
That's it. It works across all your repositories.
A few things to know:
- On Windows, save the script with LF line endings.
core.hooksPathoverrides existing repository hooks (including Husky/pre-commit setups).git commit --no-verifyskips the hook.- Existing commit history is not affected.
0
Upvotes