# I Asked for a CSV Button. The Agent Sent 63 Files

> A diff much bigger than the task is not extra work done. It is extra work for you. Ask for the plan and the file list before any code.

- URL: https://hsalem.com/csv-button-63-files/
- Author: Hassan Salem (https://hsalem.com/about/)
- Published: 2026-11-25
- Topics: AI, Process, Software Engineering

"Is the CSV thing done? I see a pull request with your name!"

Dana wrote this on Tuesday at 11:52. Dana runs customer success at our startup, and on Thursday morning she had a call with our biggest logistics customer. Their finance team wanted one simple thing: export the invoices from the admin page into a file they can open in Excel. Every month they copy the numbers by hand from the screen. They were not happy about it, and Dana was the one hearing it.

For me it was a small task. A button, a query, a file. Maybe two hours with tests.

So before my 11:00 meeting I gave it to the agent with one sentence: "Add CSV export for invoices to the admin invoice page." Then I went to the meeting.

When I came back, the pull request was there. Dana had seen the title in Slack and was already happy.

I opened it.

63 files changed. 2,140 lines added, 1,870 removed.

## A button with 63 files

I scrolled for a while before I found the button.

On the way, the agent had done a lot of things. It created an `ExportStrategy` interface with three implementations, for CSV, JSON and "future formats". It moved `InvoiceRepository` into a new package called `billing.infrastructure.persistence`. It converted eleven old Java DTOs to Kotlin data classes, "for consistency with the rest of the codebase". It renamed `customerId` to `accountId` in four places, "to align with the domain language". And it added a new CSV library to the Gradle build.

All tests were green. The summary at the top of the PR was polite and very proud of itself.

I was frustrated, and I will be honest, also a bit tired already. None of these changes were crazy on their own. Some were even good ideas. But nobody asked for them, and I could not review 63 files properly by Thursday. The rename alone touched a query that our nightly reporting job uses. Green tests did not tell me anything about that job, because that job has no tests. Yes, I know.

I wrote back to Dana: "Not done. The PR is open, but it is much bigger than it should be. I need to make it smaller first."

She answered with a question that I liked: "Isn't bigger better? It did more work, no?"

## Deleting 2,000 lines that looked fine

My first instinct was to save it. Keep the button, revert the rest, file by file. I started. After twenty minutes I had reverted the rename, and two tests broke, because the new `ExportStrategy` already depended on `accountId`. Everything was connected to everything.

So I stopped. I closed the branch and deleted it.

It felt strange to delete 2,000 lines that looked fine. It also felt like the right move. Untangling an agent's big diff costs more than letting the agent do the small one again. The code is cheap now. My review time is not.

Then I wrote a different prompt. Not longer for fun, but with a fence around the work:

```
Task: add CSV export for invoices on the admin invoice page.
Do not write code yet. First give me a plan:
1. Every file you will change or create, with one line why.
2. Existing code in this repo you can reuse.
3. Refactors you would like to do. Only list them, do not do them.
Limits: no renames, no new dependencies, no changes outside
admin/invoices and the reporting module.
If you think you must break a limit, stop and ask me.
```

The plan came back in a minute. Four files. And then the agent surprised me in the good way.

Under "existing code to reuse" it wrote that there is already a `CsvWriter` in the reporting module, from an old feature where we exported user lists. It handles quoting, commas inside values, and a UTF-8 BOM so Excel shows umlauts correctly. I had forgotten that this class exists. I think I reviewed it two years ago. The first run had ignored it and added a whole new library instead.

> A bigger diff is not more work done. It is more work for the person who has to read it.

## The question I did not think about

The second surprise came when it wrote the code. Before finishing, it stopped and asked me something:

> "Customer names and phone numbers come from user input. If a cell starts with `=`, `+`, `-` or `@`, Excel may treat it as a formula. Some phone numbers in the seed data start with `+49`. Should I escape these cells?"

This is CSV injection, or formula injection. I knew about it in theory. I did not think about it for this button, on a Tuesday, with Dana waiting. A customer name like `=HYPERLINK(...)` in an export for a finance team is exactly the kind of thing you want to stop before it happens. And even without bad intent, a phone number like `+49 89 1234` can be shown as a broken formula in Excel.

We agreed on a small, boring fix:

```kotlin
private val formulaStarts = setOf('=', '+', '-', '@', '\t', '\r')

fun safeCell(value: String): String =
    if (value.firstOrNull() in formulaStarts) "'$value" else value
```

I asked Dana what tool the customer's finance team uses. Excel, of course. So the apostrophe prefix was fine for them. I added a test with three ugly values: a formula, a phone number and a name with an umlaut.

The final PR: 4 files, around 180 lines, with tests. I reviewed it in fifteen minutes and actually understood every line. It went live on Wednesday afternoon. On Thursday Dana showed the export in the call, and the customer's finance lead opened it in Excel while they were still talking. Dana told me later that this was the best part of the call. Nobody talked about the strategy pattern.

## Answering Dana's question

On Wednesday I went to Dana's desk to answer her question properly, because it was a fair one.

I said: imagine you ask a new colleague to send one email to a customer. He sends the email, and also rewrites your email templates, renames the folders in your inbox, and changes the signature for the whole team. All of it maybe nice. But now you must check everything before the customer sees anything, and you don't have time.

She laughed and said: "Okay. So small is not lazy."

Small is not lazy. Small is something you can check.

I did not throw away the agent's ideas completely, though. I asked it to write the refactors from the first run into a short list, with one sentence of reason for each. Two of them are now tickets. The duplicated date formatting between invoices and reporting is real, and we will fix it on a calm day, in its own PR, with its own review.

## What I do now

1. **Plan first, with a file list.** Before any code, I ask for every file the agent will touch and why. Reviewing four lines of plan is much faster than reviewing 63 files of diff.
2. **Put a fence in the prompt.** No renames, no new dependencies, a clear folder boundary, and "stop and ask" if it needs to cross. Agents follow limits quite well when you actually write them down.
3. **Ask what already exists.** "Which existing code can you reuse?" found our old `CsvWriter` and saved a new dependency. The agent can search the repo faster than I remember it.
4. **When the diff is much bigger than the task, delete it.** Don't trim. Restart with a better prompt. It is cheaper, and you keep your evening.
5. **Give non-technical colleagues a status they can use.** "PR is open" sounds like "done" to most people. Say what is left and when they can show it to the customer.

I still don't know how to make the first run small by default. I added the limits to our `CLAUDE.md`, and it helps, but sometimes the agent still gets ambitious when a task touches old code. Maybe old code just looks like an invitation.

How do you keep your agent from fixing the whole house when you asked for one light switch?
