Why an AI Factory Writes Better Code Than a Prompt
Ask an AI to call an outside API and you will get code that works. It will also make the call right there, in the middle of the feature, because the prompt shows it nothing of the code around it: not the interface your team already wrote for that API, not the conventions, not the reasons behind them. Once, that is harmless. Across a team and a few months, the same API is called from dozens of places, each a little differently. That is why I believe the real reason to run an AI software factory is not speed. It is that the AI works with your codebase instead of beside it.
A real example from our own work shows it well. In one of our products, the code never calls the outside API directly. It calls one interface function, and that function holds everything about the API: how to authenticate, how to handle errors, which version to use. When the API changes, we update that one function, and every feature that uses it keeps working. Without the architecture and the plan in view, the AI would have written the call into every feature that needed it, and every change to the API would have meant finding and fixing all of them.
What a Prompt Cannot See
An AI only knows what is in front of it. A prompt carries the request, and that is all. The interface functions, the architecture and the decisions that shaped them are not in it, so the AI does the sensible thing with what it has and writes the whole thing itself.
The result is code that works on the day it is written and costs more every month after. Every direct call is one more place where a fix has to be made when the API changes, and the copies drift apart because nobody knows they are copies.
The industry data points the same way. GitClear analyzed 211 million changed lines of code from 2020 to 2024 and found that code blocks with five or more duplicated lines grew eightfold during 2024, the first year in which copy-pasted lines outnumbered moved lines, the lines developers reuse and reorganize (GitClear, 2025). That is a correlation across the whole industry, not proof of the cause, but it is the pattern you would expect when more code is written by tools that cannot see what already exists.
What an AI Factory Gives the AI
In our AI factory, code is not written from a prompt. It is written from a plan, and the plan traces back to the architecture of the product (I described the five steps the work runs through earlier). The agent that writes the code works inside the codebase, and it reads before it writes: the architecture and the plan for the piece of work, the instructions that come with the repository, and the register that says which part of the code owns what (I wrote about that register in Who Owns This Instruction?).
With that context, “call this API” becomes “call it through the interface that exists, and say where it lives”. The AI is still writing the code. The difference is that it now knows where it is standing.
We Tested It on Our Own Code
I wanted to know how big the difference really is, so we tested it on two real codebases: our own AI tooling, written in Python, and a C++ application we build. We chose C++ on purpose: it is not the easiest language to work in, even for an AI, so it makes a fair test. We wrote twenty everyday requests the way a developer would ask them, from reading the credential a script needs to call an API to a shared user-interface control. Each asked for something the codebase already has, and none named the existing code: turn what a user typed into a pull request number, list the files a pull request changed, add a rotary knob to the user interface, write to the application’s log.
The same model answered every request in three ways, three times each, for 180 answers in total. A second model then graded every answer blind, without knowing how it was asked, on one question: does the answer use the existing code, or write its own?
Without the codebase, the AI wrote everything itself. The three reuses were all the same request, where our installed tooling already told the AI how to do it.
Access to the codebase helped, but unevenly. In the C++ application, where shared code sits in one obvious folder, the AI found it in 16 of 24 answers. In our tooling, where shared code lives inside the parts that own it, it found it in 4 of 36. Several answers even recommended our existing code and then wrote their own next to it.
With the factory’s context, the AI reused the existing code every time, in both languages and both codebases, and named the file it used.
I want to be honest about the limits. One model answered and one model graded, the twenty requests were chosen where shared code exists, and the factory’s working rule was given in the request rather than through a real plan. It is a small test, but the gap is not small.
The Same Lesson as Our Learnings
This result felt familiar. I have written about coaching the AI once. In that test, general coding lessons made no difference, because the model already knew them. Lessons about our own system took the corrections needed from 16 of 21 answers to none.
Code works the same way. The model already knows how to call an API, and every new release will write a slightly better call. What it cannot know is that you already have an interface for it, which part of the code owns it, and why it was built the way it was. That knowledge is not in anyone’s training data, and a better model will not bring it. It has to come from the context you give the AI.
Why Context Decides Whether AI Coding Lasts
Prompt-by-prompt AI coding is fast in the first month. By the twelfth, the codebase is full of code that each does a little of the same thing, and every change has to find all of it. My colleague Ville Houttu put it well: past 20,000 lines, AI stops being your shortcut and starts being your mess.
That number is not arbitrary. It comes from how much an AI can hold in view at once, its context window. Code runs at about ten tokens per line, a common industry estimate that our own two codebases match, so 20,000 lines is about the 200,000 tokens many models can work with. The number grows as context windows grow, but the problem does not go away.
Even when the whole codebase fits, reuse is not guaranteed. Our test showed it: with every file readable, the AI reused the existing code in 20 of 60 answers. To do better, you have to ask it every time to analyze the codebase for anything reusable before it writes. That has two costs. First, it consumes a lot of tokens, because the AI reads the same code again on every task. Second, there is no guarantee that every run reaches the same conclusion. In our test, 5 of the 20 requests reused the existing code in some runs and not in others, with the same model, the same request and the same codebase.
This is where the architecture and the plan do more than guide the development. They become a compact representation of the codebase itself: what exists, which part owns it, and where new work belongs. The AI reads a few pages instead of the whole codebase, and it reaches the same answer every time, because the answer is written down rather than rediscovered. That is how the factory way reused the existing code in 60 of 60 answers.
It only works if the representation stays true. An architecture that no longer matches the code is worse than none, because the AI will trust it. That is why it is critical that the system maintains the architecture, the plans and the code together, so that they never drift apart. In my view, AI coding without this context is not going to last as a practice. It produces code faster than a team can keep it in order.
Building that context is the work that turns AI coding from a shortcut into a way of working: an architecture the AI reads before it writes, plans that tell it where a piece of work belongs, and a clear owner for every shared part of the code, all kept current as the code changes.
None of this is exotic, and most of it is what a good engineering team already keeps for its people. An AI factory makes sure the AI reads it too, every time, and keeps it up to date.
What About a Codebase That Already Exists?
A fair question is what happens to a codebase that was never built this way. Most code a team works on already exists, and it rarely comes with an architecture and plans written for an AI to read.
The answer is that we still start with the architecture step. The only difference is the direction. Instead of designing the architecture from scratch, our AI factory analyzes the codebase and writes down what it finds: how the code is organized, which part owns what, and which shared code new work should use.
That is exactly the analysis every prompt with the codebase in context would have to do anyway, as described above. The difference is that we do it once, and the result is one document instead of a conclusion that is thrown away at the end of each task and reached again, perhaps differently, on the next one. From then on, the AI reads that document before it writes, and our AI factory updates it as part of its normal process, so the document stays current as the code changes.
This is nothing more complex than what a good engineer does when they join a team with an existing codebase. They study it and learn how it works before they start writing code to it. An AI factory asks the same of the AI, and makes sure what it learned is written down for every task that follows.
One Interface, Used Everywhere
Back to the API. In a codebase built prompt by prompt, every feature would soon call it in its own way, and the next change to the API would mean finding them all. In our AI factory there is one interface, used everywhere and fixed in one place.
We have built our AI factory at A-CX around that idea, and whether the AI actually works from the architecture, the plans and the ownership of the code is one of the areas we look at when we assess a team’s AI factory. If your team is generating code with AI and wondering how to keep the codebase in order, contact us. Let us know if you see the same pattern in your own code.