Repository navigation
chore: enforce Assisted-By attribution via commit-msg hook - #636
Conversation
Add scripts/hooks/commit-msg, wired through pre-commit (stages: [commit-msg]), that strips Co-authored-by trailers for Claude/Cursor and Made-with lines and rewrites them as Assisted-By, so AI assistance does not inflate GitHub contributor stats. Update CLAUDE.md to document the policy and the new pre-commit install invocation. Mirrors the setup used in rossoctl/rossoctl. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
3d6a524 to
79faafb
Compare
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Force-push 3d6a524 → 79faafb only re-pads the CLAUDE.md Key Commands table for prettier, so the red lint check is fixed and is now green. The hook script and pre-commit config are unchanged. The remaining items are non-blocking (2 suggestions, 1 nit): the hook appends after the git commit -v scissors line and can duplicate Assisted-By (git interpret-trailers fixes both), the strip/detect regexes can drift, and default_install_hook_types is missing.
Author: pdettori (MEMBER, maintainer). Agent/IDE config: none. 1 commit, signed-off.
| if [ "$HAS_AI_TRAILER" = true ]; then | ||
| # Ensure there's a blank line before the trailer | ||
| echo "" >> "$COMMIT_MSG_FILE" | ||
| echo "Assisted-By: Claude (Anthropic AI) <[email protected]>" >> "$COMMIT_MSG_FILE" |
There was a problem hiding this comment.
suggestion: Appending after the last line breaks in two cases:
- With
git commit -v/commit.verbose=true, the file ends with the scissors block.Assisted-Bylands below# ------------------------ >8 ------------------------and git discards it, so the AI trailer is stripped and no attribution is left. (Reproduced in a scratch repo.) - If the message already has
Assisted-By:andSigned-off-by:, the result has a duplicateAssisted-Byin a separate paragraph, andSigned-off-byis no longer in the trailer block (git interpret-trailers --parseshows only Assisted-By).
git interpret-trailers --in-place --if-exists doNothing --trailer "Assisted-By: Claude (Anthropic AI) <[email protected]>" "$COMMIT_MSG_FILE" handles the scissors line, dedupes, and keeps a single trailer block. That makes the blank-line handling here unnecessary.
There was a problem hiding this comment.
Reproduced both cases — the trailer landed below the scissors line and was discarded, and the existing-trailers case produced a duplicate Assisted-By split from the trailer block. Switched to git interpret-trailers --in-place --if-exists doNothing as suggested and dropped the manual blank-line handling. Verified end-to-end with commit -v in a scratch repo: the trailer now lands above the scissors line and survives the commit, and the existing-trailers case keeps a single block with no duplicate.
| fi | ||
|
|
||
| # Strip Co-authored-by lines for Claude/Cursor and Made-with lines | ||
| grep -vi -E '^Co-authored-by:.*(Claude|Cursor|anthropic|cursor)' "$COMMIT_MSG_FILE" \ |
There was a problem hiding this comment.
nit: cursor is redundant with -i, and this regex differs from the one on line 9. One PATTERN variable shared by both greps would stop them drifting apart.
There was a problem hiding this comment.
Shared one AI_TRAILER_PATTERN between the detection and the strip, and dropped the redundant cursor alternative (already covered by -i).
| # Rewrite AI co-author trailers to Assisted-By (see CLAUDE.md, Commit Attribution). | ||
| # Only runs once the commit-msg hook type is installed: | ||
| # pre-commit install --hook-type pre-commit --hook-type commit-msg | ||
| - repo: local |
There was a problem hiding this comment.
suggestion: Consider a top-level default_install_hook_types: [pre-commit, commit-msg]. With it, a plain pre-commit install (what existing contributors already ran, and what most muscle memory types) installs this hook too, and the longer command in CLAUDE.md becomes optional.
There was a problem hiding this comment.
Added default_install_hook_types: [pre-commit, commit-msg] and reverted CLAUDE.md to the plain pre-commit install.
Address review feedback: - Add the Assisted-By trailer with `git interpret-trailers --in-place --if-exists doNothing`: it inserts into the trailer block above the scissors line of a `commit -v` message (where a manual append landed below it and git discarded it), dedupes against an existing Assisted-By, and keeps a single trailer block. The manual trailing blank-line handling goes away with it. - Share one AI_TRAILER_PATTERN between the detection and the strip, and drop the redundant case-insensitive `cursor` alternative. - Add default_install_hook_types: [pre-commit, commit-msg] so a plain `pre-commit install` sets up the hook; CLAUDE.md reverts to the plain command. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Summary
Adds a
commit-msghook that mechanically enforces the repo'sAssisted-Byattributionpolicy (CLAUDE.md, "Commit Attribution"), mirroring the setup already in use in
rossoctl/rossoctl.
AI assistants (Claude Code, Cursor) sometimes add
Co-authored-bytrailers to commitmessages. GitHub parses those as co-authorship, inflating contributor stats. The CLAUDE.md
policy already says to use
Assisted-Byinstead, but nothing enforced it — a trailer thatslips past review lands in history.
Changes
scripts/hooks/commit-msg— stripsCo-authored-by: …Claude/Cursor/anthropic…andMade-with:lines from the commit message and, if any were present, appendsAssisted-By: Claude (Anthropic AI) <[email protected]>. Never rejects the commit;it only rewrites the trailers.
.pre-commit-config.yaml— wires the script as a local hook withstages: [commit-msg].CLAUDE.md— documents the enforcement and updates the install instructions topre-commit install --hook-type pre-commit --hook-type commit-msg.Notes
pre-commit installneed to re-run it with the--hook-type commit-msgflag (orpre-commit install -t pre-commit -t commit-msg)to get the new hook; the existing pre-commit hook is unaffected.
.shextension, so the shellcheck gate (.sh$files) is unaffected.Co-authored-by: Claude CodeandMade-with:comesout with a single
Assisted-By:trailer and no trailing blank lines.Assisted-By: Claude Code