Skip to content

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
  1. Choose your route
  2. Decide what to capture
  3. Route A: Claude Code, step by step
  4. Route B: n8n, step by step
  5. Privacy and data protection
  6. Common problems and fixes
  7. What to do next

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.

The four stages of invoice automation
  1. Collect

    Invoice PDFs arrive by email or land in a folder

  2. Extract

    An AI model reads each one and pulls out the fields

  3. Check

    Totals add up and nothing is missing or doubled

  4. 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 Coden8n
When it runsWhen you ask, or on a schedule from the Claude desktop appEvery time a matching email arrives
Best forA monthly batch you review togetherInvoices handled as they come in
SetupA folder, a prompt and an optional Gmail connectorFive connected steps, an AI model and Google credentials
Main costYour Claude planAn n8n plan or your own server, plus AI model usage
Coding neededNoNo, 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.

FieldExampleWhy it matters
Vendor nameNorthwind SuppliesGroups costs by supplier
Invoice numberINV-2041Catches duplicates
Invoice date2026-10-03Puts the cost in the right period
CurrencyEURAvoids mixing amounts
Subtotal400.00The amount before tax
Tax80.00Needed for tax returns
Total480.00Must equal subtotal plus tax
File name2026-10_northwind_INV-2041.pdfLinks 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

text
invoices/
  CLAUDE.md
  inbox/       new invoice PDFs go here
  processed/   renamed copies after extraction
  reports/     the monthly spreadsheet and summary

Put the rules in the folder's CLAUDE.md, the file Claude Code reads at the start of every session:

markdown
# 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:

Find this month's invoice emails
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:

Extract invoice data
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

Check the extracted invoices
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:

  1. You:

    Run the checks on this month's invoices.

  2. 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

Prepare the accountant package
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:

The n8n invoice workflow
  1. Gmail Trigger

    Spots a new invoice email and downloads the PDF

  2. Gmail

    Sends the PDF to your accountant

  3. Extract From File

    Pulls the text out of the PDF

  4. Information Extractor

    An AI model turns the text into fields

  5. 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.

  1. 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 called attachment_0.
  2. 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 enter attachment_0 as the field name.
  3. 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 called text.
  4. 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 called output.
  5. Google Sheets. Choose Append or Update Row. Add a key column 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 }}.
  6. 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

ProblemLikely causeFix
The trigger fires on every emailNo search filterAdd the search from step 1 of Route B
No attachment reaches n8nSimplify is still on, or Download Attachments is offTurn Simplify off and switch on Download Attachments
Extract From PDF returns empty textThe PDF is a scanUse Analyze Document instead
The wrong file was processedThe email had more than one attachmentCheck which attachment_ number holds the PDF
A total doesn't matchA figure was misreadSend the row to review and read the original
The same invoice appears twiceThe supplier sent it againMatch 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?

An invoice's total doesn't equal its subtotal plus tax. What should happen?

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.

No spam. One click to unsubscribe. We use your email to send you the course and AI tips.

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