Skip to content

Automate Invoice Processing With AI: Claude Code or n8n

To automate invoice processing with AI, collect invoice PDFs from Gmail, let Claude extract the fields, check the math with a script and deliver a CSV. Claude Code suits a monthly batch and n8n handles each invoice as it arrives. In our November 2026 test on 8 invoices, Claude Opus 5.5 filled in 1,056 values over 16 runs and none contradicted the invoice.

By Yotam DahanUpdated 17 min readAutomation and agents

Invoice check script output: 7 invoices checked, totals of EUR 780.00 and USD 49.00 for the rows that passed, and 4 rows flagged for review: a total of 1404.00 against 1440.00, a duplicate, a date outside 2026-10 and a missing currency
Captured in October 2026 from an earlier check script (its inputs were not kept, and it checked subtotal + tax only). On November 18, 2026 we rebuilt a 7-row file with the same four problems, and three logged Claude Opus 5.5 runs of Step 4 printed the same totals.

Every invoice automation runs the same four stages: collect the PDFs, extract the fields, check the numbers with a script, and deliver a sheet and the files to your accountant. Pick Claude Code if you want to look over every invoice before anything leaves your computer, and n8n if invoices arrive all month from many suppliers and nobody should have to start a run. Neither route needs coding.

How does AI invoice processing work?

AI invoice processing means a language model reads each invoice the way a person would and returns the same fixed list of fields every time. Classic automated invoice processing uses OCR tools that often need a template per supplier layout; a model copes with a new layout on the first try, but it can still misread a figure, which is why the check stage exists.

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

    A script confirms totals add up and nothing is doubled

  4. Deliver

    Rows go to a sheet and files go to your accountant

Should you use Claude Code or n8n?

Both routes automate invoices with AI in those four stages; they differ in when they run, what you see first and what you pay for.

Claude Coden8n
When it runsWhen you ask, or on a schedule from the Claude desktop appOn every poll that finds a new invoice email, such as hourly
What you seeEvery row and every flagged file before anything is sentThe rows it adds and the alerts it emails you
SetupA folder, a prompt and an optional Gmail connectorFive connected nodes, an AI model and Google credentials
Main costYour Claude planAn n8n plan or your own server, plus AI model usage

New to n8n? Start with the n8n tutorial for beginners.

What does it cost to automate invoice processing with AI?

$0.20

median cost of one 8-invoice run on Opus 5.5 in Claude Code

55

seconds, the median length of that run

$20

Claude Pro a month on monthly billing, Claude Code included

€20

n8n Cloud Starter a month on yearly billing

Run figures from Claude Code's own cost report in our 16 test runs of November 6, 2026, at API list prices. Plan prices from claude.com/pricing and n8n.io/pricing, checked November 6 and again November 8, 2026.

