To sort Gmail with AI, I run an n8n workflow every hour. It reads the sender, subject and preview of each new email, asks Claude Haiku which of my seven labels it belongs in, adds that label, and takes the email out of my inbox. Nothing gets deleted. When I only have a few minutes, I open the three labels I care about and let the rest wait. A generator below builds yours around your own labels.

One long line of email
My inbox used to be one long line. Everything landed in the same place, brand pitches next to coupon blasts next to password resets, and I’d scroll it trying to spot the stuff that mattered. It was overwhelming AF. My eyes would cross.
My mail has its own tricky mix, too. A brand asking me to film a video for the Amazon Influencer Program looks a lot like a brand trying to sell me something, and one of those I want to see today while the other can sit for a week.
Now it works like a filing system. Every new email gets a label and leaves the inbox, and when I’ve only got a few minutes, I hit the labels that matter and skip the rest. For me that’s Admin, Amazon Pitch and Affiliate, right away. Everything else can wait.
Between September 21 and 26, the sorter handled 1,317 new emails across 118 hourly runs, and not one run failed. Only 179 of those emails landed in my three open-first labels. That’s about one email in seven. The other six are still there when I want them, I just don’t have to look at them to find the one that matters.
What does a Gmail AI sorter do?
It gives every new email exactly one label and takes it out of your inbox. Mine has seven labels, and the table shows where five days of mail actually went.
| Label | When I open it | Emails, Sept 21 to 26 |
|---|---|---|
| Admin | Right away | 142 |
| Amazon Pitch | Right away | 12 |
| Affiliate | Right away | 25 |
| Marketing | Whenever | 788 |
| Reading | Whenever | 263 |
| Receipts | Whenever | 45 |
| Sweepstakes | Whenever | 36 |
| Left in the inbox | Next check | 6 |
Marketing alone was 788 emails, 60 percent of everything. That’s the pile I used to scroll past to find a brand pitch.
The six left in the inbox are the ones where the call to the AI failed. The workflow is built so a failed call leaves the email alone instead of guessing, so those six just sat in the inbox until I saw them. I’d rather have six stragglers than one important email filed under Marketing.
Who is a Gmail AI sorter for?
It’s for you if your inbox mixes a few emails you need to act on with a lot you’ll read eventually, and you already know which is which. The labels only help if some of them are “open first” and some are “can wait.”
Skip it if:
- You get a handful of emails a day. Gmail’s own filters or tabs will do fine, and they’re free.
- Your mail sorts cleanly by sender. If every bill comes from the same three addresses, a plain Gmail filter handles it without any AI.
- You want every email answered. This files. It doesn’t reply, summarize or decide what’s urgent inside a label.
- You don’t want your mail passing through an AI. Mine only sends the sender, subject and the short preview, not the whole email, but it still leaves Gmail to get sorted.
What do you need to build a Gmail AI sorter?
- n8n. Where the workflow runs. Mine is self-hosted, and n8n Cloud works too. If the words node and trigger are new, the n8n vocabulary guide covers them.
- A Gmail account connected to n8n. The workflow needs permission to read new mail and change labels.
- An AI API key. I use Claude Haiku 4.5 through Anthropic’s API. It’s pay as you go, separate from any chat subscription. OpenAI works the same way.
- Your labels, created in Gmail first. n8n can only apply a label that already exists.
For cost, Anthropic lists Haiku 4.5 at $1 per million input tokens and $5 per million output tokens on its pricing page. My 1,311 calls over those five days added up to about $1.67, roughly an eighth of a cent per email.

