Free ยท Open-source ยท Runs on your machine

Clean the inbox.
Then keep it clean.

A four-part toolkit that clears a cluttered Gmail inbox and builds the rules that keep it clear โ€” as a byproduct of the cleanup itself. It runs entirely on your own machine against your own Google project, works on metadata only, never reads the body of your email, and never permanently deletes anything.

Why most inbox cleanups fail

Clearing the backlog is the easy part. The reason you're back at 5,000 unread a year later is that nobody sets up rules afterward โ€” the cleanup burns the energy you'd need to build the system that prevents the next one.

This toolkit flips that. Every time you tell it "trash everything from this sender," it doesn't just clear the backlog โ€” it also creates a Gmail filter that automatically handles future mail from that sender. One decision, applied backward and forward. The rules aren't a separate chore you'll never get to. They fall out of the work you're already doing.

The four-stage pipeline

Think of it as an assembly line. The first two stages only read โ€” they cannot change anything. The last two can write, but default to a dry run and ask you to confirm before touching a single message.

READS ONLY โ€” CANNOT CHANGE ANYTHING 1 ยท ingest.py Snapshots mailbox metadata, ranks senders builds sender_report.html 2 ยท analyze.py Finds cadences, subject templates, dead senders builds analysis_report.html you review, then write rules WRITES TO GMAIL โ€” DRY RUN BY DEFAULT, ASKS BEFORE LIVE 3 ยท cleanup_basic.py Bulk trash or archive by sender, plus filters whole domains and addresses 4 ยท cleanup_advanced.py Subject and age rules for mixed senders splits junk from keepers, one domain Clean inbox + standing filters Future mail handled automatically Stages 1โ€“2 are safe to run anytime. Stages 3โ€“4 change nothing until you add --execute and type yes.

Before you touch anything

Idea 01

Metadata, not content

It works on the facts about each email โ€” who, what subject, what date โ€” never the body. A privacy win and a speed win: metadata is tiny, so tens of thousands of messages process fast.

Idea 02

Trash โ‰  delete

Cleanup moves mail to Trash (recoverable 30 days) or Archive (kept forever, just out of the inbox). The permanent-delete operation is deliberately never used.

From zero to a cleaner inbox

The path at a glance. The full guide in the repo spells out every click and command, including the one-time Google setup. This is the map.

  1. Set up a free Google Cloud project

    You create your own credential that authorizes this toolkit to access your mailbox. You can't use anyone else's, and no one can use yours โ€” that's the design, and it's what keeps your inbox safe.

    โš 

    Keep credentials.json private โ€” treat it like a password. The included .gitignore blocks it from being committed by accident.

  2. Install Python and the toolkit

    Check you have Python, then install the two libraries the scripts need.

    # check Python (need 3.9+)
    python3 --version

    # install dependencies
    pip3 install -r requirements.txt
  3. Take a read-only snapshot

    Completely safe โ€” it only reads. The first run opens your browser to sign in. When it finishes, open sender_report.html and study it. This report is the thinking part; the scripts are just muscle.

    python3 ingest.py
  4. Build your rules and dry-run

    Edit the RULES block with senders from your report, then run with no flag. A dry run changes nothing โ€” it shows how many messages each rule would affect. Read those counts.

    # dry run โ€” connects to nothing, changes nothing
    python3 cleanup_basic.py
  5. Go live

    When the counts look right, add --execute. It asks you to type yes before anything happens, then cleans up and creates your filters.

    python3 cleanup_basic.py --execute
  6. Tackle the hard cases โ€” and let AI help

    Run analyze.py for the deeper report, then use cleanup_advanced.py for mixed senders. The guide includes a copy-paste prompt that hands your analysis to an AI assistant to draft the advanced rules โ€” you review and approve every one.

    python3 analyze.py
    python3 cleanup_advanced.py # dry run first, then --execute
โœ“

The golden rule: always dry-run and read the counts before any --execute. If a rule you expected to hit thousands shows zero, your pattern is probably mistyped. Nothing replaces your own eyes on the dry-run output.

What each file is for

GUIDE.mdThe complete step-by-step. Start here for every detail.
README.mdQuick orientation and the pipeline at a glance.
ingest.pyStage 1 โ€” read-only metadata snapshot + sender report.
analyze.pyStage 2 โ€” deeper analysis report (local only).
cleanup_basic.pyStage 3 โ€” bulk trash/archive by sender + filters.
cleanup_advanced.pyStage 4 โ€” subject + age rules for mixed senders.
requirements.txtThe two libraries to install.
.gitignoreBlocks secrets, tokens, and your data from being committed.

Get the toolkit

Free and open-source under the MIT license. Clone it, read the guide, clean your inbox.

github.com/courtney-buck/gmail-cleanup-toolkit โ†’