Insights

At DVT, we run regular online events focused on the latest technology trends within the IT industry and invite guest speakers to share their knowledge and insights on various topics. The DVT Insights Events aim to enlighten you, educate you and often, provide a new view on a burning issue within the technology space.
We taught AI our codebase. The hard part wasn't the model

We taught AI our codebase. The hard part wasn't the model

What we learned when we stopped asking AI to "write code" and started teaching it how our software works.

Donald Kimeu: Senior Software Engineer, DVT
Donald Kimeu: Senior Software Engineer, DVT

A note on context: the examples here come from a client engagement. Company, product, and specific tool names have been generalised, and no confidential or client-identifying details are included.

The demo always looks perfect

You've probably seen this: someone opens an AI coding tool, types "build this feature," and a few seconds later a working pull request appears. Buttons, API calls, tests — all there.

Then you drop that same AI into a real company codebase, one that's years old with its own history and habits, and the magic disappears.

It uses the wrong styling system. It builds a button that already exists somewhere else in the app. It calls an API endpoint that was never real. It puts test files in a folder that breaks the app when it builds. It tries to open a pull request on the wrong platform. It commits straight to a branch nobody is supposed to touch.

The AI didn't get worse. We just never told it how things work here.

This wasn't about building something from scratch. We were dropping an AI into a mature product with its own architecture, its own design system, its own tools, and years of decisions nobody wrote down. So the question we needed to answer was:

Can we make an AI act like a new engineer joining the team, not a stranger starting a blank project?

Our conclusion, stated plainly up front, is this: a good AI model is necessary but not sufficient. Reliable AI-driven engineering needs clear specifications the model can read, controls that enforce them automatically, and human oversight that never fully steps back. Everything below is the story of how we arrived at that, and what each piece does.

This isn't just our experience. A 2025 randomized controlled trial by the AI research nonprofit METR found that experienced developers in large, familiar codebases took, on average, 19% longer to complete tasks with AI coding assistants, despite expecting the tools to make them faster. They also accepted less than 44% of the AI's suggestions, spending the rest of their time reviewing and correcting output. The researchers measured open-source projects and we saw the same pattern in a commercial one: AI capability on its own doesn't translate into reliability inside a codebase the model doesn't already understand.

Writing code was never the hard part

Everyone talks about how good AI models are at writing code. The better question is this one:

Can the AI make the right call inside someone else's system?

That's much harder, for AI and for humans. A new engineer joining a company doesn't just learn to code. They spend their first weeks learning things nobody wrote down:

  • Which parts of the official architecture diagram are still true
  • Which components already exist, so they don't rebuild them
  • Which APIs are the real ones
  • Where tests are supposed to live
  • Which branches you're not allowed to touch
  • How releases happen
  • Which shortcuts will bite them in six months

A human engineer picks this up slowly, through conversations and mistakes. An AI doesn't have that luxury. It needs all of this written down somewhere it can read.

First we tried more rules. That didn't work.

Our first instinct was the obvious one: every time the AI did something wrong, we added a rule.

Don't use that styling system. Don't build new components. Don't touch the release branch. Don't invent APIs. Don't put tests there.

Eventually we had a giant instruction file with hundreds of rules, and the AI still managed to break one we hadn't thought of.

We realised that a long list of "don'ts" isn't the same thing as an architecture.

We needed one clear, authoritative document describing how our application works, not how a textbook says software should work, and not how we wished it worked. Just the truth, in one place.

We call it the SDD. The acronym gets used differently across the industry, so to be precise: in our case SDD stands for Spec-Driven Development document, not "software design document." It's the one file that describes, in plain terms, how the application is put together. Everything else, the instructions we give different AI tools, is just a short summary that points back to it.

This isn't a one-off idea we invented. Spec-driven development has become one of the more visible practices in AI-assisted engineering since late 2025, popularised largely by GitHub's open-sourced Spec Kit and adopted in various forms by other tooling vendors. We landed on the same principle independently: the specification, not the code, is the source of truth, and the AI's job is to generate and verify an implementation against it, not to invent one from scratch each time.

For example, our front-end code always flows the same way:

our front-end code always flows the same way

That's a small thing to write down. But it means the AI doesn't have to guess how to build a new feature. It can follow the same path every engineer follows, in order, every time.

One source of truth, not three different opinions

Once we had the SDD, we organised things like this:

Once we had the SDD, we organised things like this

If every AI tool has its own separate description of "how our app works," they'll eventually disagree with each other, and then the AI has to guess which one is right. We didn't want any guessing, so we made one rule simple and absolute:

If any instruction disagrees with the SDD, the SDD wins.

Boring rule. Exactly what you want in engineering.

Here is how these three pieces, the SDD, the agent workflows, and the automated checks, work together, since none of them does much on their own. The SDD defines what's true: the architecture, the approved components, the valid API contracts, the branch rules. The agent workflows (the slash commands described later in this piece) are the step-by-step processes that tell the AI when to consult the SDD and in what order to act, so it isn't rediscovering the rules from scratch on every task. The automated checks are the enforcement layer: they don't know anything about intent, only about whether the result matches what the SDD says should be true. Remove any one layer and the system degrades in a specific way. Without the SDD, the workflows have nothing authoritative to check against. Without the workflows, correct knowledge sits in a document nobody consults at the right moment. Without the checks, violations of the SDD can still reach production, because a rule nobody enforces is a suggestion.

The day the AI spent a fortune finding a dropdown

One of our more embarrassing moments: a small bug in a dropdown menu. A human engineer would search for the file, glance at it, fix it, done. A five-minute job.

The AI took a completely different route. It started exploring the codebase. Then it went digging for more context. Then it branched off into a side investigation. Then it re-read files it had already looked at.

