Skip to content

About

pre-commit / prek hook that strips AI coding agent trailers and session links from commits, resets the author and signs

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

pre-commit-deagent

A prek / pre-commit hook that removes the traces AI coding agents leave in your commits, and makes sure the commit is yours and signed.

Coding agents like to sign their work:

feat: add retry to the uploader

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_011CU...

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Claude Code on the web (claude.ai/code) commits as Claude <noreply@anthropic.com> and adds a session trailer:

refactor: split the workspace into crates

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AbCdEfGhJkMnPqRsTuVwXy

Other agents commit with their own identity (--author, git -c user.name=..., GIT_AUTHOR_NAME) or skip signing (--no-gpg-sign). With this hook installed, the first commit above becomes:

feat: add retry to the uploader

The author and committer are your configured git identity, and the commit is signed with your key.

What is detected

Marker Examples
Agent co-author trailers Co-authored-by: with noreply@anthropic.com, codex@openai.com, cursoragent@cursor.com, noreply@aider.chat, Copilot, claude[bot], gemini-code-assist[bot], ...
"Generated with" lines 🤖 Generated with [Claude Code](...), Generated by Cursor, ...
Agent session / task links Claude-Session: https://claude.ai/code/session_..., https://chatgpt.com/codex/tasks/..., https://jules.google.com/task/...
Agent identities author or committer using one of the agent addresses above (check only, fix replaces them with yours)

Agents are recognized by email address, not by name. A human co-author named Claude stays in the message; Signed-off-by and other trailers are left alone.

Hooks

id stage what it does
deagent post-commit Rewrites HEAD locally: strips markers, resets author/committer, signs.
deagent-check pre-push, manual Fails if the commits being pushed carry markers or an agent author/committer.

deagent (post-commit)

After every commit, the hook looks at HEAD and rewrites it if any of these hold:

  • the message contains agent markers,
  • the author or committer differs from your user.name / user.email,
  • the commit is unsigned while user.signingkey is set or commit.gpgsign is true.

Clean commits are left alone and keep their hash.

The hook runs after the commit exists, so it also catches commits made with --no-verify (which skips pre-commit and commit-msg, but not post-commit). Your identity and signing settings are read with the agent's overrides removed: GIT_CONFIG_PARAMETERS (git -c ...), GIT_CONFIG_COUNT/KEY_*/VALUE_* and GIT_AUTHOR_*/GIT_COMMITTER_* are cleared first.

The rewrite uses git commit-tree and git update-ref instead of git commit --amend. Your index and any other staged changes stay as they are, no hooks run again, and the original author and committer timestamps are kept. The old commit stays reachable in git reflog as deagent: rewrite agent commit.

The hook does not rewrite, and reports instead, when:

  • CI is set,
  • a rebase or cherry-pick is in progress,
  • the message would be empty after stripping the markers.

deagent-check (pre-push / CI)

Checks the commits in a range and exits with 1 if any of them has markers or an agent author/committer. The range is, in order of precedence:

  1. the <rev-range> argument (pre-commit-deagent check origin/main..HEAD),
  2. PRE_COMMIT_FROM_REF..PRE_COMMIT_TO_REF as set by prek on pre-push or with --from-ref/--to-ref. For a new branch it checks commits not on any remote.
  3. HEAD only.

Installation

Add the hooks to your .pre-commit-config.yaml. post-commit must be in default_install_hook_types, or deagent never fires.

default_install_hook_types: [pre-commit, post-commit, pre-push]

repos:
  - repo: https://github.com/sunsided/pre-commit-deagent
    rev: v0.1.1
    hooks:
      - id: deagent
      - id: deagent-check

Then install the git hooks:

prek install

The hooks use language: rust, so prek builds the binary with cargo on first use.

If your config already lists other hook types, add post-commit to it, or install the hook explicitly with prek install -t post-commit.

Signing

deagent signs with whatever git is configured to use (gpg.format, user.signingkey). Signing counts as configured when user.signingkey is set or commit.gpgsign is true. Otherwise the rewritten commit is unsigned, and any signature the agent added is dropped. Example for SSH signing:

git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/id_ed25519.pub
git config --global commit.gpgsign true

If signing fails (e.g. a locked key and no agent), HEAD is left untouched and the hook prints the error.

CI

Run the check over the commits of a pull request:

prek run deagent-check --hook-stage manual --from-ref origin/main --to-ref HEAD

or install the binary and call it directly:

cargo install --git https://github.com/sunsided/pre-commit-deagent
pre-commit-deagent check origin/main..HEAD

Command line

pre-commit-deagent [fix]                 rewrite HEAD (what the post-commit hook runs)
pre-commit-deagent check [<rev-range>]   report offending commits, exit 1 if any

Exit codes: 0 ok, 1 markers found (or not rewritten), 2 error.

Caveats

  • git commit prints the hash of the commit before the rewrite. The hook prints rewrote HEAD <old> -> <new>.
  • An identity an agent writes into the repository's .git/config cannot be told apart from yours.
  • author.* / committer.* config is not taken into account; only user.name and user.email are.
  • Commits created during a rebase or cherry-pick are not rewritten, and check does not flag unsigned commits.
  • If you already pushed the original commit, the rewritten one diverges from it.

License

Licensed under the European Union Public Licence v. 1.2 (EUPL-1.2).

About

pre-commit / prek hook that strips AI coding agent trailers and session links from commits, resets the author and signs

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages