How to Automate Invoices With AI (Claude Code or n8n)
Automate invoices with AI: pull invoices from email, extract vendor, date and totals, then send them to your accountant or a sheet with Claude Code or n8n.
By Yotam DahanUpdated 10 min readAutomation and agents
On this page
To automate invoices with AI, you collect the invoice files from your inbox, have an AI model read each one and pull out the fields your accountant needs, check the numbers, then deliver the result to the accountant or a spreadsheet. Claude Code does this on your computer whenever you ask or on a schedule, while n8n runs it as an always-on workflow that reacts to every new email. Below are both routes step by step, plus the privacy points to settle before any invoice reaches an AI model.
Collect
Invoice PDFs arrive by email or land in a folder
Extract
An AI model reads each one and pulls out the fields
Check
Totals add up and nothing is missing or doubled
Deliver
Rows go to a sheet and files go to your accountant
Choose your route
Both routes use the same idea. The difference is when they run and how much you see.
| Claude Code | n8n | |
|---|---|---|
| When it runs | When you ask, or on a schedule from the Claude desktop app | Every time a matching email arrives |
| Best for | A monthly batch you review together | Invoices handled as they come in |
| Setup | A folder, a prompt and an optional Gmail connector | Five connected steps, an AI model and Google credentials |
| Main cost | Your Claude plan | An n8n plan or your own server, plus AI model usage |
| Coding needed | No | No, but you configure each node |
New to the n8n side? Start with the n8n tutorial for beginners, and check what n8n costs before you pick cloud or self-hosting.
Decide what to capture
Agree on the fields with your accountant before you build anything. Changing them later means fixing every row you already have.
| Field | Example | Why it matters |
|---|---|---|
| Vendor name | Northwind Supplies | Groups costs by supplier |
| Invoice number | INV-2041 | Catches duplicates |
| Invoice date | 2026-10-03 | Puts the cost in the right period |
| Currency | EUR | Avoids mixing amounts |
| Subtotal | 400.00 | The amount before tax |
| Tax | 80.00 | Needed for tax returns |
| Total | 480.00 | Must equal subtotal plus tax |
| File name | 2026-10_northwind_INV-2041.pdf | Links each row to its original |
The example values are made up to show the format.
Route A: Claude Code, step by step
This route gives you a reviewed batch, usually once a month. It suits owners who want to see every invoice before it goes anywhere; for the wider set of jobs Claude Code can take on in a business, see Claude Code for small business.
Step 1: Set up the folder and rules
invoices/
CLAUDE.md
inbox/ new invoice PDFs go here
processed/ renamed copies after extraction
reports/ the monthly spreadsheet and summaryPut the rules in the folder's CLAUDE.md, the file Claude Code reads at the start of every session:
# Invoices
- Extract only these fields: vendor_name, invoice_number, invoice_date, currency, subtotal, tax, total, file_name.
- Never guess a value. Leave it empty and list the file under "needs review".
- Never delete or edit files in inbox/. Save renamed copies in processed/.
- Never send email. Create drafts only.Step 2: Get the invoices into the folder
The simplest start is saving each month's PDF attachments into inbox/ yourself. To make sure none are missing, connect Google's Gmail connector at claude.ai under Customize > Connectors and let Claude search for you, using Gmail's search operators:
Search my Gmail for: has:attachment filename:pdf {subject:invoice subject:receipt} newer_than:1m
List every match in a table: date, sender, subject and attachment names.
Then compare the senders with last month's vendors in @reports/ and list anyone who hasn't sent an invoice yet.
Don't forward, label or delete anything.Use the table to download the attachments into inbox/, and chase the vendors on the missing list. For other tools you may want to connect, see the ai school MCP directory and the safety basics in what an MCP server is.
Step 3: Extract the data
Claude Code reads PDF files directly, so the extraction is a single prompt:
Read every PDF in @inbox/. For each invoice, add one row to reports/invoices-[MONTH].csv with the fields from CLAUDE.md.
Write dates as YYYY-MM-DD and amounts as plain numbers without currency symbols.
Copy each file to processed/ named YYYY-MM_vendor_invoice-number.pdf and put that name in file_name.
If a value is unclear, leave it empty and add the file to a "needs review" list at the end.Step 4: Check the numbers
Using a script, check reports/invoices-[MONTH].csv:
1. subtotal + tax = total on every row (allow a difference of 0.01 for rounding)
2. no vendor and invoice number pair appears twice
3. every invoice date falls in [MONTH]
4. every row has a currency
Print the total of all invoices by currency, and list every row that fails a check with the reason.When something fails, the answer looks like this:
- You:
Run the checks on this month's invoices.
- Claude Code:
Every check passed except one row: the total on the invoice from one vendor doesn't equal its subtotal plus tax. I've left that row out of the summary and added the file to "needs review" so you can look at the original.
Step 5: Package it for your accountant
Zip the files in processed/ for [MONTH] as reports/invoices-[MONTH].zip.
Write a short summary: number of invoices, totals by currency, and the "needs review" list.
Create a Gmail draft to [ACCOUNTANT EMAIL] with that summary as the message. Don't send it.Open the draft in Gmail, attach the zip and the CSV yourself, read it once, and send it.
Step 6: Make it monthly
Once the steps run cleanly, ask Claude Code to save Steps 3 to 5 as a skill called month-end-invoices, a saved procedure you start with one command; how to create a Claude skill shows the format. In the Claude desktop app, you can also ask in a session to schedule it on the first of each month as a Desktop scheduled task. It still pauses for you at the draft.
Route B: n8n, step by step
n8n is an automation platform where each step is a node, a box on a canvas that does one job, and data flows from node to node. This workflow processes each invoice email as it arrives:
Gmail Trigger
Spots a new invoice email and downloads the PDF
Gmail
Sends the PDF to your accountant
Extract From File
Pulls the text out of the PDF
Information Extractor
An AI model turns the text into fields
Google Sheets
Adds or updates one row per invoice
The Gmail send step hangs off the trigger on its own branch. The extraction steps don't carry the PDF file forward, so the send step takes the attachment straight from the trigger.
- Gmail Trigger. Choose the Message Received event and set Poll Times, such as every hour. Under Filters > Search, enter
has:attachment filename:pdf {subject:invoice subject:receipt}. Turn Simplify off, then under Options add Download Attachments and switch it on. The first attachment arrives as a file field calledattachment_0. - Gmail, send branch. Connect a Gmail node to the trigger and choose the Send operation for a message. Set To to your accountant's address, the subject to something like
Invoice: {{ $json.subject }}and a one-line message, then under Options > Attachments enterattachment_0as the field name. - Extract From File. Connect it to the trigger as a second branch. Choose Extract From PDF and set Input Binary Field to
attachment_0. The PDF's text comes out in a field calledtext. - Information Extractor. Set Text to
{{ $json.text }}and Schema Type to From Attribute Descriptions, then add one attribute per field from the table above, each with a one-line description. Connect a chat model, such as the Anthropic Chat Model node, under Model. The answers arrive inside a field calledoutput. - Google Sheets. Choose Append or Update Row. Add a
keycolumn to your sheet and match on it, filling it with{{ $json.output.vendor_name }}-{{ $json.output.invoice_number }}, so a resent invoice updates its row instead of adding a copy. Map the other columns manually, such as{{ $json.output.total }}. - Test, then publish. Send yourself an email with a sample invoice, set the accountant address to your own for the first run, and execute the workflow. When the row and the email look right, switch the address back and click Publish so it runs on its own.
The node settings come from n8n's documentation for the Gmail Trigger and the Information Extractor.
Privacy and data protection
Invoices contain names, addresses, bank details and amounts. Settle these points before the first real one goes through:
0 of 6 done
Common problems and fixes
| Problem | Likely cause | Fix |
|---|---|---|
| The trigger fires on every email | No search filter | Add the search from step 1 of Route B |
| No attachment reaches n8n | Simplify is still on, or Download Attachments is off | Turn Simplify off and switch on Download Attachments |
| Extract From PDF returns empty text | The PDF is a scan | Use Analyze Document instead |
| The wrong file was processed | The email had more than one attachment | Check which attachment_ number holds the PDF |
| A total doesn't match | A figure was misread | Send the row to review and read the original |
| The same invoice appears twice | The supplier sent it again | Match on the key column with Append or Update Row |
Quick check0 of 2 correct
Why does the Gmail send step connect straight to the trigger in the n8n workflow?
Not quite.
The Information Extractor outputs fields, not the original file, so the send step takes the attachment from the trigger.
An invoice's total doesn't equal its subtotal plus tax. What should happen?
Not quite.
A mismatch usually means a misread figure, so a person should look at the original before the number goes anywhere.
What to do next
Pick your route: Claude Code if you want a monthly batch you review, n8n if invoices should be handled as they arrive. Then run it on last month's invoices before you trust it with this month's.
The Claude Code course includes a lesson that builds this inbox-to-accountant agent step by step. For automations that keep your tools connected around the clock, our AI automation course, Autopilot, is in early access, and what AI automation is explains where it fits.
Invoice automation setup pack
The field list with formats, a copy-ready extraction prompt with built-in checks, every n8n node setting in one table, and an email template for your accountant.
Enter your email and the full section opens right here. You also get a free lesson from the course.
Frequently asked questions
How accurate is AI invoice extraction?
It depends mostly on your files: clean digital PDFs read more reliably than phone photos or faded scans. Ask suppliers for PDF invoices where you can, and keep a person reviewing anything your checks flag.
Do I need to pay for n8n to do this?
Not necessarily. n8n's Community Edition is free to self-host, but then you run and maintain the server yourself, while n8n Cloud is a paid service. In both cases the AI model step has its own usage cost.
Can the automation pay the invoices too?
It can prepare a list of what is due and when, but keep payments manual. Money should only move through you or your accountant, with your bank's own approval steps.
Does this work with Outlook instead of Gmail?
Yes. In n8n, the Microsoft Outlook Trigger node also has a Download Attachments option, so you can swap the Gmail nodes for Outlook ones. For the Claude Code route, Anthropic's connector directory lists a Microsoft 365 connector.
How long should I keep the original invoices?
That depends on the tax rules where your business is registered, so ask your accountant. Whatever the period, the automation should copy data out of invoices, never delete the original emails or files.
Keep reading
n8n Tutorial for Beginners: Build Your First Real Workflow
A beginner n8n tutorial: build a real workflow that captures a form lead, emails them and logs them in Google Sheets, step by step, plus cloud vs self-host.
Automation and agents · 8 min readClaude Code for Small Business: A 30-Day Plan for Owners
Claude Code for small business owners: hand it quotes, invoices, inbox drafts, documents and weekly reports, with a 30-day rollout plan and ground rules.
AI by role · 8 min readWhat Is AI Automation? Plain Answers and 12 Real Examples
What is AI automation? See how it differs from rules-based automation and AI agents, 12 examples by department, what it costs, the risks and how to start.
Automation and agents · 9 min read