Show Me Your AI · Episode 08 · Template
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.
Step 00 · Personalise
0 / 5 filledNothing 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.
How it decides
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
Setup
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.
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.
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.
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.
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.
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
Anything still highlighted in yellow is a placeholder you have not filled in yet. Blue is your own text, already substituted.
Teaching it your rules
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 type | Meaning | Value |
|---|---|---|
allowlist | Always keep this sender | An email address |
blocklist | Always archive this sender as spam | An email address |
allowlist_domain | Always keep this whole domain | A domain, for example client.com |
blocklist_domain | Always archive this whole domain | A domain |
custom_rule | A general instruction fed into the prompt | Plain 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
| Placeholder | Replace with | Where it lives |
|---|---|---|
YOUR_EMAIL_HERE | Every address you send from, comma separated in quotes. Include aliases. | CONFIG.ownerEmails, near the top |
YOUR_NAME | Your actual name | The classification prompt |
YOUR_JOB_TITLE | Your role | The classification prompt |
YOUR_COMPANY | Your company name (appears six times) | The classification prompt |
YOUR_COMPANY_DOMAINS | Your company's email domains | The KEEP SIGNALS section of the prompt |
When it misbehaves
Drag it back to the inbox, then add an allowlist or allowlist_domain row to your rules sheet. Takes effect within five minutes.
Check the Triggers page (clock icon) shows processNewEmails every 5 minutes, then check the Executions page for errors.
The script property name must match exactly, all caps, no spaces.
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.
The script caps itself at 20 threads per run and stops after 4 minutes. Normal inboxes never get near Google's limits.