Skip to content

Instantly share code, notes, and snippets.

@imaitland
Last active August 14, 2026 17:13
Show Gist options
  • Select an option

  • Save imaitland/caefe0b2d6f007f1c200ee4e294f8494 to your computer and use it in GitHub Desktop.

Select an option

Save imaitland/caefe0b2d6f007f1c200ee4e294f8494 to your computer and use it in GitHub Desktop.
strip or adapt Claude Code attribution from commit messages
title strip-claude
date 2026-08-14
author Iain Maitland
tags
git
hooks
claude-code
summary A Git commit-msg hook that removes trailing Claude Code attribution from commit messages.

strip-claude

strip-claude is a Git commit-msg hook that strips trailing Claude Code attribution from commit messages.

What It Removes

The hook removes trailing lines such as:

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/...
Generated with Claude Code
Created by Claude Code
Generated with [Claude Code](https://claude.com/claude-code)

Install Globally

Git can use one hooks directory for all repositories through the global core.hooksPath setting:

mkdir -p ~/.config/git/hooks
curl -fsSL https://gist.githubusercontent.com/imaitland/caefe0b2d6f007f1c200ee4e294f8494/raw/strip-claude-commit-msg -o ~/.config/git/hooks/commit-msg
chmod +x ~/.config/git/hooks/commit-msg
git config --global core.hooksPath ~/.config/git/hooks

Install In One Repo

From the repository where you want the hook active:

mkdir -p .githooks
curl -fsSL https://gist.githubusercontent.com/imaitland/caefe0b2d6f007f1c200ee4e294f8494/raw/strip-claude-commit-msg -o .githooks/commit-msg
chmod +x .githooks/commit-msg
git config core.hooksPath .githooks

Test Locally

tmp=$(mktemp)
printf '%s\n' \
  'feat: test hook' \
  '' \
  'This body mentions Claude and should stay.' \
  '' \
  'Generated with Claude Code' \
  'Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>' > "$tmp"

hooks_path=$(git config --path --get core.hooksPath)
"$hooks_path/commit-msg" "$tmp"
cat "$tmp"
rm -f "$tmp"

Expected output:

feat: test hook

This body mentions Claude and should stay.

Notes

The hook can be customized as you like. For example, you can misdirect and attribute a commit to another agent, or be honest and say something like:

An LLM trained on the sum total of human knowledge was used.

Claude Code can be configured to omit this attribution (but not make it honest) at the source. See Claude Code attribution settings.

#!/bin/sh
# Remove Claude Code attribution trailers/footers from commit messages.
set -e
msg_file=$1
if [ -z "$msg_file" ] || [ ! -f "$msg_file" ]; then
printf >&2 '%s\n' "strip-claude: missing commit message file"
exit 1
fi
tmp_file=$(mktemp "${TMPDIR:-/tmp}/strip-claude.XXXXXX")
trap 'rm -f "$tmp_file"' EXIT
awk '
function is_claude_footer(line, lower) {
lower = tolower(line)
if (!index(lower, "claude")) {
return 0
}
if (lower ~ /^[[:space:]]*[[:alnum:]-]+:[[:space:]]*/) {
return 1
}
if (index(lower, "generated") ||
index(lower, "created") ||
index(lower, "authored") ||
index(lower, "claude code")) {
return 1
}
return 0
}
function emit_pending_blank() {
if (started && pending_blank) {
print ""
}
pending_blank = 0
}
{
lines[++line_count] = $0
}
END {
scan_end = line_count
while (scan_end > 0 &&
(lines[scan_end] ~ /^[[:space:]]*$/ ||
lines[scan_end] ~ /^[[:space:]]*#/)) {
scan_end--
}
for (i = scan_end; i > 0; i--) {
if (is_claude_footer(lines[i])) {
remove[i] = 1
removed_attribution = 1
continue
}
if (removed_attribution && lines[i] ~ /^[[:space:]]*$/) {
remove[i] = 1
continue
}
break
}
for (i = 1; i <= line_count; i++) {
if (remove[i]) {
continue
}
if (lines[i] ~ /^[[:space:]]*$/) {
if (started) {
pending_blank = 1
}
continue
}
emit_pending_blank()
print lines[i]
started = 1
}
}
' "$msg_file" > "$tmp_file"
cat "$tmp_file" > "$msg_file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment