diff --git a/tools/commit-cleaner/README.md b/tools/commit-cleaner/README.md index a3ee905..250930c 100644 --- a/tools/commit-cleaner/README.md +++ b/tools/commit-cleaner/README.md @@ -15,6 +15,28 @@ commits that already carry them. | `claude-settings.example.json` | Drop-in `.claude/settings.json` for a repository that vendors the hook under `.githooks/`. | | `test.sh` | Tests for all of the above. | +## First line of defense: turn the trailers off + +Claude Code has a supported setting that stops it writing the trailers in the +first place. Put this in `.claude/settings.json` (project) or +`~/.claude/settings.json` (every project on your machine): + +```json +{ + "attribution": { + "commit": "", + "sessionUrl": false + } +} +``` + +`commit: ""` removes the `Co-Authored-By` trailer and `sessionUrl: false` +removes the `Claude-Session:` link that cloud and Remote Control sessions add. +Add `"pr": ""` to drop the pull-request footer too. This works everywhere the +settings file loads, with no git configuration. The hook below is the backstop +for anything that still slips through (older clients, other tools, pasted +messages). + ## What is removed * `Co-Authored-By:` lines whose address is `@anthropic.com`, or whose name starts with `Claude` @@ -54,7 +76,8 @@ is a fresh clone with no hooks installed: 1. Copy `commit-msg` to `.githooks/commit-msg` in the repository. 2. Copy `guard.py` to `.claude/hooks/commit-guard.py`. -3. Copy `claude-settings.example.json` to `.claude/settings.json`. +3. Copy `claude-settings.example.json` to `.claude/settings.json`. It carries + the `attribution` setting above plus the two hooks. The `SessionStart` hook points `core.hooksPath` at `.githooks/` at the start of every session, and the `PreToolUse` hook blocks bypasses. Contributors working diff --git a/tools/commit-cleaner/claude-settings.example.json b/tools/commit-cleaner/claude-settings.example.json index 5165e25..c38bba0 100644 --- a/tools/commit-cleaner/claude-settings.example.json +++ b/tools/commit-cleaner/claude-settings.example.json @@ -1,11 +1,15 @@ { + "attribution": { + "commit": "", + "sessionUrl": false + }, "hooks": { "SessionStart": [ { "hooks": [ { "type": "command", - "command": "git config core.hooksPath .githooks" + "command": "cd \"${CLAUDE_PROJECT_DIR:-.}\" && git config core.hooksPath .githooks" } ] } diff --git a/tools/commit-cleaner/guard.py b/tools/commit-cleaner/guard.py index 380a08b..a8b0d59 100755 --- a/tools/commit-cleaner/guard.py +++ b/tools/commit-cleaner/guard.py @@ -16,6 +16,7 @@ {"hooks": {"PreToolUse": [{"matcher": "Bash", "hooks": [{"type": "command", "command": "python3 /guard.py"}]}]}} """ + import json import re import shlex @@ -79,8 +80,18 @@ def check(words): if not words or words[0] != "git": # Tampering with the hook file itself. joined = " ".join(words) - if re.search(r"hooks/commit-msg|\.githooks/commit-msg", joined) and words[0] in ( - "rm", "mv", "cp", "chmod", "truncate", "tee", "sed", "install", "ln", + if re.search(r"hooks/commit-msg|\.githooks/commit-msg", joined) and words[ + 0 + ] in ( + "rm", + "mv", + "cp", + "chmod", + "truncate", + "tee", + "sed", + "install", + "ln", ): deny("refusing to modify or remove the commit-msg hook") return @@ -89,14 +100,21 @@ def check(words): opts, i = [], 1 while i < len(words) and words[i].startswith("-"): opts.append(words[i]) - if words[i] in ("-c", "-C", "--git-dir", "--work-tree", "--config-env", "--exec-path"): + if words[i] in ( + "-c", + "-C", + "--git-dir", + "--work-tree", + "--config-env", + "--exec-path", + ): if i + 1 < len(words): opts.append(words[i + 1]) i += 1 i += 1 if i >= len(words): return - sub, args = words[i], words[i + 1:] + sub, args = words[i], words[i + 1 :] if sub == "config" and any("hookspath" in a.lower() for a in args): deny("changing core.hooksPath would disable the commit-msg hook") @@ -114,7 +132,14 @@ def check(words): deny("overriding core.hooksPath on the command line skips the hook") if any(o == "--git-dir" or o.startswith("--git-dir=") for o in opts): deny("relocating --git-dir for a commit bypasses the repository hooks") - for k in ("HOME", "GIT_DIR", "GIT_CONFIG_GLOBAL", "GIT_CONFIG_SYSTEM", "GIT_CONFIG_PARAMETERS", "XDG_CONFIG_HOME"): + for k in ( + "HOME", + "GIT_DIR", + "GIT_CONFIG_GLOBAL", + "GIT_CONFIG_SYSTEM", + "GIT_CONFIG_PARAMETERS", + "XDG_CONFIG_HOME", + ): if k in env: deny(f"setting {k} for a commit can relocate the hooks; commit without it")