AI-powered (or heuristic) Gmail inbox cleanup CLI
Project description
gmail-cleanup
Gmail inbox cleanup — one command, with or without AI. Works standalone via aggressive heuristic rules, or with Claude Code for smart AI-driven analysis.
One-shot deletion of junk mail — no manual filters, no dragging emails to trash one by one.
Demo GIF is generated from docs/demo.tape via VHS — brew install vhs && vhs docs/demo.tape. The simulation is scripted (docs/demo.sh) so no real Gmail account is needed to re-render it.
Install
Recommended — pipx (one-shot, no clone):
pipx install gmail-cleanup-cli
# or from git directly: pipx install git+https://github.com/twok020101/gmail-cleanup.git
gmail-cleanup --auto # preview an aggressive cleanup plan
gmail-cleanup --auto --execute # actually run it
gmail-cleanup --auto --execute --limit 500
gmail-cleanup --undo # restore the most recent run
You'll still need a credentials.json in the current directory on first run — see Google Cloud credentials guide below. Run gmail-cleanup from whichever folder holds your credentials.
Without pipx — clone and run (original flow): See Setup below.
How it works
Two modes:
- Heuristic mode (no AI):
gmail-cleanup --auto→ rules-based plan (Promotions, Social 14d+, Updates 30d+, Spam, no-reply 90d+, job platforms 60d+) → execute. - AI mode (with Claude Code): Claude scans your inbox via Gmail MCP → generates a smarter plan → execute.
AI mode flow:
Gmail MCP (read-only) cleanup.py (delete access)
│ │
▼ ▼
Claude analyzes ──► generates plan ──► executes deletion
your inbox (JSON queries) via Gmail API
- Claude scans your inbox using the Gmail MCP (read-only)
- Categorizes every sender: spam, newsletter, transactional, important
- Shows you the plan and asks for confirmation
- Runs
cleanup.pywhich trashes matching emails via Gmail API
Requirements
- Python 3.9+ (python.org/downloads)
- A Google account
- Claude Code (optional — only needed for AI-driven analysis mode)
Platform support
| Platform | Status |
|---|---|
| macOS | Tested |
| Linux (Ubuntu, Fedora, etc.) | Supported |
| Windows (Git Bash / WSL) | Supported |
| Windows (PowerShell) | Supported via manual setup |
Setup (one-time, ~5 min)
1. Clone this repo
git clone https://github.com/YOUR_USER/gmail-cleanup.git
cd gmail-cleanup
2. Install Python (if not already installed)
macOS:
brew install python
Ubuntu/Debian:
sudo apt install python3 python3-venv python3-pip
Fedora:
sudo dnf install python3
Windows: Download from python.org/downloads and check "Add to PATH" during install.
3. Open in Claude Code and run /gmail-cleanup
claude
Then type /gmail-cleanup. Claude walks you through everything:
- Gmail MCP — Claude checks if it's connected, tells you how to add it if not
- Python setup — runs
bash setup.shautomatically (creates venv, installs deps) - Google credentials — Claude walks you through creating
credentials.jsonstep-by-step (one-time, ~3 min) - First auth — script opens your browser for Google login, approve once, token is cached
Why do I need credentials.json? The Gmail MCP gives Claude read-only access. To actually delete emails, the script needs
gmail.modifypermission via your own Google OAuth credentials. Google requires each user to authorize this themselves — there's no way around it. Your credentials stay on your machine and are gitignored. Seecredentials.json.examplefor the expected format.
Manual setup (no Claude)
If you prefer to set up without Claude:
# Unix/macOS/Linux
bash setup.sh
# Windows (PowerShell)
python -m venv venv
venv\Scripts\pip install -r requirements.txt
Then follow the credentials.json instructions printed by setup.sh, or see the Google Cloud setup guide below.
Usage
Heuristic mode (no AI, no Claude Code needed):
gmail-cleanup --auto # preview aggressive cleanup rules
gmail-cleanup --auto --execute # execute (dry-run is default)
gmail-cleanup --auto --execute --limit 100
gmail-cleanup --undo # restore previous run
AI mode (with Claude Code): Open this folder in Claude Code and say:
clean up my gmail
Or run the skill directly:
/gmail-cleanup
Claude will:
- Scan your inbox using Gmail MCP
- Show a summary of what it found
- Ask what to keep/delete
- Execute the cleanup
Manual usage (without Claude Code)
Write your own plan and run the script directly:
{
"queries": [
{"name": "All Promotions", "query": "category:promotions"},
{"name": "All Spam", "query": "in:spam"},
{"name": "Old GitHub", "query": "before:2026/2/6 from:github.com"}
]
}
# Dry-run is the DEFAULT — shows what would be deleted, touches nothing
venv/bin/python cleanup.py plan.json
# Actually trash the matching messages
venv/bin/python cleanup.py plan.json --execute
# Cap deletions per run (useful for trying things out safely)
venv/bin/python cleanup.py plan.json --execute --limit 50
# Oops — restore everything from the most recent run
venv/bin/python cleanup.py --undo
On Windows, swap venv/bin/python for venv\Scripts\python.
What gets deleted by default
Heuristic mode (--auto):
| Category | Condition |
|---|---|
| Promotions tab | All |
| Social tab | Older than 14 days |
| Updates tab | Older than 30 days |
| Spam | All |
| No-reply senders | Older than 90 days |
| Job platforms | Older than 60 days |
| Unsubscribe-containing emails | Older than 90 days |
| Starred, Important, Sent, Drafts, personal | Never deleted |
AI mode (Claude Code): Claude analyzes your actual inbox and shows you the plan before executing. Bank/payment alerts and transactional emails are typically preserved.
FAQ
Is it safe?
Emails go to Trash, not permanently deleted. You have 30 days to recover anything from Gmail's Trash. On top of that: dry-run is the default — you must pass --execute to delete anything, and --undo restores the most recent run if you change your mind.
Do I need to pay for Claude Code?
No. The --auto heuristic mode runs 100% locally with no LLM cost. Claude Code is optional and only used for the smart AI-analysis mode.
Can Claude delete without asking (AI mode)? No. The skill always shows the cleanup plan and waits for your confirmation before executing.
Does my data leave my machine? In heuristic mode: deletion runs 100% locally using your own Google OAuth credentials. In AI mode: the Gmail MCP reads emails through Claude's MCP connection. No data is sent to any third party beyond Claude's platform (which applies the same privacy rules as any Claude Code session).
Can I run it periodically?
Yes. Heuristic mode: run gmail-cleanup --auto --execute on a cron job or scheduler. AI mode: come back to Claude Code every 2 weeks and run /gmail-cleanup for a fresh analysis.
Google Cloud credentials guide
Step-by-step with screenshots description
Heads up: the "unverified app" screen is expected. The first time you authorize, Google will show a scary-looking "Google hasn't verified this app" warning. This is normal for personal OAuth clients — you created the app yourself, so of course Google hasn't verified it. Click Advanced → Go to <your app name> (unsafe) to continue. You're granting access to your own OAuth client, which only runs on your machine.
- Go to console.cloud.google.com
- Create a new project (any name, e.g. "gmail-cleanup")
- Search "Gmail API" in the top search bar → click Enable
- Go to APIs & Services → OAuth consent screen
- User Type: External → Create
- Fill in app name and your email
- Add scope:
https://www.googleapis.com/auth/gmail.modify - Add your Gmail as a Test User → Save
- Go to APIs & Services → Credentials
- Create Credentials → OAuth client ID
- Application type: Desktop app
- Click Create → Download JSON
- Rename the downloaded file to
credentials.json - Move it into this project folder
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gmail_cleanup_cli-0.1.0.tar.gz.
File metadata
- Download URL: gmail_cleanup_cli-0.1.0.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27faa9f9dd1105a9bf2443b61a13579a3a2f609ef2069648418cd7fe43fe1dbe
|
|
| MD5 |
5f188518f816339b22cc1d8d823d8979
|
|
| BLAKE2b-256 |
3aa9e157452b05f9d3926247ef979a8d591f7c8327ef8d3dc7db2463d68d6f7b
|
Provenance
The following attestation bundles were made for gmail_cleanup_cli-0.1.0.tar.gz:
Publisher:
publish.yml on twok020101/gmail-cleanup
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gmail_cleanup_cli-0.1.0.tar.gz -
Subject digest:
27faa9f9dd1105a9bf2443b61a13579a3a2f609ef2069648418cd7fe43fe1dbe - Sigstore transparency entry: 1256616930
- Sigstore integration time:
-
Permalink:
twok020101/gmail-cleanup@8c4e076441faac319c10c1f7e0f5c20d635a7b1f -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/twok020101
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8c4e076441faac319c10c1f7e0f5c20d635a7b1f -
Trigger Event:
release
-
Statement type:
File details
Details for the file gmail_cleanup_cli-0.1.0-py3-none-any.whl.
File metadata
- Download URL: gmail_cleanup_cli-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e27b50024d04a8f4511f64082559fa7e7645d62336bc990194d37315df2bbdba
|
|
| MD5 |
99e494be44fff64ff62edd8231d357d8
|
|
| BLAKE2b-256 |
5e040a885279170b42d4ff540b1cdb0dd62dbb343dfd57df0994b2786321c08b
|
Provenance
The following attestation bundles were made for gmail_cleanup_cli-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on twok020101/gmail-cleanup
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gmail_cleanup_cli-0.1.0-py3-none-any.whl -
Subject digest:
e27b50024d04a8f4511f64082559fa7e7645d62336bc990194d37315df2bbdba - Sigstore transparency entry: 1256617065
- Sigstore integration time:
-
Permalink:
twok020101/gmail-cleanup@8c4e076441faac319c10c1f7e0f5c20d635a7b1f -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/twok020101
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8c4e076441faac319c10c1f7e0f5c20d635a7b1f -
Trigger Event:
release
-
Statement type: