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 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
-
Download the hook script:
curl -o git-commit-msg-hook.sh https://gist.githubusercontent.com/Sinetheta/56d31d6f51b6a3d9b02350963503dd2d/raw/git-commit-msg-hook.sh
-
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
-
Test it: Make a commit from Cursor and check the commit message!
The main hook script that detects Cursor and adds co-author attribution.
Convenience script to install the hook with proper permissions.
The hook detects Cursor through multiple environment variables:
TERM_PROGRAM == "cursor"CURSOR_SESSIONis setUSER_AGENTcontains "Cursor"CURSOR_AGENT == "1"
When Cursor is detected, it automatically appends the co-author line to commit messages.
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)
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.