From 71969ccc4d8a396ac686886addcb4a5dddb33fe0 Mon Sep 17 00:00:00 2001 From: Kai Chen Date: Fri, 17 Apr 2026 05:25:53 -0700 Subject: [PATCH] chore: auto-credit Claude as co-author on every commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds .githooks/prepare-commit-msg that appends a Co-authored-by trailer for Claude via `git interpret-trailers` (safe for merge/squash, idempotent on existing trailers). `package.json` now runs `git config core.hooksPath .githooks` in postinstall so `npm install` activates the hook in any fresh clone — no extra devDependency like husky. AGENTS.md and the Cursor git-workflow rule document the policy so agents add the trailer explicitly when committing through environments that skip git hooks (web editors, sandboxed runs, --no-verify). Made-with: Cursor Co-authored-by: Claude --- .cursor/rules/git-workflow.mdc | 7 +++++++ .githooks/prepare-commit-msg | 27 +++++++++++++++++++++++++++ AGENTS.md | 20 +++++++++++++++++++- package.json | 3 ++- 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100755 .githooks/prepare-commit-msg diff --git a/.cursor/rules/git-workflow.mdc b/.cursor/rules/git-workflow.mdc index 3664f61..d51f9c9 100644 --- a/.cursor/rules/git-workflow.mdc +++ b/.cursor/rules/git-workflow.mdc @@ -20,6 +20,13 @@ See `AGENTS.md` for the full canonical version. Short form: 2. Commit with conventional-style message: `: ` + **Every commit must credit Claude as co-author.** `.githooks/prepare-commit-msg` + appends the trailer automatically after `npm install`, but include it + explicitly anyway as defense-in-depth: + ``` + Co-authored-by: Claude + ``` + 3. Push the branch and open a PR: ```bash git push -u origin HEAD diff --git a/.githooks/prepare-commit-msg b/.githooks/prepare-commit-msg new file mode 100755 index 0000000..b2ed9ad --- /dev/null +++ b/.githooks/prepare-commit-msg @@ -0,0 +1,27 @@ +#!/usr/bin/env sh +# Appends a Co-authored-by trailer crediting Claude on every commit. +# +# Activated via `core.hooksPath = .githooks`, which is set automatically by the +# `postinstall` npm script. To install manually, run: +# git config core.hooksPath .githooks + +set -e + +COMMIT_MSG_FILE=$1 +COMMIT_SOURCE=$2 + +# Skip for true merge commits (they carry their own author metadata) but run +# for everything else including squash, amend, and template-based commits. +case "$COMMIT_SOURCE" in + merge) exit 0 ;; +esac + +COAUTHOR="Co-authored-by: Claude " + +# `git interpret-trailers` handles trailer placement (blank line before, +# existing trailers, duplicates) correctly. +git interpret-trailers \ + --in-place \ + --if-exists addIfDifferent \ + --trailer "$COAUTHOR" \ + "$COMMIT_MSG_FILE" diff --git a/AGENTS.md b/AGENTS.md index ba8312e..a5faee2 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -18,11 +18,17 @@ For every change: ``` Branch name format: `fix/…`, `feat/…`, `chore/…`, `docs/…`, `refactor/…`. -2. Commit with a conventional-style message: +2. Commit with a conventional-style message. **Every commit in this repo must + credit Claude as a co-author** — `.githooks/prepare-commit-msg` appends the + trailer automatically once `npm install` has run, but include it explicitly + anyway (e.g. when you commit via an API/web editor that skips git hooks): + ``` : + + Co-authored-by: Claude ``` 3. Push the branch and open a PR with `gh pr create`: @@ -52,6 +58,18 @@ Run the same sequence CI runs — fail fast locally: npm run lint && npm run typecheck && npm run test && npm run build ``` +## Git hooks (co-author trailer) + +This repo ships a `prepare-commit-msg` hook at `.githooks/prepare-commit-msg` +that appends `Co-authored-by: Claude ` on every commit +(skipped for merge commits). `npm install` sets `core.hooksPath = .githooks` +via the `postinstall` script, so the hook activates automatically after a +fresh clone + install. + +If you commit in an environment where the hook can't run (GitHub web editor, +some sandboxed agents, `-n` / `--no-verify` situations), add the trailer +manually so the policy is never silently dropped. + ## Secrets Never commit `.env.local`, `.env.vercel.check`, `.env.sentry-build-plugin`, or diff --git a/package.json b/package.json index 287a9ed..466459b 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "lint": "eslint", "typecheck": "tsc --noEmit", "test": "vitest run", - "test:watch": "vitest" + "test:watch": "vitest", + "postinstall": "git config core.hooksPath .githooks 2>/dev/null || true" }, "dependencies": { "@fontsource/bitter": "^5.2.10",