Metadata-Version: 2.5
Name: cleanmsg
Version: 0.1.1
Summary: Remove AI attribution lines (Co-Authored-By: Claude, Copilot, Cursor...) or any text from git commit messages, safely.
Project-URL: Homepage, https://github.com/enikakis/cleanmsg
Project-URL: Issues, https://github.com/enikakis/cleanmsg/issues
Author: enikakis
License-Expression: MIT
License-File: LICENSE
Keywords: ai,claude,cli,co-authored-by,commit-message,copilot,git,rewrite-history
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Version Control :: Git
Requires-Python: >=3.10
Provides-Extra: fast
Requires-Dist: git-filter-repo; extra == 'fast'
Description-Content-Type: text/markdown

# cleanmsg

**Remove AI attribution lines, or any text, from your git commit messages. Safely.**

AI coding tools like to sign their work. After a while your history looks like this:

```
Add login form

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

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

Whether you keep those lines is your call (some projects require them). If you
don't want them, `cleanmsg` strips them out of existing commits: it shows you what
will change first, keeps a backup, and can force-push the result to GitHub.

It works for any text, too: `WIP`, `[skip ci]`, a ticket number, a typo you
repeated in 40 commits.

## Example

```console
$ cleanmsg --ai
3 commit message(s) to change in branch 'main':
  88912d10  Add password reset flow
            - 🤖 Generated with [Claude Code](https://claude.com/claude-code)
            - Co-Authored-By: Claude <noreply@anthropic.com>
  d4de968e  Validate e-mail on submit
            - Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
  52744c5d  Add login form
            - 🤖 Generated with [Claude Code](https://claude.com/claude-code)
            - Co-Authored-By: Claude <noreply@anthropic.com>

Preview only, nothing changed. Add --apply to rewrite (and --push to update GitHub).

$ cleanmsg --ai --apply --push
...
Rewrite and force-push branch 'main'? [y/N] y
Rewriting with git filter-repo...
Done. Backup saved as 20261127-135715 (undo with: cleanmsg --undo)
Force-pushing main -> origin/main
```

Afterwards the commit reads just:

```
Add login form
```

Removing your own text works the same way:

```console
$ cleanmsg "my change"
1 commit message(s) to change in branch 'main':
  169560e2  fix login my change
            - fix login my change
            + fix login
```

## Install

```bash
pipx install "cleanmsg[fast]"      # or: uv tool install "cleanmsg[fast]"
```

`[fast]` also installs [git-filter-repo](https://github.com/newren/git-filter-repo),
which makes rewriting large repos much faster. Without it, `cleanmsg` falls back to
the `git filter-branch` command that ships with git. Both give the same result.

Needs Python 3.10+ and git. It installs both a `cleanmsg` command and `git cleanmsg`.

From source:

```bash
git clone https://github.com/enikakis/cleanmsg && cd cleanmsg
pipx install ".[fast]"
```

## Usage

Run it inside a repository. **Nothing is changed unless you pass `--apply`.**

```bash
cleanmsg --ai                          # preview: which AI lines would go
cleanmsg --ai --apply                  # rewrite the current branch locally
cleanmsg --ai --apply --push           # ... and force-push to GitHub
cleanmsg "WIP" --last 5 --apply        # only the last 5 commits
cleanmsg -e "[skip ci]" -e "fixup" --unpushed --apply
cleanmsg -E 'JIRA-\d+' --apply         # regular expression
cleanmsg --undo                        # put the old history back
```

### What to remove

| Option | |
|---|---|
| `TEXT` / `-e TEXT` | text to remove; give as many as you like |
| `--ai` | AI attribution lines (see below) |
| `-E`, `--regex` | treat TEXT as a regular expression, matched per line |
| `-i`, `--ignore-case` | match regardless of case |

A line that only contained the removed text is deleted entirely. Leftover
double spaces are collapsed. If a message would end up empty, it is left as is.
Messages without a match are not touched, so those commits keep their hash.

### Which commits

| Option | |
|---|---|
| *(default)* | the whole current branch |
| `--last N` | only the last N commits |
| `--unpushed` | only commits that aren't on the upstream branch yet (no force-push needed) |
| `--all` | every local branch and tag |

### Actions

| Option | |
|---|---|
| `--apply` | actually rewrite (otherwise: preview only) |
| `--push` | force-push the rewritten branches (and tags) to their remote |
| `-y` | don't ask for confirmation |
| `-v` | list every affected commit (the preview shows the first 20) |
| `-C PATH` | run on another repository |

### What `--ai` removes

Whole lines like these (case-insensitive):

```
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: aider (gpt-4o) <noreply@aider.chat>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Generated by GitHub Copilot
```

Also Codex, ChatGPT, Gemini, Devin, Windsurf, Codeium, Amazon Q, Jules, Junie, Cline,
Roo Code and opencode. Human co-authors (`Co-authored-by: Jane <jane@example.com>`)
are kept.

Some tools share a name with real people (Claude, Devin, Jules, Gemini, Junie). For
those, the name alone is not enough: the line is only removed when it is clearly the
tool, for example `Claude Opus 4.5`, `Devin AI`, a `noreply@anthropic.com` address or
a `[bot]` address. So `Co-authored-by: Devin Smith <devin@example.com>` is kept.

Run `cleanmsg --show-ai-patterns` for the exact regular expressions.
Missing a tool? Open an issue or PR.

## Safety

Rewriting history is the scary part, so `cleanmsg` is careful about it:

- **Preview by default.** You see every line that will go before anything happens.
- **Confirmation** before rewriting or pushing (skip with `-y`).
- **Backups.** Before every rewrite the old branches and tags are saved under
  `refs/cleanmsg-backup/<time>/`. `cleanmsg --undo` restores the latest one
  (`--undo --push` restores GitHub too). See them with `--list-backups` and delete
  them with `--drop-backups`.
- **`--force-with-lease`** instead of a plain force-push: if someone pushed in the
  meantime, the push is refused instead of overwriting their work.
- **GitHub checks.** If the [`gh`](https://cli.github.com) CLI is installed and logged
  in, `cleanmsg` warns you before pushing to a **protected branch** or a branch with
  **open pull requests** (turn off with `--no-github-checks`).
- Refuses to run with uncommitted changes.

### Things to know

- Changing a commit message changes that commit's hash **and the hash of every
  commit after it**. That is why a force-push is needed, and why anyone else with a
  clone needs to reset to the new history (`git fetch && git reset --hard origin/main`).
  It's best on your own repos or branches.
- Rewritten commits lose their GPG/SSH **signatures**.
- **This is not a way to scrub secrets.** GitHub can keep old commits reachable by
  their hash, and pull requests keep their own copies. If you committed a password or
  key, rotate it, and follow GitHub's guide to
  [removing sensitive data](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository).

## How it works

`cleanmsg` reads the messages with `git log` to build the preview. When you apply,
it hands the same cleaning function to `git filter-repo` (if installed) or
`git filter-branch`, limited to the commits you chose. Authors, dates and file
contents stay exactly the same; only the messages change.

## Development

```bash
python -m pip install pytest git-filter-repo
python -m pytest            # runs the end-to-end tests with both engines
./bin/cleanmsg --help       # run from the checkout without installing
```

## License

[MIT](LICENSE)
