Gmail Cleaner
name: gmail-cleaner
by cedarscy · published 2026-03-22
$ claw add gh:cedarscy/cedarscy-gmail-cleaner---
name: gmail-cleaner
description: Clean and organize Gmail accounts in bulk. Use when asked to clean Gmail, remove spam, trash newsletters/promotional emails, bulk-delete emails by sender, create labels, set up auto-filters, or restore emails from trash. Handles single or multiple Gmail accounts via OAuth token files. Works with any Gmail account using the Gmail API.
---
# Gmail Cleaner
Bulk Gmail cleanup using the Gmail API. Processes 1000 messages per API call.
Prerequisites
Workflow
1. Auth (first time or new account)
python scripts/auth.py --credentials /path/to/credentials.json --token /path/to/token.pkl --scopes settingsFor a second account, specify a different `--token` path (e.g., `gmail_token_work.pkl`).
2. Scan (identify what to clean)
python scripts/scan.py --token /path/to/token.pkl --sample 500Shows inbox counts by category + top 40 senders. Run this first.
3. Clean (bulk trash/delete)
# Trash specific senders:
python scripts/clean.py --from "spam@example.com,news@example.org"
# Trash by Gmail search query:
python scripts/clean.py --query "category:promotions older_than:30d"
# From a JSON config file (list of {query, label}):
python scripts/clean.py --config senders.json
# Permanently delete instead of trash:
python scripts/clean.py --from "spam@example.com" --delete
# Dry run first:
python scripts/clean.py --from "spam@example.com" --dry-run4. Deep Clean (comprehensive)
# Full deep clean (4 steps: trash promos → archive old → mark read → purge trash):
python scripts/deep_clean.py
# Custom age thresholds:
python scripts/deep_clean.py --promo-days 7 --archive-days 30 --unread-days 14
# Skip trash purge (keep trash for 30-day auto-delete):
python scripts/deep_clean.py --skip-trash-purge5. Organize (labels + filters)
# Apply built-in label set (Business, Banking, Tech, Personal, Trading, Social):
python scripts/organize.py
# Custom labels/rules/filters from JSON:
python scripts/organize.py --config labels.json
# Labels only (no filters):
python scripts/organize.py --skip-filters6. Restore (rescue emails from trash)
# Restore all emails from a sender + apply a label:
python scripts/restore.py --from healthbeat@mail.health.harvard.edu --label "Harvard Health"
# Restore by query:
python scripts/restore.py --query "from:apple.com in:trash" --label "Tech/Apple"Multiple Accounts
Run each script with a different `--token` path per account:
python scripts/scan.py --token ~/.openclaw/workspace/gmail_token_personal.pkl
python scripts/scan.py --token ~/.openclaw/workspace/gmail_token_work.pkl
python scripts/deep_clean.py --token ~/.openclaw/workspace/gmail_token_work.pklCommon Patterns
**Full cleanup for one account:**
python scripts/auth.py --scopes settings
python scripts/scan.py # identify top senders
python scripts/clean.py --from "..." # trash specific senders
python scripts/deep_clean.py # clean categories
python scripts/organize.py # create labels + filters**Rescue important emails caught in bulk delete:**
python scripts/restore.py --from important@example.com --label "Important"**Senders config file format** for `clean.py --config`:
[
{"query": "from:temu@eu.temuemail.com", "label": "Temu"},
{"query": "category:promotions older_than:7d", "label": "Old Promos"}
]Notes
More tools from the same signal band
Order food/drinks (点餐) on an Android device paired as an OpenClaw node. Uses in-app menu and cart; add goods, view cart, submit order (demo, no real payment).
Sign plugins, rotate agent credentials without losing identity, and publicly attest to plugin behavior with verifiable claims and authenticated transfers.
The philosophical layer for AI agents. Maps behavior to Spinoza's 48 affects, calculates persistence scores, and generates geometric self-reports. Give your...