Claude Code route: the work counts against your plan's usage allowance, so there is no per-invoice bill. Pro costs $20 a month billed monthly or $17 a month billed yearly, and the Free plan doesn't include Claude Code (Claude's pricing page, checked November 8, 2026).

n8n route: a poll that finds new invoices counts as one execution, and n8n's executions docs say a poll that finds nothing doesn't count, so even hourly checking stays far below Starter's 2,500 executions a month; the n8n pricing guide has every plan.

The AI step: Anthropic's PDF docs put a page at 1,500 to 3,000 text tokens, so 100 one-page invoices come to at most about 300,000 input tokens (chart below). A Claude Code run costs more, because it also sends Claude Code's own instructions and tool calls: our 8-invoice runs on Opus 5.5 came to $0.18 to $0.27, about 2 to 3 cents an invoice.

API input cost of 100 one-page invoices (300,000 tokens)
  • Haiku 5.5$0.03
  • Sonnet 5.5$0.60
  • Opus 5.5$1.20

Anthropic's API list prices of $0.10, $2 and $4 per million input tokens (platform.claude.com/docs/en/about-claude/pricing), checked November 6, 2026, with each invoice sent as its own request, as n8n does, plus a little for the answers. Opus 5.5 is the model we tested.

Which is the best AI model for invoice processing?

The one your checks say is good enough. We kept the model fixed at Opus 5.5 in all 16 runs, and every change in the results came from the field list and the rules, so we can't rank models for you. We did not test Haiku 5.5, at a fortieth of Opus 5.5's input price, so before you switch to save money, run it on last month's invoices and compare its CSV with a run you trust.

Which fields should you extract from an invoice?

Invoice data extraction only works if every run fills the same fields, so settle them with your accountant first and use the same names everywhere.

FieldExampleWhy it matters
Document typeinvoiceKeeps credit notes from counting as costs
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
Other charges0.00Shipping, fees and discounts, so the math still adds up
Tax80.00Needed for tax returns
Total480.00Must equal subtotal plus other charges plus tax
File name2026-10_northwind_INV-2041.pdfLinks each row to its original

The example values are made up to show the format.

How accurate is AI invoice extraction? We tested 8 invoices

Very accurate on what the invoice prints, and only as careful as your rules on what it leaves open. On November 6, 2026 we ran eight made-up invoices 16 times through Route A's prompt with Claude Opus 5.5 in Claude Code 2.1.303 and logged every run.

Only the CLAUDE.md changed in the first 13 runs: the first field list (3 runs), then Other charges and Document type (3), then the date rule (4), then a currency rule (3). The last 3 runs kept that CLAUDE.md and also used Step 3's revised prompt. A script compared every value with the invoices and ran Step 4's checks.

InvoiceWhat happened in 16 runs
Clean; odd labels ("Bill #", "Net", "Amount due"); German format 1.234,50 €Every value right in all 16 runs
Scan with no text layerRead right in all 16; pdftotext, a plain PDF text extractor, got nothing from it
US date 10/09/2026 from a Brooklyn studioLeft empty for review with the first field list (3 of 3) and with the date rule (10 of 10); in between, 2 of 3 runs wrote October 9 without flagging it
Shipping line and discountFigures read right; on the first field list the discounted invoice's subtotal was left empty in 2 of 3 runs, and the sum check flagged both correct invoices in all 3
Credit note showing only $First field list: left out (3 of 3). With Document type: a negative row in all 13. The $ became USD without comment in 2 of the 7 runs before the currency rule, and stayed empty for review in all 6 with it
  • No misread figures: 1,056 values filled in, none contradicted the invoice, and 4 were guesses on values it leaves open (the date twice, USD twice).
  • Two fields ended the false alarms: with Other charges and Document type, the sum check passed every correct invoice in all 13 later runs.
  • Ask for the review list in the reply: in 1 of 13 runs it landed inside the CSV as three extra rows; Step 3's prompt now asks for it at the end of the reply, which kept it out in the 3 runs that followed.
  • Keep the script: checking by reading, Opus 5.5 agreed with it in all 16 runs, but the script gives the same answer on 800 rows and names the row that failed.

Route A: Claude Code, step by step

You need Claude Code and a folder on your computer; for other jobs Claude Code can take on, 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, which Claude Code loads whenever you start a session there:

markdown
# Invoices
- Extract only these fields: document_type, vendor_name, invoice_number, invoice_date, currency, subtotal, other_charges, tax, total, file_name.
- document_type is invoice or credit_note. Credit notes get negative amounts.
- other_charges is shipping, fees and discounts as one number (discounts negative, 0 if none).
- If a date could be read two ways, such as 10/09/2026, leave it empty.
- currency is a three-letter code. If the invoice shows only a symbol that several currencies share, such as $, and nothing else on it (an address, a tax number) settles which one, leave it empty.
- 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 catch missing ones, connect Google's Gmail connector at claude.ai/customize/connectors; Claude Code picks it up when you're signed in with your plan. It sees attachment metadata, not the files (Anthropic's Google Workspace connector page), so use it for a checklist built with 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.

Download the attachments in that table into inbox/ and chase the vendors on the missing list. For the safety basics of connecting tools, see what an MCP server is.

Step 3: Extract invoice data from PDF to Excel or Google Sheets

Claude Code reads PDF files directly, so the extraction is one prompt, and the CSV it writes opens in Excel or Google Sheets.

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 list the file under "needs review" at the end of your reply, not inside the CSV.

Step 4: Check the numbers

Check the extracted invoices
Write a small script that checks reports/invoices-[MONTH].csv, then run it:
1. subtotal + other_charges + tax = total on every row (allow a difference of 0.01 for rounding)
2. no vendor and invoice number pair appears twice (keep the first row and flag every later copy)
3. every invoice date falls in [MONTH]
4. every row has a currency
Print the total by currency of the rows that pass every check, and list every row that fails a check with the reason.

The wording of the last line matters. On November 18, 2026 we ran this step 9 times with Opus 5.5 on a made-up 7-row file with four planted problems: a swapped digit (1404 instead of 1440), a duplicate, a September date and a missing currency. Every run caught all four. When the prompt asked for "the total of all invoices", all 3 runs added the flagged rows in (EUR 2,664.00 instead of 780.00). Asking for the rows that pass fixed that, but 2 of 3 runs then flagged both copies of the duplicate, until "keep the first row" made all 3 agree. One of those last runs, as the script printed it:

Terminal
python3 check_report.py
Report: reports/invoices-2026-10.csv
 
Totals by currency (rows that pass every check):
  EUR  780.00
  USD  49.00
 
Rows that fail a check: 4
  line 5: Pixel & Co PX-0057 (2026-10_pixel-co_PX-0057.pdf)
    - amounts don't add up: 1200.00 + 0.00 + 240.00 = 1440.00, but total is 1404.00
  line 6: Northwind Supplies INV-2041 (2026-10_northwind-supplies_INV-2041-copy.pdf)
    - duplicate of line 2 (same vendor and invoice number)
  line 7: Greenleaf Office GL-3310 (2026-09_greenleaf-office_GL-3310.pdf)
    - invoice date 2026-09-28 is outside 2026-10
  line 8: Metro Couriers MC-7781 (2026-10_metro-couriers_MC-7781.pdf)
    - currency is missing

Each run cost about $0.10 on Claude Code's own cost report. Flagged rows stay out of the totals until you fix them.

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. If your books are in QuickBooks or Xero, both also connect to Claude, so it can answer questions about what is already recorded there.

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), then ask the Claude desktop app to schedule it for the first of each month. Per Anthropic's desktop scheduled tasks docs, local tasks run only while the app is open and the computer awake; if it sleeps through the 1st, one catch-up run starts when it wakes.

Route B: n8n invoice automation, 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 send step hangs off the trigger on its own branch, because the extraction steps don't carry the PDF forward.

  1. Gmail Trigger. Event Message Received, Poll Times such as every hour, and under Filters > Search has:attachment filename:pdf {subject:invoice subject:receipt}. Turn Simplify off, then add Options > Download Attachments and switch it on; the first attachment arrives as a file field called attachment_0.
  2. Gmail, send branch. A Gmail node on the trigger with the Send operation, your accountant's address in To, a subject such as Invoice: {{ $json.subject }} and attachment_0 under Options > Attachments.
  3. Extract From File. A second branch from the trigger: Extract From PDF with Input Binary Field set to attachment_0. The text comes out in a field called text.
  4. Information Extractor. Text set to {{ $json.text }}, Schema Type set to From Attribute Descriptions, one attribute per field from the table above with a one-line description, and Type Number for the four amounts. Connect a chat model, such as the Anthropic Chat Model node, under Model; the answers arrive inside output.
  5. Google Sheets. Append or Update Row, matching on a key column filled 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 }}. With QuickBooks Online, its n8n node can create a Bill instead, once your accountant trusts the data.
  6. Test, then publish. Email yourself a sample invoice with your own address in place of the accountant's, execute the workflow, and when the row and the email look right, switch the address back and click Publish.

