11 min read
An agent harness for an existing codebase
What an older product needs in place before AI agents can ship changes into it
Mario Jurić · Posted on December 4, 2026
An agent harness is everything around a language model that turns it into a dependable worker: the instructions it starts with, the tools it may use, the checks that stop a bad change, and the record of what it did. On a new project the harness and the code grow up together. On an existing one, the harness has to be fitted to code that was never written with agents in mind, and that is a different job.
This post is about that job. It draws on a year of running every project we ship, old and new, through our own delivery engine, and on the repository of this website, an older Next.js and Payload codebase where Claude Code now does much of the routine work.
Why agents struggle in old code
The research is consistent about where the gains are. On green-field work, the blank file and the first version, AI speeds a team up by something like a third to a half. On complex changes to code that already exists, by ten percent or less. We went through the sources in the year software got cheap to build and expensive to own.
Three things cause most of the gap, and a harness can do something about each.
The agent copies the nearest example. An older codebase usually holds three generations of the same pattern: the way it was done in the first year, the way someone started doing it later, and the way the team agrees it should be done now. An agent looking for an example will find whichever is closest to the file it is editing, and it will copy that one faithfully.
The agent prefers new code to old. A model satisfies the request in front of it, and the cheapest way to do that is fresh code that works now. Extending a helper written four years ago means reading it first. Writing a new one means not having to. Left alone, an agent will leave you with both.
The rules are not written down. Which folder is legacy and must not be touched, which table is read by a reporting job nobody remembers, which API a partner still calls: in an older product, that knowledge lives with the people who have been around longest. An agent cannot ask them.
What to put in place, in order
1. Write down the conventions that matter, and only those
Start with a short instruction file at the root of the repository: what the product is, how the code is laid out, where new code goes, and the handful of conventions that touch nearly every task. On this website's repository that file says, among other things, which typography components every page must use, which colour tokens replace raw values, and which fonts exist on purpose.
Keep it short. The more rules an instruction file holds, the less reliably a model follows any of them; we went through the measurements in the software factory essay. Rules that only matter in one corner of the codebase belong in path scoped rules that load when a file there is touched, not in the file every session reads.
2. Name the legacy, and fence it
Decide which parts of the codebase are the model to copy and which are history. Say so in writing, in the folder itself, and back it with a check where you can: a hook that refuses edits in a folder marked as frozen, or one that blocks a deprecated import from being added anywhere new. An agent that cannot write the old pattern stops spreading it.
3. Turn the mistakes you have already seen into checks
Every older codebase has a list of mistakes that have happened more than once. Each one is a candidate for a deterministic check that runs every time, whatever the agent decides.
On this website, two examples. Every page must appear in the sitemap, so a script runs before every build and fails it when a page route is missing. Internal links must end with a trailing slash, because a link without one costs a redirect, so another script checks every link in the code. Neither rule depended on an agent remembering it once the check existed. A commit hook runs the linter in strict mode, so a warning is treated as a failure.
Do not try to predict where agents will go wrong. Watch where they do, and add a check exactly there. Then delete the prose rule the check replaced.
4. Give agents lanes
In a large existing codebase, the most damaging changes are the ones that wander: a frontend change that quietly edits a database query, a fix in one module that rewrites a shared helper. Split the work along the lines the architecture already has, give each agent the files it may touch, and let a hook refuse the rest. In our own engine, the frontend agent cannot touch a route the server agent has not prepared.
5. Put a spec in front of every change
An older codebase is mostly decisions nobody wrote down. Every change an agent makes should start from a short spec in the repository that says what changes, why, and how it will be checked, and that links to the earlier decisions it must respect. Over time the specs become the written history the codebase never had. We cover the method on a real project in spec-driven development in practice.
6. Review every change against the same rules
Have a separate agent read each change against the same instruction file, rules and spec the implementer was given, and refuse to close the session until it has. The implementer and the reviewer must share one source of truth, or the review grades against rules the work was never asked to follow.
7. Teach the workflows as skills
Older products have workflows that happen often enough to matter and rarely enough to forget: adding a page to a set of landing pages, rebuilding a screenshot, writing a case study. Each of those is a skill on this website's repository, loaded only when the task calls for it. A skill carries the steps, the checks and the mistakes made last time, which is exactly what the person who used to do it carried in their head.
What the harness does not fix
Tests that test nothing. If the codebase has few tests, an agent asked to add them will write many, and many of them will pass without checking anything that matters. Decide what a meaningful test is for each kind of change and review the tests as carefully as the code.
Functional correctness. A harness catches a change that breaks a rule. A change that follows every rule and does the wrong thing can still get through. A person who knows the product still reads what ships.
Review load. Agents produce changes faster than people read them. Smaller changes, each tied to a spec, make review quicker. They do not make it optional.
Where to start this week
- Write the short instruction file, and read it as a newcomer would.
- List the three mistakes that have reached production more than once, and turn each into a check that runs on every commit or every build.
- Mark one legacy area as frozen and enforce it.
- Require a spec for the next ten changes, however small.
- Read every agent transcript for a week and note each place it went wrong. That list is your next set of checks.
If you would rather have the harness built for your codebase, that is work we do: agent harness development for one agent that has to run unattended, and AI software factory development for a team's whole delivery process.


