DANGILBERT.AI ← All episodes EP_08 · Template

Show Me Your AI · Episode 08 · Template

AI inbox filter for Gmail.

A Google Apps Script sits on your Gmail, wakes up every five minutes, and asks Claude to classify anything new. Cold pitches and junk get labelled and archived before you see them. Real mail stays put. Fill in the five fields below and the script rewrites itself.

⏱ 30 minutes 💷 Under $1 / month 🔒 Runs in your own Google account

Step 00 · Personalise

0 / 5 filled

Your details.

Nothing here leaves your browser. Typing rewrites the script further down the page, so what you copy is already yours. Leave a field blank and its placeholder stays highlighted in the code so you can spot it later.

Used in the prompt so Claude knows whose inbox it is guarding.
Shapes what counts as relevant. A recruiter's borderline is not a lawyer's.
Appears six times in the prompt. All six get replaced.
Mail from these is always kept. Plain text, list as many as you like.
Comma separated. Include aliases — this is how the script spots your own threads.
Saved in this browser only, so you can come back mid-setup.

How it decides

Four checks, cheapest first.

  1. Thread participation. If you wrote any message in the thread, it is a real conversation. Kept, no AI involved.
  2. Sent history. If you have ever emailed the sender, they are more likely to be legitimate. Kept.
  3. Your learned rules. Allowlisted senders are kept, blocklisted ones are archived. No API call needed.
  4. Claude classification. Everything else goes to Claude with a strict prompt and lands in one of four Gmail labels.
CF/KeptStays in your inbox.
CF/BorderlineArchived, worth a skim.
CF/SalesArchived cold outreach.
CF/SpamArchived junk.

Cost is trivial. A small, fast model classifying 50 to 1,000 cold emails a day comes to well under a dollar a month, and the first three checks never call the API at all.

Before you start

What you need.

A Gmail accountPersonal or Workspace, either is fine.
An Anthropic API keyFrom console.anthropic.com.
30 minutesMost of it is clicking through Google's authorisation screens.

Setup

Six steps.

  1. Create the script

    Go to script.google.com and click New project. Name it something you will recognise, for example "Email Classifier". Delete the stub code in the editor.

  2. Paste your personalised script

    Fill in the five fields above, hit Copy the script, and paste it into the empty editor. Save.

    Worth two extra minutes: read the prompt inside buildClassificationPrompt and adjust it to your job. The BORDERLINE examples were written for someone in media and advertising. Swap them for whatever counts as a maybe in your world.

  3. Create your rules sheet

    In the toolbar dropdown next to Debug, select createRulesSheet and click Run. Google will ask you to authorise the script — approve it. The scopes are Gmail, Sheets, and external requests, and that last one is the Claude API call.

    Open the Execution log. It prints a Sheet ID and URL. Copy the ID.

  4. Set your two Script Properties

    Click the gear icon (Project Settings), scroll to Script Properties, click Add script property. Add ANTHROPIC_API_KEY with your API key as the value, then RULES_SHEET_ID with the Sheet ID from step 3.

    Your key lives only here. It is never in the code and never in a chat window.

  5. Test it once

    Select processNewEmails in the toolbar dropdown and click Run. Check the execution log: you should see classifications with confidence scores and reasons. Check Gmail: the four CF labels now exist, and anything classified Sales or Spam has been archived under them.

    If something real got archived, drag it back to the inbox and add the sender to your rules sheet.

  6. Turn it on

    Select setupTrigger and click Run once. That installs the five-minute timer. No deploy step is needed, because the trigger runs whatever is saved. You are done.

    For the first week, skim CF/Sales and CF/Spam every day or two and correct anything misfiled. After that the rules sheet does the watching for you.

The script

Copy this into Apps Script.

Anything still highlighted in yellow is a placeholder you have not filled in yet. Blue is your own text, already substituted.

email-classifier.gs
Placeholder — still to fill in Your details

Teaching it your rules

The rules sheet.

The script reads your rules sheet on every run, so corrections take effect within five minutes without touching the code. Add a row for each rule.

Rule typeMeaningValue
allowlistAlways keep this senderAn email address
blocklistAlways archive this sender as spamAn email address
allowlist_domainAlways keep this whole domainA domain, for example client.com
blocklist_domainAlways archive this whole domainA domain
custom_ruleA general instruction fed into the promptPlain English, e.g. "payment receipts from app stores are always Kept"

Rule of thumb

Prefer general custom rules over one-off entries. "Podcast invitations are always Sales" beats blocklisting one podcast host at a time, and it keeps working on senders you have never seen before.

Reference

Every placeholder, and where it lives.

PlaceholderReplace withWhere it lives
YOUR_EMAIL_HEREEvery address you send from, comma separated in quotes. Include aliases.CONFIG.ownerEmails, near the top
YOUR_NAMEYour actual nameThe classification prompt
YOUR_JOB_TITLEYour roleThe classification prompt
YOUR_COMPANYYour company name (appears six times)The classification prompt
YOUR_COMPANY_DOMAINSYour company's email domainsThe KEEP SIGNALS section of the prompt

When it misbehaves

Troubleshooting.

Real mail got archived

Drag it back to the inbox, then add an allowlist or allowlist_domain row to your rules sheet. Takes effect within five minutes.

Nothing is happening

Check the Triggers page (clock icon) shows processNewEmails every 5 minutes, then check the Executions page for errors.

"No ANTHROPIC_API_KEY set" in the log

The script property name must match exactly, all caps, no spaces.

"No working model found"

The model names in CONFIG.models are out of date. Replace them with current Anthropic model strings from the models docs and save. This is the most likely failure if you are picking this script up months after the episode aired — the script tries each model in order and caches the first that returns a 200, so one working name is enough.

Worried about quota

The script caps itself at 20 threads per run and stops after 4 minutes. Normal inboxes never get near Google's limits.

Copied