AI engineering · 1 November 2026 · 8 min read
Build it twice: why AI coding agents should throw work away, not patch it forever
When code is cheap to write, the expensive mistake is patching a flawed design forever. Here's how we use AI agents to build fast, keep the lessons, throw the code away and rebuild it properly.
- AI engineering
- AI coding agents
- Prototypes and MVPs
- Refactoring
- Architecture
- For CTOs and tech leads
- For founders
In this article
The short answer: AI agents have made writing code cheap, but most teams still treat code as precious. So when a design turns out to be wrong, they patch it, and agents will keep patching it for as long as you let them. A better habit is to build the first version fast, write down what it taught you, throw it away and build it again from those lessons. The code is the cheap part now. The understanding is what you keep.
We throw away far more code than we used to, on purpose, and our systems are better for it. Here's how we decide when to stop patching, and what we keep when we start again.
Why do agents patch instead of stopping?
Give an agent a bug and it will fix the bug. Give it the next one and it will fix that too. What it won't do, unless you ask, is step back and say: "These are all the same problem, and the problem is the design."
That's not a flaw in any particular model. An agent works on the task in front of it, and "fix this" is a narrower, more finishable task than "question whether this should exist". So the fixes pile up. A special case here, a retry there, a flag that switches off the part that keeps breaking. Each one is reasonable on its own. Together they bury a bad decision under layers of code that all depend on it.
With people, this eventually stops because someone gets tired of it. Agents don't get tired. They'll patch a flawed design for as long as you keep asking.
How do you know it's time to stop?
These are the signs we watch for. Any one is a reason to pause. Two or more usually means the design is wrong, not the code.
The same area keeps coming back. It was fixed last week, and the week before.
The work goes back and forth. Changes are reverted, or a value flips one way, then back, then the first way again.
The same thing exists twice. Two copies of a mechanism, each fixed separately, slowly drifting apart.
Fixes need special cases. "Except when…" appears in the code more than once.
Nobody can explain it in a sentence. Not the agent, not the person directing it.
The checks around the code grow faster than the code. More effort goes into proving the thing works than into the thing.
What does building it twice look like?
Here's a recent example. We needed a new web front end for a real-time data platform: live charts, streams of events, a lot of moving parts. Instead of planning it all up front, we had agents build an exploratory version quickly, to find out what the real problems were.
It did its job. In a few days we had a working app and a long list of things we'd got wrong:
The first click crashed it. Moving from one page to another ran a cleanup on a chart that was already gone. Every check had opened one page at a time, and none had clicked through the app the way a person would.
The same decisions kept changing. One scrollbar's width was changed eight times, and several commits were reverted outright.
Mechanisms were written more than once. Retrying with longer and longer delays existed in three separate places, each slightly different.
The rules were broken quietly. A missing value was skipped instead of refused, and a negative age was quietly turned into zero: code made to look safe by hiding errors.
The important parts had no tests. The pieces that handle reconnection, gaps and failures were the least tested of all.
At that point, the old instinct would be to fix those things one by one. We didn't. We wrote the lessons down, area by area: what to keep, what to change, what to drop and what was still undecided. Then we archived the exploratory version and started the rebuild from those lessons.
The rule for the rebuild is simple: the first version is the reference, never the source. Every piece is written again, and code is copied across only when a review says it already meets the bar. The archive is still there to look at. It just isn't the starting point.
We've done the same with bigger things. We once built an internal developer tool almost entirely with agents, and it grew far beyond what the problem needed until it collapsed under its own weight. That rewrite started with a postmortem that named the one root cause, listed every way it showed up, and, just as importantly, listed what the first version got right and should keep. Our real-time market-data platform is itself a rebuild, started after a first version had taught us what the hard parts really were.
Isn't throwing work away wasteful?
It used to be. When a person spent months writing a system, throwing it away meant throwing away months.
Agents change the maths. Writing the code is now the fast part. What took the time in that first version was finding out what the problems were, and you don't lose that by deleting the code. You lose it by not writing it down.
The waste is the other way round now. Patching a flawed design means paying for it on every change, forever. Each patch makes the next change harder to get right, and harder to review.
Seven rules for iterating with AI agents
1. Treat the first version as an experiment
Say upfront that it's there to teach you something. That makes it much easier to throw away later, because nobody has promised it will last.
2. Write down the lessons before you delete anything
A rebuild without written lessons is just doing it again. Record what went wrong, why, what to do instead, and what was right and must be kept. If you can, name the one cause behind most of the problems. There usually is one.
3. Rebuild from the lessons, not from the old code
The old version is something to look at, not something to copy. If you start from the old code, you'll bring its assumptions with you.
4. Tell agents when to stop
Our agents are told to stop and report, not try again, when a fix starts to look like a pattern: the same area fixed again, a change undone, a second copy of something that already exists. Things that touch money, security, production or anything that can't be undone always stop for a person. An agent that stops and says "I think the design is wrong here" is doing its job.
5. Build a mechanism only when its first real caller arrives
Most over-built systems are built for imagined needs. Generalise when there are two real cases, not one and a guess.
6. Keep each step small enough to review
A few hundred lines that someone has actually read and tried beat thousands that nobody has. Small steps also make it obvious when something keeps coming back.
7. Decide the look before you build it
For anything visual, show options side by side, as screenshots, recordings or component previews, and commit only the one that's chosen. Flip-flopping in the code is the most expensive way to make up your mind.
What does this mean for your business?
Most businesses treat code they've paid for as something to protect. That made sense when every line was expensive. With AI agents, a rebuild that once took a quarter can take weeks, and the expensive part is now the time your team loses working around a design that's wrong.
If the same part of your product keeps needing fixes, that's usually a sign to pay for a rethink, not another patch. And when you're unsure how to build something new, budgeting for a quick first version that's meant to be thrown away is one of the cheapest ways to buy certainty. The question to ask your team isn't "can we save this code?" It's "what did the first version teach us?"
What should your team do first?
Look at your last month of changes. Find the area that's been fixed most often, and ask whether it needs another fix or a rethink.
Write one lessons document for something you'd build differently today, even if you never rebuild it.
Give your agents a stop rule. Even one line in their instructions, "if you're fixing the same thing twice, stop and explain why", changes how they behave.
Try one spike. Next time you're unsure how to build something, have agents build it fast, on the understanding that it will be thrown away.
FAQ
When should you rewrite instead of refactor? When the problems all come from the same decision. If fixing one thing keeps breaking another, or the fixes all need special cases, the design is the problem, and refactoring just rearranges it. If the problems are scattered and unrelated, refactor.
Do AI coding agents make rewrites safer? They make rewrites much cheaper. Whether they're safer depends on what you carry across: written lessons, a clear definition of "correct" and independent checks. Without those, you'll rebuild the same mistakes faster.
How do you stop an AI agent going round in circles? Give it explicit stop conditions, and make stopping a valid outcome. Ask it to report when it's fixing the same area again, undoing its own work or duplicating something. Then have a person decide whether to carry on or step back.
What is a spike in software development? A short, deliberately disposable piece of work to answer a question: will this approach work, and where are the hard parts? With agents, a spike can be a fairly complete working version, which makes what it teaches you much more concrete.
We embed engineers who know when to build, when to stop and when to start again. If your team is stuck patching something that should have been rebuilt, we're happy to talk.
Related articles
I built a prototype with AI. How do I make it real?
Make it real to the people who would pay for it before you make it real as a product. Show it on invented data, watch what they do, then decide whether to harden it, rebuild it or drop it, knowing what real and regulated data will ask of it.
For Founders, Product and innovation leads
8 August 20269 min read
How do you clean up code that’s too risky to change?
One piece at a time, without changing what the customer sees, adding tests as you go so each step can be proven safe. A full rewrite is rarely the answer.
For CTOs and tech leads, Engineers
21 October 20264 min read
Guardrails, not guidelines: how to stop AI coding agents breaking your architecture
Coding agents are brilliant at the task in front of them and blind to the system around it. Here's why they quietly erode your architecture, and the guardrails we use to stop it.
For CTOs and tech leads, Engineers
21 July 20268 min read
Read something that sounds like your problem?
A free 15-minute intro with our CEO. Bring the article, and he’ll tell you which service fits, if any. If a spreadsheet and two rules would do the job, we’ll say so.