Skip to content

Instantly share code, notes, and snippets.

@panphora
Created November 3, 2025 18:02
Show Gist options
  • Select an option

  • Save panphora/1cf274e089ef4257e958101cf6f327b1 to your computer and use it in GitHub Desktop.

Select an option

Save panphora/1cf274e089ef4257e958101cf6f327b1 to your computer and use it in GitHub Desktop.

Git Hook: Filter Claude Co-Author Attribution

This global git hook automatically removes Claude Code's Co-Authored-By: line from all commit messages across all repositories.

Installation

  1. Configure git to use a global hooks directory:
mkdir -p ~/.git-hooks
git config --global core.hooksPath ~/.git-hooks
  1. Create the commit-msg hook:
touch ~/.git-hooks/commit-msg
chmod +x ~/.git-hooks/commit-msg
  1. Add the following content to ~/.git-hooks/commit-msg:

For macOS:

#!/bin/sh
#
# Filter out Claude Code co-author attribution from commit messages
#

# Read the commit message file
COMMIT_MSG_FILE=$1

# Remove Claude-specific Co-Authored-By line
sed -i '' '/Co-Authored-By: Claude/d' "$COMMIT_MSG_FILE"

# Remove trailing blank lines (but keep the message content)
perl -i -pe 's/\n+$/\n/' "$COMMIT_MSG_FILE"

For Linux:

#!/bin/sh
#
# Filter out Claude Code co-author attribution from commit messages
#

# Read the commit message file
COMMIT_MSG_FILE=$1

# Remove Claude-specific Co-Authored-By line
sed -i '/Co-Authored-By: Claude/d' "$COMMIT_MSG_FILE"

# Remove trailing blank lines (but keep the message content)
perl -i -pe 's/\n+$/\n/' "$COMMIT_MSG_FILE"

What It Does

The hook automatically removes Claude Code's co-author attribution from commit messages:

Note: This only filters out Claude-specific attribution. Other Co-Authored-By: lines (from human contributors) will be preserved.

Example

Before hook:

Add new feature

This is a description.

Co-Authored-By: Claude <[email protected]>

After hook:

Add new feature

This is a description.

Notes

  • This is a global git hook that applies to all repositories on your machine
  • The hook runs automatically on every git commit in any repository
  • It silently filters out Claude's co-author line without any error messages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment