Legacy code migration with AI agents works best when the agents first recover what the old system actually does, write it down as a specification with tests, and only then rebuild it on the new stack. Done in that order, migration stops being a rewrite from guesswork. In a recent proof run we used this approach to rebuild a 350,000-line Java and JSP application in TypeScript in five days.
This article sets out how we run that process and how to try it on one of your own systems. It draws on our Agentic Legacy Code Modernisation playbook and on the migration work described in our public sector case study.
Why legacy code migrations go wrong
Large rewrites tend to fail on requirements. The people who wrote the original system have often moved on, the documentation stopped matching the code years ago, and decades of edge cases live only in the source. So the rewrite guesses at the rules, and nobody notices which ones were dropped until users do.
Michael Feathers put the underlying problem plainly in Working Effectively with Legacy Code (2004), where he defined legacy code as code without tests. Without tests, nobody can say with confidence what the system does today, and a migration has nothing to check the new version against. AI agents are now good at closing that gap, which is a large part of why we think legacy modernisation is where much of the value in enterprise AI sits.
Recover the specification before you migrate legacy code
The running system is the most accurate record of its own rules that you have. Every rule that matters is already in the code, the database schema and the way people use the application, even where the documents say otherwise. So the first job in an agentic migration is to read all of that and write it down.
In practice, agents analyse the code structure, extract the business logic, map the data flows and flag rules that look compliance-relevant, such as how personal data is handled. They also generate characterisation tests, which pin down how the current system behaves, odd corners included. Our playbook takes test coverage from zero to more than 80 percent this way, without relying on anyone's memory of how the system was meant to work.
Recovered behaviour still needs a person to explain it, though. Say your returns policy is 30 days and the system has been accepting returns on day 35. That is either a decision somebody made or a bug nobody caught, and only someone who knows the business can tell you which. So every recovered specification goes to the client for sign-off before anything is rebuilt. In SpecOps, our specification tool, each line records whether it came from an agent or from a reviewer accepting the agent's proposal, and approvals attach to a version number, so a substantive edit marks earlier sign-offs as stale.
Choosing between maintain, strangler fig, rewrite and replace
Once the specification and tests exist, the next decision is what to do with the system. We score each application against eight criteria and choose one of four routes: maintain it as it is, migrate it gradually with a strangler fig approach, rewrite it, or replace it with an existing product. Some systems come out of that scoring as better left alone.
The strangler fig pattern, which Martin Fowler described in 2004, moves functionality piece by piece from the old system to a new one until the old one can be switched off. It suits systems that are too large or too critical to cut over in one go. A full rewrite suits a contained application whose recovered specification is complete enough to rebuild from, and that was the situation in the example below.
A worked example: 350,000 lines of Java migrated in five days
A large public sector organisation in Singapore asked us to help migrate its legacy systems after working with us on agentic delivery and training. Several of its internal applications were old, thinly documented and costly to change, and few of the people who built them were still around to explain them.
As a proof run on a test project, one engineer working with up to 20 sub-agents per stage rebuilt a 350,000-line Java and JSP application in TypeScript, reaching a running development build in five days. Our own projection for doing the same work by hand was three engineers and close to a year. Production release was outside the scope of the run, which was there to show that agentic migration holds up at real size.
The run followed ACDC, our Agent Centric Development Cycle, in which the specification comes before the code. When validation fails, the work goes back to the specification before anyone touches the code, for the reasons we set out in Spec Drift: Fix the Spec, Fix It Once. On a migration that matters even more, because the specification is the only thing that ties the new system to the old one.
Why we migrated the old design before the new one
Midway through that work, the product managers we had trained redesigned the application themselves and asked us to build their new design in place of migrating the old one. It was a reasonable request, and we advised against it.
Our recommendation was to migrate the existing system as it stands first, then make their improvements once it runs on the new stack. If the platform and the behaviour change at the same time, any difference in the new system could be a migration defect or an intended change, and the recovered specification can no longer settle which. Keeping the two steps apart keeps the specification useful as a check.
The redesign still has value. Once the migration is signed off, it becomes a set of changes against a known baseline, and the same specification and tests show exactly what moved.
How to start a legacy code migration with AI agents
Start with one system. Pick an application that is costly to change and thinly documented, but contained enough to finish, and have agents recover its specification and characterisation tests before anyone writes new code. Keep a list of the behaviours your team cannot explain, like those day-35 returns, because that list is a good early measure of your migration risk.
Then put the specification in front of the people who own the business rules and get it signed off against a version. Only after that should you choose a route and start rebuilding. Our playbook sets out the full sequence, and if you have a system in mind, let's talk: https://www.mission.plus/contact-us


