How to build cash application using Claude

- You need
- Bank lines and open invoices, as two CSV files
- Tested with
- Claude Sonnet 5.5, made-up data, 3 Nov 2026
- Result
- 35 of 35 bank lines matched the answer key
Before you start
A bank line arrives with a payer name nobody recognises and a reference somebody typed from memory.
Matching those lines to open invoices used to be a software project with a vendor and a data mapping. On 3 Nov 2026 we described five rules to Claude and had a working script in one session.
Cash application looks like a lookup. Our test has 35 bank lines and 42 open invoices, and it already needs rules for a typo in a reference, one payment covering several invoices, a customer who pays 3 percent short, and a payer name that differs from the customer name.
Size changes the job. More customers means more ways of writing the same payer, more invoices at the same amount, and more lockbox and bank formats. More entities and currencies add credit memos, deductions and payment terms, and each one touches the rules you wrote before it.
A mid size or large company should not own this code. Cash application runs on exceptions, and the exceptions decide how the application changes.
Whether a short payment is a discount, a dispute or a write off is a decision about that customer, and it can be different for the next one.
One session built it. Keeping it right is what we expect to take longer: customers change how they pay, the bank changes its file, and each new exception is a rule to write and test again.
We did not test that part. For the build or buy trade-off, read Build vs Buy: Finance AI Agents in 2026.
What you need
An ERP connection
Cash application is two reads and one write. You read the bank lines and the open items on the AR ledger. You write the cash receipt against an invoice.
In a live setup the reads are the simple part, and the write is where a mistake would cost you, because a wrong application stays on a customer's account until somebody notices it. We tested neither, since we used CSV files.
Our script never posts to an ERP. It writes a results file that a clerk checks. If your ERP has a mature, documented REST API for open items and receipts, you could build the posting step yourself. Check its API terms before you connect an AI tool to it.
ChatFin's build or buy page says ChatFin runs on the ERP and version you already have, reads through governed feeds, and writes back only drafts that a person approves through the official API. That is the posting step handed to someone else.
The data points
| File | Columns |
|---|---|
| Bank lines | line_id, date, amount, payer, reference |
| Open invoices | invoice_no, customer_id, customer, invoice_date, due_date, open_amount, currency |
The script never read the date, invoice date, due date or currency columns. Three things were missing, and Claude pointed at each one. The bank file has no currency column.
The invoice file has no discount terms, so a payment marked "LESS DISC" cannot be checked against the terms. And there is no list of the names each customer pays under.
A plan, broken into steps
Ask for the plan before any code. Attach both files and paste this.
I work in accounts receivable. I want a small tool that does cash application for me. I have two files: - bank_lines.csv: customer payments from the bank (line_id, date, amount, payer, reference) - open_invoices.csv: invoices still unpaid (invoice_no, customer_id, customer, invoice_date, due_date, open_amount, currency) For every bank line the tool should say which open invoice or invoices it pays, or that it cannot tell. My rules: 1. A bank line is matched only when you are sure. If it could fit two customers, do not guess. 2. The reference is the strongest clue, then the amount, then the payer name. The payer name on the bank line is often not the customer name. 3. One payment can pay several invoices of the same customer. 4. If a customer paid less or more than the invoice, match it and show the difference. 5. If nothing fits, mark it unapplied. Do not write code yet. Break the job into numbered steps. For each step say what it checks, and what the tool does with a line it cannot decide. Then list anything in my rules that is unclear.
Claude read the files and gave eight steps: read and tidy both files, pull invoice numbers out of each reference, work out which customer the line belongs to, check the amount against the invoices named, look at the amount alone when there is no reference, make sure no invoice is used twice, give each line one status and a reason, then write the result.
For each step it said what happens to a line it cannot decide.
It also asked eleven questions about our rules. Three of them could change a decision:
- Three payments are exactly 97 percent of their invoice and say LESS DISC. Is that a discount that closes the invoice, or a short payment that leaves the rest open?
- How far can an amount be from the invoice and still count as a match?
- Three lines have no reference, but the amount and the payer name both point to one invoice. Is that sure enough?
Open for your AR lead. We did not answer them. We told Claude to use its plan, and it answered with ten listed choices. In a real project your AR lead and controller answer them first.
Ask Claude to build it
Good. Use that plan. Write one Python script, standard library only, that reads both files and writes matches.csv with these columns: line_id, status, invoice_nos, difference, reason. - status is one of: matched, matched_with_difference, needs_review, unapplied - invoice_nos: invoice numbers joined with | when one payment pays several - reason: one short sentence a collector can read Never change my input files. Run it, then show me the count of lines per status and every line that is not plain matched.
We ran both prompts in Claude Code with Sonnet 5.5 (claude-sonnet-5-5) on 3 Nov 2026, as two turns of one conversation. We then ran them again from scratch in a clean folder, in one session that held both messages.
The second script was longer (320 lines) and gave the same status on all 35 lines. We did not run them in the Claude chat app.
The script is 211 lines of Python, standard library only. It gave every one of the 35 bank lines a status: 26 matched, 5 matched with a difference, 2 for review and 2 unapplied. These are the nine lines that were not plain matches:
| Line | Status | Invoices | Reason the script gave |
|---|---|---|---|
| B002 | needs review | INV-10478, INV-10485 | No reference and payer not recognised; amount fits INV-10478 (Northline Foods Inc), INV-10485 (Maple Row Hardware). |
| B012 | matched with difference | INV-10581 | Paid 29.11 short against INV-10581 of 970.40. Reference says LESS DISC. |
| B014 | unapplied | none | No reference, payer not recognised, and no open invoice has this amount. |
| B024 | matched with difference | INV-10586 | Paid 146.70 short against INV-10586 of 4890.00. Reference says LESS DISC. |
| B026 | matched with difference | INV-10593 | Paid 125.00 over against INV-10593 of 1760.00. |
| B027 | needs review | INV-10478, INV-10485 | No reference and payer not recognised; amount fits INV-10478 (Northline Foods Inc), INV-10485 (Maple Row Hardware). |
| B029 | matched with difference | INV-10602 | Paid 40.00 over against INV-10602 of 3125.00. |
| B032 | unapplied | none | INV-10211 is not on the open invoice list. |
| B033 | matched with difference | INV-10575 | Paid 70.20 short against INV-10575 of 2340.00. Reference says LESS DISC. |
In the first script Claude made some choices that we never asked for. It sent any reference more than 10 percent away from the invoice amount to review. It ignored dates.
It assumed every amount is in dollars. It reported "LESS DISC" in the reason but did not treat it as a discount. Each is a policy, and the policy belongs to you.
Where to run it
Cash is applied every morning. A script on one laptop stops when the laptop does, and it leaves no record of who accepted a match.
You need a place that runs it on a schedule, a screen where a clerk approves the review lines, and a log. A hosting service like Vercel can serve that screen. We hosted nothing for this page.
Test it before you trust it
1. Keep the answer key out of the chat
We built the 35 bank lines from known cases: 14 with the invoice number in the reference, 4 payments covering several invoices, 3 under another payer name, 3 short, 2 over, 3 with no reference, 2 typos, 2 where the amount fits two customers, and 2 that fit nothing.
We did not give Claude the answer key. All 35 results matched it, and among those 35 none was applied to a wrong invoice.
Made-up data. We designed the cases. A 35 out of 35 score shows that the script follows the rules on these cases. It says nothing about the accuracy on your bank file.
2. Try to break it
Then we sent 12 awkward cases, each against the same open invoices plus five test invoices. The table groups them into ten rows. These results are from the first script.
| What we sent | What the script did |
|---|---|
| The same payment twice, both lines naming INV-20003 | Both held. Reason: "INV-20003 is also claimed by" the other line |
| Reference names the right invoice, amount is half of it (320.00 short of 640.00) | Held. Claude set a 10% limit on its own; we never gave it one |
Reference typed inv20004, no hyphen, lower case | Matched to INV-20004, when it was the only line naming that invoice |
| Reference names one customer's invoice, payer is another customer | Held. Reason names both: the payer looks like Maple Row Hardware, the reference is for Brightway Dental LLC |
| No reference, and the customer has two open invoices for that amount | Held, both invoices listed |
No reference, payer typed as THE NORTHLINE FOODS COMPANY, HARBOR TOOLS LIMITED or BRIGHTWAY DENTAL | All three matched on the name and a unique amount |
No reference, payer ACCT PAYABLE DEPT | Held, with the one invoice that fits listed |
A negative bank line, a refund of -250.00, reference REFUND | Unapplied, reason "No reference and Brightway Dental LLC has no open invoice for this amount". The reference was there, and the money is going out, so the reason is wrong |
No reference, payer HARBOR FREIGHT LLC, an amount that fits a Harbor Tools invoice | Matched to the Harbor Tools invoice, reason "amount and payer name both fit". Wrong customer |
Reference is the bare number 10406, no INV prefix | Matched, but by amount and payer. The reference was ignored, and the reason says "No reference" |
3. Take the choices to your AR lead
Two rows show the usual problem. The script had no rule for money going out, so it filed the refund under the nearest rule and gave a reason that reads wrong.
And it accepted a payer that only starts with the same word as a customer, so a different company's payment went to a Harbor Tools invoice. Our 35 lines never contained that. The second script chose differently on three of these rows.
It set no limit on the half payment and matched it with a difference. It sent the refund to review with the reason "not a usable payment amount". It held the HARBOR FREIGHT payment for review instead of applying it.
Two scripts from the same prompts disagree where the prompts were silent, so write down what each choice should be, add it to the prompt, and run the same lines again.
Where ChatFin fits
The script shows how far five rules and two files get you.
What it lacks is the rest of the job: the connection that posts to your ERP, a screen where the clerk clears the review lines, a record of who approved each match, and a person who updates it when a customer starts paying a new way.
ChatFin's own build or buy page lists the governed connection, the approval workflow and the audit trail as the parts you get when you buy (Build vs Buy: Finance AI Agents in 2026).
If you would rather buy it
ChatFin's build or buy page says it reads through governed feeds and writes back only drafts a person approves. We did not run this process through ChatFin. ChatFin also has a page titled Cash application is a matching problem.