By the time it fixed the bug, it had burned through roughly 36,000 tokens of context (the unit LLMs use to measure how much text they've read and generated) on a single dropdown fix.

That taught us something important: not every task deserves the same amount of effort. So we built two speeds:

For a small, well-understood fix: go straight to the file, read it, understand it, fix it, test it.

For something unfamiliar or bigger: explore the codebase, understand the architecture, trace how pieces connect, make a plan, build it, check it works.

More "thinking" isn't automatically better engineering. Sometimes the smartest thing the AI can do is simply open the file it was told to open and not go looking for adventure.

What the numbers show

We pulled the session logs and pull request history from the engagement to see what day-to-day work looks like under this setup. One limit up front: every session and pull request in this project came after we introduced the SDD in March 2026, so there is no before-and-after comparison to offer. What follows is a baseline of how the system behaves, not proof that it improved anything.

Agent sessions (103 sessions since the SDD was introduced)

Measure Result
Tokens per session (input + output), median 27,583
Tokens per session, average 69,012
Tokens in the heaviest session 734,060
Session length, median 38 minutes

Pull requests (109 created between 1 September and 2 November 2026, one front-end repository)

Measure Result
Completed / abandoned 104 / 5
Creation to merge, median 6 minutes
Creation to merge, average 260 minutes
Creation to merge, 90th percentile about 17 hours
Creation to merge, longest about 3.9 days
Merged within 10 minutes of creation 62 of 104

The shape tells us more than the averages do. Most work is small and quick: the median session used about 27,600 tokens, less than the roughly 36,000 the dropdown fix consumed on its own (not a controlled comparison, since a session can contain several tasks). A long tail of heavy work pulls the averages up: the heaviest session, a seven-hour UI fix and pull request, used more than 734,000 tokens. The average session length of about 15 hours is misleading for a similar reason, since some sessions were left open or resumed days later, so the median of 38 minutes is the better guide. Pull requests follow the same pattern, with a 6-minute median against a 260-minute average, and some of the fastest merges were small follow-up fixes.

What we have not measured yet: review rounds per pull request, defect or rework rates, and a pre-SDD baseline. A fast merge describes flow, not quality, so these figures say nothing yet about code quality. Those are the measures we want next, and they are the ones that would let us claim an improvement rather than describe a pattern.

The AI didn't know which tools we use

This one seems obvious once you see it happen, but it's easy to miss.

Our company uses a specific platform for tracking work and managing code, and it's split across two separate areas of that platform: one for tracking tasks, another for the actual code and pull requests.

The AI handled the task-tracking side fine. But when it came time to submit code for review, it reached for the tool it had seen a million times in its training: the "create a pull request on GitHub" command.

Except we don't use GitHub. At all.

The AI knows how software is built in general. It has no idea how your company does it, until you tell it, explicitly.

We had to spell out things like: which system owns tasks, which system owns code, which specific tool the AI should use for each, what counts as a valid pull request, and which branches are off-limits.

We also learned a subtler lesson about backup plans. We'd written a rule like: "If the pull-request tool fails, just tell the person how to do it manually." That sounds reasonable, but the AI started treating "explain it to a human" as an acceptable way to finish the job, even when the tool hadn't failed. We had to fix that: the fallback applies only when the tool really fails, not as an easy exit from the task itself, which was for the AI to submit the work.

Turning designs into code, without reinventing the wheel

We also connected the AI to our design tool (Figma), hoping for a clean pipeline: designer makes a screen, AI turns it into working code.

If you just ask an AI to "build what you see in this design," it will happily build brand-new versions of things that already exist. A new button. A new dropdown. A new header. All because it didn't know the real ones were already sitting in our codebase.

So we changed the goal. The design tool became a reference to check against, rather than a blueprint to copy directly. The actual source of truth is our existing library of components. We built the AI a simple list: here are the components we already have, Button, Dropdown, Header, Sidebar, and so on.

Now the AI's job isn't "recreate this picture." It's "find the piece we already built that matches this picture, and use that." A small shift, with a completely different and far better result.

Shortcuts became real workflows, not just quick prompts

We built a set of shortcuts like /fix, /feature, and /report that trigger the AI to do specific jobs. At first these look like typing shortcuts. They're something more useful: repeatable mini-processes.

For example, /feature walks the AI through the same steps every time: understand what's being asked, check it against our architecture, check the real API, check the design, build it, test it, double-check, prepare it for review.

That's not a clever prompt. It's a lightweight version of how a good engineer works. And because we wanted this to work the same way no matter which AI tool someone used, we saved these workflows with the code itself rather than in someone's personal notes. That way, if we ever switch AI tools, the workflow doesn't disappear with it.

Telling the AI "don't" isn't as strong as making it impossible

We had plenty of rules that said "don't do this." But a rule is just a suggestion unless something enforces it.

A failed automated check is a completely different kind of feedback. If the AI writes messy code, a code-quality check catches it immediately. If it breaks something, the tests fail immediately. If the code doesn't fit the system's structure, that fails too. And if it tries to push to a branch it shouldn't touch, the system simply rejects it.

That immediate, automatic pushback is far more effective than any written instruction. We started thinking of these as checkpoints the code has to pass through before it's allowed to go anywhere near production: quality check, test check, structure check, architecture check, and only then, review.

The AI is going to make mistakes. That's fine. What counts is building a system where mistakes get caught before they cause damage.

This isn't a hypothetical concern. Independent research from the code-analytics firm GitClear, which analysed over 200 million lines of code across thousands of repositories, found that as AI-assisted coding became widespread, code churn (the share of code altered or reverted within two weeks of being written) roughly doubled, duplication rose substantially, and genuine refactoring fell sharply. None of that shows up in a demo. It shows up months later, in a codebase that's harder to maintain. Automated gates counter exactly this pattern, catching the duplication, structural drift and quick patches before they're merged rather than letting them accumulate, as GitClear's data suggests they otherwise would.

Some traps are hidden inside the tools themselves

One example: our app uses a particular version of a web framework, and we discovered that if test files were placed in one specific folder, the framework would try to treat them as real pages and accidentally include them in the live app.

The obvious fix is "don't put tests there." The deeper lesson is that quirks of your specific tools are part of what the AI needs to know, and general knowledge about that tool won't tell it. A human who's worked in the codebase for a while just knows this. An AI trained on generic documentation has no way to know it unless someone writes it down.

This is why our SDD doesn't just describe the clean architecture. It also captures the scars, the weird stuff you only learn after something breaks in production.

Institutional knowledge is the missing piece

Everyone's talking about model quality, memory size, speed, and clever prompting tricks. Those all matter. But one variable gets far less attention: the stuff your team has learned the hard way.

The knowledge that says "we don't do it that way here" almost never lives in a README. It lives in old pull requests, failed releases, hallway conversations, and code review comments, in people's heads.

AI gives us a reason to finally write that knowledge down in a form a machine can use. For example:

The problem: test files in one folder accidentally get bundled into the live app. The rule: keep those tests somewhere else. The safeguard: the automated build fails if someone breaks this rule.

Once you write it that way, it stops being a story engineers tell each other. It becomes part of the system itself.

What "AI-first" means

I used to think "AI-first development" meant: give every engineer an AI assistant. I don't think that's enough anymore.

A real AI-ready engineering setup looks more like a whole system:

A real AI-ready engineering setup looks more like a whole system

The AI model is only one piece. Everything built around it is what makes it reliable.

The AI is a new team member, not a finished expert

After going through all of this, my view of the AI model itself got a lot less glamorous, and I think that's healthy.

Think of the AI as a new team member. A remarkably capable one, even by the standards of an experienced hire. It reads huge amounts of code fast. It writes quickly. It can investigate a bug. It can explain its thinking. It can even come up with a solution an experienced engineer wouldn't have thought of first.

But like any new team member, it doesn't automatically know your company. It doesn't know your architecture, your release process, or which mistakes your team already paid the price for.

You have to onboard it, the same way you would a person. Writing a 400-line list of instructions isn't onboarding. What teaches it is an environment where the right move is the obvious one.

None of this replaces human oversight

Everything above describes how we make the AI more reliable. None of it makes the AI accountable, and the two are not the same thing.

Every change the AI proposes still goes through human code review before it reaches production, the same as any other change would. The automated gates (quality checks, tests, structure checks) catch a lot, but they check whether code fits the pattern, not whether it's the right thing to build, or whether it introduces a security risk a linter can't see. That judgment still sits with a person.

We also treat AI-written code as needing the same security scrutiny as any other code, sometimes more, since the AI has no instinct for which shortcuts create risk it just hasn't seen labelled as risky. And when something ships that shouldn't have, the accountability sits with the engineer who reviewed and approved it, not with the tool. Encoding architecture and rules into the system reduces how often mistakes happen. It doesn't remove the need for someone responsible to check the work.

The takeaway

If your organisation is bringing AI coding tools into a real, existing codebase, don't start with "which AI model should we use." Start with this question instead:

What would we tell a new senior engineer before we let them touch this codebase?

Write that down. Make it something a machine can read and check against. Connect it to your real tools. Put your most important rules behind automatic checks, not just written warnings. Give the AI a quick path for easy tasks and a careful path for hard ones. And every time it makes a mistake, don't just fix the code, fix whatever let the mistake happen in the first place.

That's the shift that turns an AI coding tool from fancy autocomplete into an actual part of how your team builds software. None of it works, though, without the three things in combination: a specification clear enough for a machine to check against, controls strong enough to enforce it automatically, and people who still read the output before it ships. A better model helps. It isn't the part that makes any of this reliable.

We're still not fully there ourselves. Some of this is solid, some is still experimental, and we're still finding gaps. But the direction is clear:

Don't try to make the model smarter. Make your codebase clearer.

Because in a mature system, the most useful AI collaborator is rarely the one that knows the most code. Usually it's the one that knows exactly which code it's allowed to touch.


References

  • METR. Measuring the Impact of Early-2025 AI on Experienced Open-Source Developer Productivity (2025) — randomized controlled trial finding a 19% slowdown and sub-44% suggestion acceptance rate among experienced developers using AI coding assistants on familiar codebases.
     
  • GitClear. AI Copilot Code Quality Report (2025) — analysis of over 200 million lines of code showing increased code churn and duplication, and declining refactoring activity, correlated with AI-assisted coding adoption.
     
  • GitHub. Spec Kit (open-sourced September 2025) and related industry coverage of spec-driven development as an emerging AI-assisted engineering practice.

Related Articles