How does a Gmail AI sorter work?
Every hour, n8n checks Gmail for new mail and runs each email through the same short line of steps:
- Gmail Trigger. Pulls in the new emails since the last check, with the sender, subject and a short preview of each.
- Build the request. A Code node packs those three fields together with my sorting instructions.
- Ask the AI. An HTTP Request node sends it to Claude Haiku. It’s set to keep going if the call fails, so one bad call doesn’t stop the batch.
- Read the answer. Another Code node pulls the label out of the reply. If the reply is missing or unreadable, the email gets no label and stays put.
- Route by label. A Switch node sends each email down the branch for its label.
- Add the label, then archive. Two Gmail nodes per branch. One adds the label, the next removes it from the inbox.
The sorting instructions are the part worth your time. Each label gets a one-line description of what belongs in it, and a few tie-breakers for the ones the AI mixes up. Mine says an email only counts as an Amazon pitch if it mentions the Amazon Influencer Program, shoppable video or a storefront, and a brand blast that isn’t about a video collab is Marketing.
The bug that archived the wrong emails
For a while, my sorter archived the wrong emails, and I have no idea how long it was doing it before I caught it.
Step 6 needs to know which email it’s working on. My archive steps asked for the email id with $node["Gmail Trigger"].json.id, which looks right and isn’t. That form grabs an email by its position in the hourly batch, not by which email is going down that branch. So when 12 marketing emails came through, the workflow labeled the right 12 and then took the first 12 emails of the whole batch out of the inbox. Two of those were daily emails I actually wanted to see. Four real marketing emails stayed behind.
The fix was one expression, {{ $json.id }}, which reads the id of the email actually passing through that step:
| Expression in the archive step | What it archives |
|---|---|
$node["Gmail Trigger"].json.id | Whichever email sat in the same position in the batch |
{{ $json.id }} | The email going down that branch |
I fixed it on September 10, and the same day I changed every label to leave the inbox. Before that, only Marketing and Reading archived anything, so the other five labels were sticky notes on mail that never left. The generator bakes the right expression in, so yours starts out fixed.
Get the generator
The generator asks what labels you want and what goes in each one, which ones you’d open with five minutes to spare, what should happen when the AI isn’t sure, how often to sort, which AI you have a key for, and whether you click in n8n or build with Claude Code. Then it writes a prompt you can paste into Claude or ChatGPT to walk you through the build one step at a time, a skill for Claude Code, or both.
It puts your open-first labels at the top of the sorting instructions so a close call leans toward the mail you care about, asks the AI for one word instead of a paragraph, and uses the fixed id expression. Paste the prompt into a chat, or save the skill as SKILL.md in its own folder under ~/.claude/skills/.
What it doesn’t do
It isn’t perfect. Every so often something lands in the wrong label. So far nothing has been badly mislabeled, and since nothing gets deleted, a wrong label is a quick drag to fix.
It doesn’t sort old mail. It only sees email that arrives after it’s switched on. My old inbox needed its own one-time cleanup.
It doesn’t empty the labels for me. I’ve started moving the emails I want to hang onto into a Keep label by hand, so the other labels can get back to zero. The sorter never touches Keep. The generator asks if you want one too.
And mine pays for words it never uses. My sorting instructions still ask the AI for a priority score, a short analysis and a suggested reply for every email, and nothing in the workflow uses any of them. Over those five days the replies averaged 131 tokens per email, and the output side came to about $0.86 of the $1.67, more than everything I sent in. The generator only asks for the label, which is all the sorting needs.
It also won’t tell me if it stops running. My n8n error workflow emails me if a run fails, and a sorter is a good thing to point at one.

Frequently asked questions
Can AI sort my Gmail into labels automatically?
Yes. An n8n workflow can check Gmail on a schedule, ask an AI model which label each new email belongs in, then add that label and remove the email from the inbox. Gmail’s built-in filters can’t do this, because they match on fixed words and senders rather than reading what the email is about.
How much does it cost to sort Gmail with AI?
Mine costs about an eighth of a cent per email. My 1,311 calls to Claude Haiku 4.5 over five days came to about $1.67, at Anthropic’s listed $1 per million input tokens and $5 per million output tokens. Asking only for the label, with no summary or reply, keeps it lower.
Does the AI read my whole email?
Not in my setup. It sends the sender, the subject line and Gmail’s short preview of the message, not the full body. That’s enough to sort most mail, and it’s cheaper and keeps less of your email leaving Gmail.
What happens if the AI picks the wrong label?
The email lands in the wrong label and you move it. Nothing gets deleted, only labeled and archived. If one label keeps catching the wrong mail, rewrite its one-line description in the sorting instructions to be more specific.
Why did my n8n Gmail workflow archive the wrong emails?
The archive step is most likely reading the email id with $node["Gmail Trigger"].json.id, which picks an email by its position in the batch. Use {{ $json.id }} instead, so each step works on the email going down that branch.
How often should an AI email sorter run?
Every hour works for me. Mail waits in the inbox until the next check, so pick how long you’re fine with it sitting there. Every 15 minutes means more runs, but the AI cost stays about the same, because you pay per email, not per run.
Try it yourself
A Gmail AI sorter is a scheduled Gmail Trigger, one short AI call per email, and a label plus archive step for each label, and it turns one long line of email into a few labels you can check in five minutes.
Start with the generator above and keep it to a handful of labels, with two or three marked open first. Test it on one email before you switch it on. Then point it at an error workflow so you hear about it if it stops. If you’re wondering whether all of this saves time or just adds more to watch, I wrote about that in does automation save time.
A tool I built
Porch Pile
Track your whole Amazon Influencer operation, every product, video, and brand deal, so one glance tells you what to film next.
Start your pile →I run an affiliate program on the tools I build. Approved affiliates earn 20% on what their referrals pay, for up to a year. US only for now. See the program →
Related reading
- n8n Error Workflow: How I Stop Finding Out Days Later
- n8n Schedule Trigger Not Working? Mine Never Ran for 7 Weeks
- The n8n Vocabulary Guide for People Who Are Not Developers
Subscribe if you haven’t already. I’ve got more of my own workflows to walk through, and they’re coming. Go forth and automate the boring stuff.
