← All articles

Before your developers use AI coding agents, prepare the code

Short answer

AI coding agents work reliably only in code they can read and check. Before rolling them out, give the code a clear structure, one consistent way to do each common task, and automated tests the agent can run itself. Start with the part of the system your team changes most often.

If your company has its own software, your developers have probably tried AI coding agents by now. The first impression is often mixed: impressive on a small, new project, unpredictable on the system your business actually runs on. A change that looks right breaks something elsewhere. The agent invents a fourth way of doing what the software already does three ways.

It is tempting to conclude the tools are not ready. More often, the code is not ready. An agent works from what it can read. If the code is inconsistent and nothing checks its work, it has no reliable way to know what "correct" looks like.

Much of the work of adopting these tools well is not in writing better instructions for the agent. It is in restructuring the code so an agent can work in it reliably. Three things matter most.

1. A clear structure

An agent, like a new developer, learns your system by reading it. When responsibilities are scattered, with business rules in the user interface, database calls in random places and one file that does everything, the agent cannot tell where a change belongs.

What helps:

  • One obvious place for each kind of code: data access, business rules, screens, integrations.
  • Smaller files and modules with a single purpose, so the agent can read everything relevant to a change at once.
  • A short written guide in the project's main folder that explains the layout, how to run the project and the rules that are easy to break. Many agents read such a file automatically when it has the name they look for.

2. Consistent patterns

If the code handles errors, dates or database access in several different ways, an agent tends to copy whichever example it finds. The inconsistency spreads.

Pick one way to do each common task, document it, and migrate the old variations over time. The goal is that any example the agent finds is a good example. This also makes the code easier for people to review, which matters more when more of it is generated.

3. Tests that catch mistakes before they ship

This is the most important of the three. An agent can produce a lot of change quickly. Without automated tests, every one of those changes has to be checked by hand, and the time saved writing code is lost reviewing it.

What helps:

  • Tests around the business rules that matter most: pricing, permissions, calculations, anything that costs money when wrong.
  • A single command that runs them, so the agent can check its own work before handing it over.
  • Checks that run automatically on every proposed change, before it reaches production.

Agents can also help write the tests, once someone has decided what they must cover, so the safety net itself can be built faster.

Where to start

You don't need to restructure everything before using an agent. Pick the part of the system your team changes most often and:

  • Write the project guide with the layout and the rules people keep breaking.
  • Add tests around that area's key rules and make them run with one command.
  • Clean up one inconsistent pattern that the area relies on.
  • Then use the agent on real tasks there and note where it goes wrong. Each mistake points to the next thing to clarify.

The goal is faster development without trading away reliability. If your developers tried AI tools and got messy results, look at the code before giving up on the tool. The same principle applies to data: AI only works as well as what it is given, as we explain in why AI projects fail.

Common questions

Why do AI coding agents make mistakes in our existing code?

An agent works from what it can read. In code with scattered responsibilities, several ways of doing the same thing and no automated tests, it has no reliable way to know what correct looks like.

How do we prepare a codebase for AI coding agents?

Give it a clear structure, one consistent way to do each common task, a short written guide in the project's main folder, and automated tests the agent can run with a single command.

Do we need to restructure the whole system first?

No. Start with the part your team changes most often, add a guide and tests there, clean up one inconsistent pattern, then use the agent on real tasks in that area.

Want this done in your company?

Book a free 30-minute call. We'll look at where your team loses the most time and whether automation is worth it.

Book a call

Get one useful email a month

New articles and free tools, in plain English. Nothing to buy.

Serge Nassar is the founder of SJN Solutions, based in Boisbriand, Québec. He builds integrations, data migrations and custom applications for companies with 20 to 200+ employees.