Last active
November 2, 2026 13:48
-
-
Save kibotu/2f6e8e89c59c073d7f878b7825c45f4e to your computer and use it in GitHub Desktop.
Disable supported AI-agent commit / PR attribution settings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # | |
| # Disable supported AI-agent commit / PR attribution settings. | |
| # Read-only preflight; each file is patched only after an individual approval. | |
| # | |
| # Requirements: Bash 3.2+, Python 3.11+ (stdlib JSON + TOML validation). | |
| # Usage: bash disable-agent-attribution.sh | |
| # | |
| set -Eeuo pipefail | |
| IFS=$'\n\t' | |
| readonly SCRIPT_NAME="${0##*/}" | |
| readonly PYTHON="${PYTHON:-python3}" | |
| if ! command -v "$PYTHON" >/dev/null 2>&1; then | |
| printf 'error: Python 3 is required (JSON/TOML-safe config editing).\n' >&2 | |
| exit 1 | |
| fi | |
| "$PYTHON" - <<'PY' | |
| import json | |
| import os | |
| import re | |
| import shutil | |
| import stat | |
| import sys | |
| import tempfile | |
| from pathlib import Path | |
| HOME = Path.home() | |
| GREEN, YELLOW, RED, CYAN, DIM, RESET = ( | |
| "\033[32m", "\033[33m", "\033[31m", "\033[36m", "\033[2m", "\033[0m" | |
| ) | |
| COLOR = sys.stdout.isatty() and os.environ.get("NO_COLOR") is None | |
| def paint(s, c): return f"{c}{s}{RESET}" if COLOR else s | |
| def section(title): | |
| print() | |
| print(paint("── " + title + " " + "─" * max(2, 58-len(title)), CYAN)) | |
| def state(label, detail, color=None): | |
| mark = "●" if color else "○" | |
| print(f" {paint(mark, color or DIM)} {label:<19} {detail}") | |
| def atomic_write(path: Path, content: str): | |
| path.parent.mkdir(parents=True, exist_ok=True) | |
| mode = stat.S_IMODE(path.stat().st_mode) if path.exists() else 0o600 | |
| fd, tmp = tempfile.mkstemp(prefix=f".{path.name}.", suffix=".tmp", dir=str(path.parent)) | |
| try: | |
| with os.fdopen(fd, "w", encoding="utf-8", newline="") as f: | |
| f.write(content) | |
| f.flush() | |
| os.fsync(f.fileno()) | |
| os.chmod(tmp, mode) | |
| # Keep a single, non-overwriting backup per original state. | |
| if path.exists(): | |
| backup = path.with_name(path.name + ".pre-attribution-disable.bak") | |
| if not backup.exists(): | |
| shutil.copy2(path, backup) | |
| os.replace(tmp, path) | |
| except BaseException: | |
| try: os.unlink(tmp) | |
| except OSError: pass | |
| raise | |
| def read_json(path): | |
| try: | |
| with path.open(encoding="utf-8") as f: return json.load(f) | |
| except FileNotFoundError: | |
| return {} | |
| except (OSError, UnicodeError, json.JSONDecodeError) as e: | |
| raise ValueError(f"cannot safely parse JSON: {e}") | |
| def write_json(path, data): | |
| old = path.read_text(encoding="utf-8") if path.exists() else "" | |
| indent = 2 | |
| if old: | |
| m = re.search(r"\n([ \t]+)\S", old) | |
| if m: indent = len(m.group(1).replace("\t", " ")) | |
| newline = "\r\n" if "\r\n" in old else "\n" | |
| rendered = json.dumps(data, ensure_ascii=False, indent=indent) + newline | |
| atomic_write(path, rendered) | |
| def claude_status(path): | |
| d = read_json(path) | |
| a = d.get("attribution") | |
| # Empty commit + PR + no session URL covers older supported versions; | |
| # attribution:false is the newer all-attribution switch. | |
| if a is False: return "disabled" | |
| if isinstance(a, dict) and a.get("commit") == "" and a.get("pr") == "" and a.get("sessionUrl") is False: | |
| return "disabled" | |
| return "needs patch" | |
| def patch_claude(path): | |
| d = read_json(path) | |
| d["attribution"] = {"commit": "", "pr": "", "sessionUrl": False} | |
| write_json(path, d) | |
| def cursor_status(path): | |
| d = read_json(path) | |
| a = d.get("attribution", {}) | |
| if isinstance(a, dict) and a.get("attributeCommitsToAgent") is False and a.get("attributePRsToAgent") is False: | |
| return "disabled" | |
| return "needs patch" | |
| def patch_cursor(path): | |
| d = read_json(path) | |
| a = d.get("attribution") | |
| if not isinstance(a, dict): a = {} | |
| a["attributeCommitsToAgent"] = False | |
| a["attributePRsToAgent"] = False | |
| d["attribution"] = a | |
| write_json(path, d) | |
| def codex_status(path): | |
| import tomllib | |
| # Parse the complete file before considering any edit; malformed TOML is never rewritten. Do not mistake a key in a table | |
| # for the top-level commit_attribution setting. | |
| if not path.exists(): return "needs patch" | |
| text = path.read_text(encoding="utf-8") | |
| top = re.split(r"(?m)^\s*\[", text, maxsplit=1)[0] | |
| m = re.search(r'(?m)^\s*commit_attribution\s*=\s*("(?:[^"\\]|\\.)*"|\'[^\']*\'|[^\s#]+)', top) | |
| if not m: return "needs patch" | |
| try: | |
| value = json.loads(m.group(1)) if m.group(1).startswith('"') else m.group(1).strip("'") | |
| except Exception: | |
| value = None | |
| return "disabled" if value == "" else "needs patch" | |
| def patch_codex(path): | |
| import tomllib | |
| text = path.read_text(encoding="utf-8") if path.exists() else "" | |
| if text: | |
| tomllib.loads(text) | |
| # Replace only a top-level key. If absent, insert before the first table. | |
| first_table = re.search(r"(?m)^\s*\[", text) | |
| head_end = first_table.start() if first_table else len(text) | |
| head = text[:head_end] | |
| tail = text[head_end:] | |
| pattern = re.compile(r'(?m)^[ \t]*commit_attribution[ \t]*=.*(?:\n|$)') | |
| if pattern.search(head): | |
| head = pattern.sub('commit_attribution = ""\n', head, count=1) | |
| else: | |
| if head and not head.endswith("\n"): head += "\n" | |
| head += 'commit_attribution = ""\n' | |
| atomic_write(path, head + tail) | |
| # The first three have documented, machine-readable controls. | |
| targets = [ | |
| ("Claude Code", HOME / ".claude" / "settings.json", claude_status, patch_claude, | |
| "Commit trailers, PR attribution text, and session URL"), | |
| ("Codex CLI", Path(os.environ.get("CODEX_HOME", str(HOME / ".codex"))) / "config.toml", | |
| codex_status, patch_codex, "Co-authored-by commit trailer (when codex_git_commit is enabled)"), | |
| ("Cursor Agent CLI", Path(os.environ.get("CURSOR_CONFIG_DIR", str(HOME / ".cursor"))) / "cli-config.json", | |
| cursor_status, patch_cursor, "Made with Cursor commit and PR attribution"), | |
| ] | |
| # Explicitly requested tools without a verified native attribution toggle. | |
| unsupported = [ | |
| ("Hermes Agent", "No documented native commit/PR attribution setting found; do not inject speculative config."), | |
| ("OpenCode", "No documented native commit/PR attribution setting found; do not inject speculative config."), | |
| ("Cursor IDE", "Use Settings → Git & Pull Requests → Commit Attribution / PR Attribution; no verified portable config key."), | |
| ] | |
| section("AGENT ATTRIBUTION · PREFLIGHT") | |
| print(" Read-only inspection. No files will be changed until you approve each patch.") | |
| print() | |
| pending = [] | |
| for name, path, check, patch, scope in targets: | |
| try: | |
| status = check(path) | |
| exists = path.exists() | |
| detail = f"{path} — {scope}" | |
| if status == "disabled": | |
| state(name, "already disabled", GREEN) | |
| else: | |
| state(name, ("file missing; will create" if not exists else "attribution not fully disabled"), YELLOW) | |
| pending.append((name, path, patch, detail)) | |
| except (ValueError, OSError) as e: | |
| state(name, f"cannot inspect safely: {e}", RED) | |
| for name, note in unsupported: | |
| state(name, "manual / unsupported", DIM) | |
| print(f" {note}") | |
| if not pending: | |
| section("RESULT") | |
| print(paint(" All supported configuration targets are already compliant.", GREEN)) | |
| sys.exit(0) | |
| section("APPROVAL") | |
| print(f" {len(pending)} supported target(s) need attention.") | |
| print(" Each approval changes only the named configuration file.") | |
| print(" Backups: <file>.pre-attribution-disable.bak (first backup is preserved).") | |
| changed = 0 | |
| skipped = 0 | |
| failed = 0 | |
| for index, (name, path, patch, detail) in enumerate(pending, 1): | |
| section(f"{index}/{len(pending)} · {name}") | |
| print(f" File {path}") | |
| print(f" Scope {detail.split(' — ', 1)[1]}") | |
| try: | |
| with open("/dev/tty", "r", encoding="utf-8") as tty: | |
| print(" Apply this patch? [y/N] ", end="", flush=True) | |
| answer = tty.readline().strip().lower() | |
| except (OSError, EOFError): | |
| print("\n No interactive terminal available; stopping safely.") | |
| break | |
| if answer not in ("y", "yes"): | |
| state("Skipped", "left unchanged", DIM) | |
| skipped += 1 | |
| continue | |
| try: | |
| # Re-check immediately before writing to avoid overwriting an intervening change. | |
| current = path | |
| if name == "Claude Code": | |
| if claude_status(current) == "disabled": | |
| state("No change", "already compliant", GREEN); continue | |
| elif name == "Codex CLI": | |
| if codex_status(current) == "disabled": | |
| state("No change", "already compliant", GREEN); continue | |
| else: | |
| if cursor_status(current) == "disabled": | |
| state("No change", "already compliant", GREEN); continue | |
| patch(path) | |
| # Validate JSON after serialization; TOML parser is stdlib on Python 3.11+. | |
| if path.suffix == ".json": | |
| read_json(path) | |
| state("Patched", "written and validated", GREEN) | |
| changed += 1 | |
| except Exception as e: | |
| state("Failed", str(e), RED) | |
| failed += 1 | |
| section("SUMMARY") | |
| print(f" {paint(str(changed) + ' patched', GREEN)} · {paint(str(skipped) + ' skipped', DIM)} · {paint(str(failed) + ' failed', RED if failed else DIM)}") | |
| print(" Restart affected agent processes before expecting the new settings to apply.") | |
| print(" Note: this controls supported agent-generated commit/PR attribution; it cannot") | |
| print(" prevent arbitrary model-written text or instructions from adding attribution.") | |
| if failed: | |
| sys.exit(1) | |
| PY |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.