Promotional email is harmless one at a time and a mess by the thousand. Gmail can’t delete mail by age with a normal filter, but a short script can, and it only takes ten minutes to set up once.
Preview what will be cleared
In Gmail's search box, paste:
category:promotions older_than:30d -is:starred -is:importantThese are the emails the bot will move to the bin. Starred and important ones are skipped. If something you want to keep shows up, star it.
Start a new script
Go to script.google.com, click New project and name it Inbox cleanup.
Paste the script
Replace everything in the editor with this. Change
30if you want to keep promotions for longer:const DAYS = 30; function cleanPromotions() { const query = 'category:promotions older_than:' + DAYS + 'd -is:starred -is:important'; for (let round = 0; round < 10; round++) { const threads = GmailApp.search(query, 0, 100); if (threads.length === 0) return; GmailApp.moveThreadsToTrash(threads); } }Run it once and allow access
Click Run and allow access to Gmail. Each run clears up to 1,000 conversations, so a big backlog may take a few nights.
Run it every night
Open Triggers, click Add trigger, choose
cleanPromotions, Time-driven, Day timer, Midnight to 1 am, and save.
Paste this into Claude Code, Codex or any coding agent. The agent writes and sets up the automation, then tells you what to click.
Write a Google Apps Script that tidies my Gmail every night. - Move conversations in the Promotions category older than 30 days to the bin, skipping starred and important ones. - Also do the same for the Social category, but after 14 days. - Never touch anything from senders on a KEEP list I can edit at the top of the script. - Process at most 1,000 conversations per run so it stays inside Apps Script's time limit, and send me a one-line weekly email saying how many it cleared. - Add a nightly trigger, and tell me where to paste it on script.google.com and what to click.
You still need to
- Sign in to Google and click Allow when the script first runs.
Things that trip people up
- The Promotions tab only exists if Gmail's inbox categories are on. Without it, the search finds nothing.
- Emails stay in the bin for 30 days before Gmail deletes them for good, so you can still rescue one.