Skip to content

Instantly share code, notes, and snippets.

@Sinetheta
Last active September 12, 2025 19:56
Show Gist options
  • Select an option

  • Save Sinetheta/56d31d6f51b6a3d9b02350963503dd2d to your computer and use it in GitHub Desktop.

Select an option

Save Sinetheta/56d31d6f51b6a3d9b02350963503dd2d to your computer and use it in GitHub Desktop.
A git commit-msg hook that automatically adds co-author attribution when Cursor makes commits, while remaining completely transparent to human users and other tools.

Cursor-Aware Git Commit Hook

A git commit-msg hook that automatically adds co-author attribution when Cursor makes commits, while remaining completely transparent to human users and other tools.

Features

  • Cursor Detection: Only activates when Cursor environment is detected
  • Automatic Attribution: Adds Co-authored-by: Cursor <[email protected]> to commit messages
  • Transparent: Human users and other tools are unaffected
  • Smart: Won't duplicate co-author lines if already present
  • Easy Setup: One-command installation

Installation

  1. Download the hook script:

    curl -o git-commit-msg-hook.sh https://gist.githubusercontent.com/Sinetheta/56d31d6f51b6a3d9b02350963503dd2d/raw/git-commit-msg-hook.sh
  2. Install the hook:

    chmod +x git-commit-msg-hook.sh
    cp git-commit-msg-hook.sh .git/hooks/commit-msg
    chmod +x .git/hooks/commit-msg
  3. Test it: Make a commit from Cursor and check the commit message!

Files

git-commit-msg-hook.sh

The main hook script that detects Cursor and adds co-author attribution.

install-cursor-hook.sh

Convenience script to install the hook with proper permissions.

How It Works

The hook detects Cursor through multiple environment variables:

  • TERM_PROGRAM == "cursor"
  • CURSOR_SESSION is set
  • USER_AGENT contains "Cursor"
  • CURSOR_AGENT == "1"

When Cursor is detected, it automatically appends the co-author line to commit messages.

Usage in AI Instructions

Add this to your AI agent instructions:

- **ALWAYS** use `git commit -m "message"` for commits (pre-commit hook auto-adds co-author when Cursor is detected)

License

MIT License - feel free to adapt and use in your projects!


Note: This hook is completely transparent to human users and other development tools. It only activates when Cursor is detected as the committer.

#!/bin/bash
# Commit-msg hook to automatically add co-author attribution for Cursor commits
# This hook only activates when Cursor is detected as the committer
# Human users and other tools are unaffected
# Detect if Cursor is the committer
if [[ "$TERM_PROGRAM" == "cursor" ]] || [[ -n "$CURSOR_SESSION" ]] || [[ "$USER_AGENT" == *"Cursor"* ]] || [[ "$CURSOR_AGENT" == "1" ]]; then
# Cursor detected - add co-author attribution
echo "🤖 Cursor detected - adding co-author attribution"
# Check if commit message already has co-author
if ! grep -q "Co-authored-by: Cursor" "$1"; then
echo "" >> "$1"
echo "Co-authored-by: Cursor <[email protected]>" >> "$1"
fi
else
# Not Cursor - do nothing (transparent for other users)
exit 0
fi
#!/bin/bash
# Setup script to install the Cursor-aware commit-msg hook
# This hook only adds co-author attribution when Cursor is detected
echo "🔧 Installing Cursor-aware commit-msg hook..."
# Copy the hook to git hooks directory
cp scripts/git-commit-msg-hook.sh .git/hooks/commit-msg
# Make it executable
chmod +x .git/hooks/commit-msg
echo "✅ Commit-msg hook installed successfully!"
echo ""
echo "The hook will:"
echo " ✅ Add co-author attribution when Cursor makes commits"
echo " ✅ Do nothing when humans or other tools make commits"
echo " ✅ Be completely transparent to all users"
echo ""
echo "To test: Make a commit from Cursor and check the commit message"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment