- Tools
- Gmail, Google Apps Script, Claude API
- Price
- Apps Script free, Claude API pay as you go
- Time
- 15 min
- Level
- Copy and paste, beginner
The idea: instead of opening thirty emails when you start work, you read one message that tells you what is urgent, what is waiting for your reply and what can wait. Everything happens inside your Google account, with a personal Gmail or a Google Workspace account.
Set up the key and the script
- Create a Claude API keySign in to the Claude Console, add a payment method and create a key. An API key is a password that lets a program use Claude: never paste it into an email or into the code.
- Create an Apps Script projectOpen script.google.com with the Google account of the inbox you want summarised, then click “New project”.
- Store the key in the script propertiesOn the left, open “Project Settings”, then “Script Properties”. Add a property named
CLAUDE_API_KEYwith your key as the value, and save. - Paste the scriptReplace everything in
Code.gswith the code below, then save. You can adapt the instructions and the Gmail search at the top of the file.// Gmail search: inbox, last 24 hours, no promotions or social const SEARCH = 'in:inbox newer_than:1d -category:promotions -category:social'; const MAX_THREADS = 30; const INSTRUCTIONS = "You are my assistant. Here are the emails I received since yesterday. " + "Summarise them in three parts: 1. Urgent (to handle today), " + "2. Waiting for my reply, 3. For information. " + "One line per email: sender, subject, what to do. Do not make anything up."; function morningSummary() { const key = PropertiesService.getScriptProperties().getProperty('CLAUDE_API_KEY'); const threads = GmailApp.search(SEARCH, 0, MAX_THREADS); if (threads.length === 0) return; const emails = threads.map(function (thread) { const msg = thread.getMessages().pop(); return 'From: ' + msg.getFrom() + '\nSubject: ' + msg.getSubject() + '\n' + msg.getPlainBody().slice(0, 1500); }).join('\n\n---\n\n'); const response = UrlFetchApp.fetch('https://api.anthropic.com/v1/messages', { method: 'post', contentType: 'application/json', headers: { 'Authorization': 'Bearer ' + key, 'anthropic-version': '2023-06-01' }, payload: JSON.stringify({ model: 'claude-haiku-5-5', max_tokens: 2000, messages: [{ role: 'user', content: INSTRUCTIONS + '\n\n' + emails }] }), muteHttpExceptions: true }); if (response.getResponseCode() !== 200) throw new Error(response.getContentText()); const text = JSON.parse(response.getContentText()).content .filter(function (block) { return block.type === 'text'; }) .map(function (block) { return block.text; }) .join('\n'); MailApp.sendEmail(Session.getEffectiveUser().getEmail(), 'Your email summary', text); }
Test it, then schedule it
- Run a first testPick the
morningSummaryfunction at the top of the editor and click “Run”. Google asks you to allow the script to read your emails, connect to an external service and send an email on your behalf: it is your own script, but read the list before accepting. The summary lands in your inbox. - Schedule it every morningOn the left, open “Triggers” (the alarm clock icon), then “Add Trigger”. Choose the
morningSummaryfunction, a time-driven trigger, daily, between 7am and 8am, and save. Google runs the script at a fixed time within that window.
Good to know
- The script only reads the last message of each conversation and its first 1,500 characters: that is on purpose, to keep costs down. Raise these values if you need to.
- The summary can be wrong or miss a detail. It is there to help you sort, not to replace reading an important email.
- On a free Gmail account, Google limits each run to 6 minutes and total trigger time to 90 minutes a day, which is plenty here.
Your emails go to Anthropic. Their content is sent to the Claude API to be summarised. Anthropic says it does not use data from its commercial products to train its models by default, but keep sensitive emails out of the search (health, client data under a confidentiality agreement). Keep the key in the script properties, never in the code, and do not share this project: anyone with access can see the key.
Sources
- Google Apps Script: GmailApp
- Google Apps Script: installable triggers
- Google Apps Script: script properties
- Google Apps Script: quotas
- Gmail: search operators
- Claude API overview and pricing
- Anthropic: is my data used for model training?
Want to go further, with automatic sorting, draft replies or delivery to Slack? That is the kind of automation I set up.