What we ran. On November 8, 2026 we ran two parts of this workflow in n8n 2.44.4 on our 8 test invoices: Extract From PDF returned each file's text in text and nothing from the scan, and the If condition above sent all 8 correct rows, the negative credit note included, to true and a planted 1404-for-1440 total to false. The Gmail, Information Extractor and Google Sheets nodes need your own accounts, so their settings come from n8n's docs for the Gmail Trigger and the Information Extractor, plus the trigger's defaults in the 2.44.4 source code.

Prefer to start from someone else's build? A search for "invoice" in n8n's template library returned 354 workflows on November 8, 2026. Treat any n8n invoice processing template as a draft: check where each node sends your data before you add credentials.

Privacy and data protection

Invoices contain names, addresses, bank details and amounts, so settle these points before the first real one goes through (the Claude terms come from Anthropic's data usage page):

0 of 6 done

Common problems and fixes

Problem or messageLikely causeFix
This operation expects the node's input data to contain a binary file 'attachment_0', but none was foundSimplify is on, Download Attachments is off, or the email had no fileTurn Simplify off, switch on Download Attachments, and keep has:attachment in the search
Some invoice emails never triggerRead Status is on Unread emails only and someone opened themSet Read Status to Unread and read emails
Extract From PDF returns empty textThe PDF is a scanUse Analyze Document instead
is Anthropic-hosted and doesn't support local OAuthYou added Gmail with claude mcp addRun claude mcp remove with that name and connect Gmail at claude.ai instead
The Gmail connector doesn't show in Claude CodeClaude Code is using an API key, not your planRun /status, unset ANTHROPIC_API_KEY and run /login
A total doesn't matchA misread figure, or shipping or a discount outside Other chargesCheck other_charges first, then read the original

The n8n messages come from the node source code, and the Claude Code ones from Anthropic's MCP docs and tools reference.

Quick check0 of 3 correct

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

You ask Claude to fetch this month's invoice PDFs through the Gmail connector. What happens?

A US supplier's invoice is dated 10/09/2026. What should the extraction write?

What to do next

Pick a route from the comparison table, then run it on last month's invoices, which you already know, and match its totals with your records before you trust it with this month's.

Our Claude Code course, in early access for pre-order, builds this kind of agent in a 30-minute lesson, "Invoices from your inbox straight to your accountant". For automations that keep your tools connected around the clock, our AI automation course, Autopilot, is in early access too, 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.

No spam. One click to unsubscribe. We use your email to send you this bonus, new guides and news about our courses.

Frequently asked questions

What if an invoice subtracts withholding tax?

Add a withholding field, entered as a positive number, and change the sum check to subtotal + other charges + tax - withholding = total, or every such invoice gets flagged. None of our 8 test invoices had withholding, so we didn't test this rule: compare the first few rows with the originals by hand.

Is AI invoice processing free?

The software can be: n8n says it runs as the free Community edition when you host it yourself without a license key. The AI step is not free, because Claude's Free plan doesn't include Claude Code, API calls are billed per token, and a server of your own has its own hosting bill.

Can AI read invoices and receipts from photos?

Yes. Claude reads JPEG, PNG, GIF and WebP images as well as PDFs, so AI receipt processing and photographed invoices work in the Claude Code route. We didn't test phone photos, so we can't say how often blur, shadows or creases cause misreads: check every photographed row until you know.

Does this work with Outlook instead of Gmail?

Yes. In n8n, the Microsoft Outlook Trigger node has its own Download Attachments option, so you can swap the Gmail nodes for Outlook ones. For the Claude Code route, Anthropic offers a Microsoft 365 connector.

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.

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 and never delete the original emails or files.

Keep reading