Delete years of Gmail clutter in minutes. Free, open-source. Core features need no API key.
π€― 495 emails deleted Β· 87.4 MB freed in 8s using mailtrim π₯ 34% of your inbox is clutter β caused by just 3 senders.
mailtrim is a CLI tool that finds inbox clutter, ranks it by impact, and bulk-deletes it safely β with a 30-day undo window.
Core workflow (stats, purge, undo) is fully local β no API key required, nothing sent anywhere. Optional AI commands (triage, bulk, avoid, digest, rules --add) send only email subjects and 300-character snippets to Anthropic for classification β never full body content. See Anthropic's privacy policy for how API data is handled on their side.
No subscription. No black box.
The paid tools charge $7β$40/month, process your email on their servers, and still don't solve the problems that matter most:
| Problem | SaneBox / Superhuman | mailtrim |
|---|---|---|
| "Remind me only if they haven't replied" | β Not solved | β Conditional follow-up |
| Why did AI move this email? | β Black box | β One-line explanation per email |
| Natural language bulk cleanup | β Not solved | β "Archive newsletters older than 60 days" |
| 30-day undo for bulk operations | β Not solved | β Full undo log |
| "Emails I keep avoiding" detection | β Not solved | β AI insight per avoided email |
| Unsubscribe success rate | 70β85% | β Near-100% (headless browser fallback) |
| Privacy β core commands local | β Cloud-processed | β Core: local only. AI commands: subjects/snippets to Anthropic |
| Cost | $7β$40/month | Free |
- All data stays in
~/.mailtrim/β no external servers, no telemetry, no analytics - OAuth token is written
chmod 0o600(owner read-only) - AI features send only email subjects and snippets to Anthropic β never full body content. See Anthropic's privacy policy for their data handling.
- No AI key? β everything except
triage,bulk,avoid,digest, andrules --addworks without one - Why
gmail.modifyscope? This grants read, compose, trash, and label access β mailtrim uses it to list messages, move mail to Trash, and manage labels. The scope technically permits reading full body content; mailtrim fetches metadata only and never reads or stores body text. - Why
gmail.sendscope? Thefollow-upcommand creates reminder drafts. It is never called bystats,purge,triage,bulk,undo, or any cleanup command. If you don't usefollow-up, this permission is never exercised. - Revoking access: Go to myaccount.google.com/permissions and remove mailtrim. Delete
~/.mailtrim/token.jsonlocally to complete the removal. - See PRIVACY.md for the full data flow
| Feature | Commands | Cost |
|---|---|---|
| Inbox analysis + bulk delete | stats, purge, undo, sync, unsubscribe, follow-up, rules --run |
Free β no API key needed |
| AI classification + NL cleanup | triage, bulk, avoid, digest, rules --add |
Requires Anthropic API key Β· ~$0.01β0.05 per run |
The core cleanup workflow β scan, rank, delete, undo β costs nothing and requires no AI key. AI features are optional and pay-per-use; there is no subscription.
git clone https://github.com/sadhgurutech/mailtrim
cd mailtrim
python3 -m venv venv && source venv/bin/activate
pip install -e .
# Optional: headless browser for near-100% unsubscribe success
pip install -e ".[headless]" && playwright install chromiumThis is a standard OAuth setup β you're authorising yourself to access your own inbox. Google never charges for this. You only do this once; after that, mailtrim auth refreshes your token automatically.
Stuck? The OAuth consent screen step trips up most people. When asked for "User type", choose External. Under "Test users", add your own Gmail address. That's it β you don't need to publish the app.
- Go to console.cloud.google.com β New project
- APIs & Services β Enable APIs β search Gmail API β Enable
- OAuth consent screen β External β add your Gmail as a test user
- Credentials β Create β OAuth 2.0 Client ID β Desktop app β Download JSON
- Save it:
mv ~/Downloads/client_secret_*.json ~/.mailtrim/credentials.json
Scopes requested:
gmail.modify(read, trash, label management) andgmail.send(follow-up drafts).gmail.modifygrants the capability to read body content β mailtrim never does, but you should know the scope allows it.
"This app isn't verified" warning: Google shows this for any OAuth app that hasn't gone through their review process. It is expected and safe to proceed β you are authorising your own app to access your own inbox. Click Advanced β Go to mailtrim (unsafe) to continue.
mailtrim auth
# Opens browser β click Allow β donemailtrim statsSample output (illustrative β your numbers will vary):
Scan complete β 2,000 emails Β· 38 senders
34% of your inbox is clutter β caused by just 3 senders. 87.4 MB gone in one command.
TOTAL RECLAIMABLE SPACE
You can safely free ~87.4 MB (34.0% of scanned inbox)
from your top 3 senders Β· Each cleanup takes ~3-5s
All deletions go to Trash β undo anytime
# Impact Sender Emails Size Oldest Risk
1 100 (High) LinkedIn Jobs 312 44.0MB 847d ago Safe to clean
2 82 (High) Substack Weekly 183 26.1MB 512d ago Safe to clean
3 51 (Medium) GitHub Notifications 147 9.3MB 91d ago Low risk
4 29 (Low) Shopify 94 12.2MB 203d ago Safe to clean
5 18 (Low) Medium Daily Digest 87 11.4MB 445d ago Safe to clean
Impact = 60% storage + 40% volume (0-100)
mailtrim purgeSample output (illustrative):
Top Email Offenders (823 emails Β· 102.3 MB)
# β Sender β Emails β Size β Latest β Sample subject
ββββΌββββββββββββββββββββββββββββββΌβββββββββΌββββββββΌββββββββββΌβββββββββββββββββββββββββββββ
1 β LinkedIn Jobs <jobs@li...> β 312 β 44MB β Apr 03 β 12 new jobs matching your...
2 β Substack <hello@subst...> β 183 β 26MB β Apr 01 β This week: AI is eating...
3 β GitHub <noreply@github...> β 147 β 9MB β Apr 04 β [myrepo] New issue opened...
Select senders to delete.
Enter numbers (1,3), ranges (1-5), all, or q to quit.
Your selection: 1,2
Selected 2 senders β 495 emails (70 MB):
β LinkedIn Jobs (312 emails)
β Substack (183 emails)
Move 495 emails to Trash? (undo available for 30 days) [y/N]: y
β Moved 495 emails to Trash. Undo log ID: 1 (mailtrim undo 1)
mailtrim stats --shareThe command outputs the following text, ready to copy and paste:
π€― 495 emails deleted Β· 87.4 MB freed in 8s using mailtrim
β’ 3 senders responsible
β’ Core cleanup runs locally β no API key needed
β’ My inbox was 34% clutter β now it's clean
β’ ~41 min of reading time reclaimed
Free forever. β https://github.com/sadhgurutech/mailtrim
mailtrim stats
mailtrim stats --json # machine-readable outputHow the Risk/Confidence score works:
Three signals combine to estimate how safe bulk-deletion is (0β100):
| Signal | Weight | Logic |
|---|---|---|
List-Unsubscribe header present |
30 pts | Sender self-identifies as bulk/marketing |
| Age β₯ 180 days in inbox | up to 35 pts | Emails sitting >6 months are rarely actionable |
| Volume β₯ 50 from one sender | up to 35 pts | High frequency = almost certainly automated |
π’ β₯70 = Safe to clean Β· π‘ 40β69 = Low risk Β· π΄ <40 = Review first
Scores are heuristics β the 30-day undo exists precisely because no heuristic is perfect.
mailtrim purge # sort by email count (default)
mailtrim purge --sort oldest # show oldest clutter first
mailtrim purge --sort size # largest senders first
mailtrim purge --query "older_than:1y" # custom query
mailtrim purge --unsub # also unsubscribe while deleting
mailtrim purge --permanent # skip Trash β IRREVERSIBLE
mailtrim purge --json # output sender list as JSONmailtrim sync # last 200 messages
mailtrim sync --limit 500
mailtrim sync --query "in:inbox is:unread"mailtrim triage # classify unread inbox
mailtrim triage --limit 50Every email gets: priority (high/medium/low) Β· category Β· why Β· suggested action
mailtrim bulk "archive all newsletters I haven't opened in 60 days"
mailtrim bulk "delete all emails from noreply@* older than 1 year"
mailtrim bulk "label receipts from order@ or receipt@ senders"
mailtrim bulk "archive LinkedIn notifications" --dry-run # preview firstmailtrim undo # list recent operations
mailtrim undo 42 # undo operation #42mailtrim follow-up <message-id> --days 3 # remind only if no reply in 3 days
mailtrim follow-up --list # see what's due today
mailtrim follow-up --sync # check threads for repliesmailtrim avoid # show with AI insight
mailtrim avoid --no-insights # faster, no AI
mailtrim avoid --process <id> --action archivemailtrim unsubscribe newsletters@company.com
mailtrim unsubscribe --from-query "label:newsletters" --limit 20
mailtrim unsubscribe --historymailtrim rules --add "archive LinkedIn notifications older than 7 days"
mailtrim rules --list
mailtrim rules --run
mailtrim rules --run --dry-runmailtrim digestAll settings via environment variables or ~/.mailtrim/.env:
| Variable | Default | Description |
|---|---|---|
ANTHROPIC_API_KEY |
(not set) | Anthropic API key. Without it, mock AI mode is used. |
MAILTRIM_AI_MODEL |
claude-sonnet-4-6 |
Claude model for AI features |
MAILTRIM_DRY_RUN |
false |
Global dry-run (preview without executing) |
MAILTRIM_UNDO_WINDOW_DAYS |
30 |
How long undo logs are kept |
MAILTRIM_AVOIDANCE_VIEW_THRESHOLD |
3 |
Views before an email is "avoided" |
MAILTRIM_FOLLOW_UP_DEFAULT_DAYS |
3 |
Default follow-up window |
MAILTRIM_DIR |
~/.mailtrim |
Where tokens, DB, and config are stored |
~/.mailtrim/.env example:
ANTHROPIC_API_KEY=sk-ant-...
MAILTRIM_DRY_RUN=false
MAILTRIM_UNDO_WINDOW_DAYS=30
Security note: Restrict permissions on this file β
chmod 600 ~/.mailtrim/.envβ so only your user account can read the API key.
# Run all 115 tests β zero API calls, zero credentials needed
python -m pytest tests/ -v
# With coverage
python -m pytest tests/ --cov=mailtrim --cov-report=term-missingAll AI paths are covered by MockAIEngine β the full CLI can be exercised without any API key.
See CONTRIBUTING.md. Bug reports and feature requests welcome via GitHub Issues.
mailtrim/
βββ config.py # Settings (env vars, ~/.mailtrim/.env)
βββ core/
β βββ gmail_client.py # Gmail API: OAuth, CRUD, batching, retry on 429/5xx
β βββ storage.py # Local SQLite: emails, follow-ups, rules, undo log
β βββ ai_engine.py # Claude API: classify, NLβquery, digest, avoidance
β βββ mock_ai.py # Deterministic stub β full testing without API key
β βββ follow_up.py # Conditional follow-up: only surfaces if no reply
β βββ bulk_engine.py # NL β dry-run preview β execute β 30-day undo
β βββ avoidance.py # "Emails you avoid" detector + per-email AI insight
β βββ unsubscribe.py # RFC 8058 one-click + mailto + Playwright headless
β βββ sender_stats.py # Sender aggregation for stats/purge commands
βββ cli/main.py # Typer + Rich CLI β 11 commands
MIT β free to use, modify, and distribute.