Skip to content

chore: enforce Assisted-By attribution via commit-msg hook - #636

Merged
pdettori merged 2 commits into
rossoctl:mainfrom
pdettori:chore/assisted-by-commit-msg-hook
Oct 27, 2026
Merged

pdettori merged 2 commits into
rossoctl:mainfrom
pdettori:chore/assisted-by-commit-msg-hook

Conversation

@pdettori

Copy link
Copy Markdown
Member

Summary

Adds a commit-msg hook that mechanically enforces the repo's Assisted-By attribution
policy (CLAUDE.md, "Commit Attribution"), mirroring the setup already in use in
rossoctl/rossoctl.

AI assistants (Claude Code, Cursor) sometimes add Co-authored-by trailers to commit
messages. GitHub parses those as co-authorship, inflating contributor stats. The CLAUDE.md
policy already says to use Assisted-By instead, but nothing enforced it — a trailer that
slips past review lands in history.

Changes

  • scripts/hooks/commit-msg — strips Co-authored-by: …Claude/Cursor/anthropic… and
    Made-with: lines from the commit message and, if any were present, appends
    Assisted-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 with stages: [commit-msg].
  • CLAUDE.md — documents the enforcement and updates the install instructions to
    pre-commit install --hook-type pre-commit --hook-type commit-msg.

Notes

  • Contributors who already ran plain pre-commit install need to re-run it with the
    --hook-type commit-msg flag (or pre-commit install -t pre-commit -t commit-msg)
    to get the new hook; the existing pre-commit hook is unaffected.
  • The script has no .sh extension, so the shellcheck gate (.sh$ files) is unaffected.
  • Verified locally: a message carrying Co-authored-by: Claude Code and Made-with: comes
    out with a single Assisted-By: trailer and no trailing blank lines.

Assisted-By: Claude Code

@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Oct 27, 2026
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]>
@pdettori
pdettori force-pushed the chore/assisted-by-commit-msg-hook branch from 3d6a524 to 79faafb Compare October 27, 2026 16:08

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread scripts/hooks/commit-msg Outdated
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"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Appending after the last line breaks in two cases:

  1. With git commit -v / commit.verbose=true, the file ends with the scissors block. Assisted-By lands below # ------------------------ >8 ------------------------ and git discards it, so the AI trailer is stripped and no attribution is left. (Reproduced in a scratch repo.)
  2. If the message already has Assisted-By: and Signed-off-by:, the result has a duplicate Assisted-By in a separate paragraph, and Signed-off-by is no longer in the trailer block (git interpret-trailers --parse shows 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread scripts/hooks/commit-msg Outdated
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" \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shared one AI_TRAILER_PATTERN between the detection and the strip, and dropped the redundant cursor alternative (already covered by -i).

Comment thread .pre-commit-config.yaml
# 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
@pdettori
pdettori merged commit ac4f3fd into rossoctl:main Oct 27, 2026
14 checks passed
@pdettori
pdettori deleted the chore/assisted-by-commit-msg-hook branch October 27, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants