Hand a legacy codebase to a cloud agent
For engineers
Legacy code, cloud and IDE agents, estimation, team practice and headless runs.
Hand a legacy codebase to a cloud agent in this order: learn what the code does and why, pin that behaviour with tests, size the work as a range, write tickets a sandbox can finish, and let shared rules, review limits and capped headless runs carry the rest.
The case
Corvane Freight runs billing-core, an invoicing service started in 2011. It is Java 8, about 210,000 lines, nine Maven modules, with 31 percent line coverage. On 2 December 2026 the CTO asks for Java 21 by the end of January and for the hand-rolled RoundingHelper to be replaced by standard BigDecimal calls. Six engineers will do it, using an IDE agent in their editors and a cloud agent that opens pull requests from a remote sandbox.
The tempting move is one ticket, "Upgrade to Java 21 and fix rounding", assigned to the cloud agent. It will come back with a large pull request and a green build. For an invoicing system, green is not the same as unchanged, and nobody can review that diff in an afternoon. Six skills decide whether this goes well.
Learn the code first (code-ide-agents, code-legacy)
An IDE agent answers from what it can see. Open tabs are a small part of nine modules, so attach the folders and symbols that matter, such as TotalsCalculator and the totals package, and ask for the call chain, not a summary. Then check three claims in the map against the source. An agent's module map is a draft.
Legacy code hides decisions. The Norwegian VAT line rounds half down, which looks like a bug. git log -L and the ticket id in the commit show that BILL-212 added it in 2016 to match a tax office letter. Read history and tickets before an agent is allowed to "fix" an oddity.
Pin behaviour before you change it (code-legacy)
A characterization test records what the code does today, odd results included. Run the current build on anonymised sample invoices and let the agent write tests that assert those exact outputs. Review them for tests that assert what someone believes should happen. A test that fails on the old code is not a characterization test. After that, refactor in small steps, one commit each, tests run after every step. Be wary of code that looks dead: LegacyTaxTable has no Java callers, yet an XML file in the resources folder still loads it by name.
Size it as a range (sdlc-estimation)
Agents make boilerplate, tests and mechanical edits faster. Design, integration, review and waiting stay slow, and two reviewers who each read about eight pull requests a week cap the whole project. Give a range, for example two to five weeks, with a two-day spike on the reflection and XML configuration first. Measure the effect later by comparing similar tickets with and without an agent, because felt speed-ups and measured ones can differ, as the METR study of experienced developers showed.
Write tickets a sandbox can finish (code-cloud-agents)
A cloud agent works alone in a remote environment, so the ticket carries everything: the scope, the files, what must not change, and a done check it can run, such as mvn -q verify passing with the characterization suite unchanged. The setup script installs the JDK and dependencies, and the network allowlist must include every host the build needs. Give it well-specified, testable work, such as replacing 14 deprecated date calls. Keep open design questions and anything needing local hardware for people.
When the pull request arrives, review in risk order: does it match the task, did CI run everything, and did the agent edit or delete tests to get green? An agent that deletes the failing test has not fixed anything.
Agree the rules (sdlc-team)
Put shared rules in a committed AGENTS.md: the verify command, protected files, the rule on characterization tests. Personal preferences stay in personal settings. Set limits on agent pull request size, require author self-review, and keep a different person approving every merge. Track lead time, change failure rate and rework, not lines generated.
Run it unattended with caps (harness-headless)
A nightly job can run the agent headless to triage or fix failing tests. Pre-approve only the tools it needs, cap turns and wall-clock time, save the transcript, and validate any machine-readable result against a schema before acting on it. In CI, never give a write-scoped token to a workflow that checks out fork code or pastes pull request text into the prompt. The agent opens a branch; a person merges.
What goes wrong
- The agent upgrades and "fixes" rounding in one change, and Norwegian invoices shift by a cent.
- A failing test is edited or removed, and the report says all tests pass.
- Progress is reported as pull requests opened, while few are merged.
- A nightly run loops on a flaky test for 90 minutes because nothing caps it.
Steps
Map the code with an IDE agent
Attach the folders and symbols that matter, not just the open tabs. Ask for the call chain from the invoice endpoint to
RoundingHelper, then check three claims in the answer against the source before you trust the map.Context for the IDE agent - user
@TotalsCalculator @billing-core/totals Trace how an invoice total is computed from InvoiceController to RoundingHelper. List each class on the path with the file and line where it calls the next one.
- assistant
InvoiceController.create (line 54) -> InvoiceService.build (line 112) -> TotalsCalculator.sum (line 41) -> RoundingHelper.vat (line 40). CreditNoteService and ReportExport also call RoundingHelper.vat.
- user
Recover why the odd rounding exists
Follow the half-down rounding line through git history to its ticket. BILL-212 from 2016 shows it was deliberate. The rule stays, and the agent is told so in the ticket.
Pin current behaviour with characterization tests
Run the current build on anonymised sample invoices and have the agent write tests that assert exactly what comes back today. Review each expected value against a real run of the old code.
Characterization test, current behaviour src/test/java/com/corvane/billing/characterization/RoundingHelperTest.java
@Test void norwayVatRoundsHalfDown() { // observed on production build 8.41 assertEquals(new BigDecimal("12.34"), RoundingHelper.vat("NO", new BigDecimal("12.345")));}Estimate as a range with a spike
Give a range that includes agent retries, review and integration. Start with a short spike on the unknowns, here the reflection and XML references, and update the range when it ends.
Estimate for the CTO Goal: Billing-core on Java 21 with the rounding helper replaced
- Spike (2 days): search code and resources for reflection and XML class references
- Characterization tests for three callers (3-5 days including review)
- Java 21 upgrade in small pull requests (5-10 days, two reviewers)
- RoundingHelper replacement with finance sign-off (3-6 days)
- Range: two to five weeks, re-estimated after the spike
Write a ticket the sandbox can finish
One narrow change per ticket, with files, a rule that must not change, and a done check the agent can run. Make sure the sandbox can reach every host the build needs.
Ticket BILL-871 Scope
Upgrade billing-core to Java 21 only. Do not change RoundingHelper or any file under src/main/resources.
Must not change
Norway VAT rounds half down (BILL-212). The characterization suite must pass unchanged.
Done when
mvn -q verify passes. Do not edit or delete tests under characterization/. If a test fails, stop and describe it in the pull request.
Set team rules and review limits
Put the verify command and the protected files in the committed
AGENTS.md. Cap agent pull requests, require self-review and keep a second person approving every merge.Agent pull request rules Billing-core agent rules
- Agent pull requests stay under 400 changed lines.
- The requester reads and self-reviews the diff before asking for review.
- A code owner other than the requester approves every merge.
- Rounding and tax code need a second code owner.
Run the nightly job headless, with caps
Pre-approve only the tools the job needs, cap turns, save the output and push to an agent branch for a person to review. Never push to main from an unattended run.
Nightly fix job ci/nightly-fix.sh
set -euo pipefailtimeout 40m claude -p "Fix failing tests in billing-core, do not edit characterization tests" \ --allowedTools "Bash(mvn:*)" "Edit" "Read" \ --max-turns 25 --output-format json > run.jsongit push origin HEAD:agent/nightly-fix
Skills this scenario uses
Where to study
- Legacy Modernization meets GenAI (martinfowler.com) (opens in a new tab)ArticleFree
How generative AI helps understand and migrate legacy systems in small, checked steps.
- Characterization test (Wikipedia) (opens in a new tab)ArticleFree
Defines tests that pin the current behaviour of code before it is changed.
- About GitHub Copilot cloud agent (opens in a new tab)DocsFree
How an agent works from an issue in a remote environment and opens a pull request.
- Review AI code edits (VS Code docs) (opens in a new tab)DocsFree
Per-file keep and undo for agent changes in the editor.
- Early-2025 AI and experienced developer productivity (METR) (opens in a new tab)PaperFree
A measured study in which developers felt faster than the timing showed.
- DORA metrics guide (opens in a new tab)ArticleFree
Defines lead time, deployment frequency, change failure rate and recovery time.
- Run Claude Code programmatically (Claude Code docs) (opens in a new tab)DocsFree
Print mode, allowed tools, turn limits and JSON output for unattended runs.
- Secure use reference (GitHub Actions) (opens in a new tab)DocsFree
Token permissions and the risks of untrusted input in workflows.