Blog

Claude Code Refactoring Playbook: Strangler Fig With an Agent

July 2026 · 8 min read · Technical

A hand-drawn vine wrapping and overtaking a legacy code column, with a new sprout growing free at the top
← Back to all posts

Most Australian businesses carrying a decade-old codebase know the feeling. The system still runs the business, but every change takes longer than it should, the original authors have moved on, and nobody wants to be the person who breaks payroll or invoicing. The instinct is to rewrite the whole thing. That instinct is almost always wrong.

Big-bang rewrites fail for a well-documented reason. You freeze feature work for months, the new system has to match years of accumulated business rules nobody wrote down, and the cutover becomes a single tense weekend. The strangler fig pattern offers a calmer path. You wrap the old system, route one slice of behaviour at a time to new code, and let the legacy shrink until there is nothing left worth keeping. Claude Code, the agentic command-line tool from Anthropic, makes that slice-by-slice work far cheaper to execute.

What the strangler fig pattern actually asks of you

The name comes from the strangler fig, a plant that grows around a host tree and slowly takes over its structure until the original trunk rots away and the fig stands on its own. In software, the host is your legacy system. You put a routing layer in front of it, build replacement functionality behind that layer, and redirect traffic feature by feature. At no point is the whole system down. At no point are you betting the business on one release.

The pattern has three moving parts. First, a seam: a place in the request path where you can decide whether a call goes to old code or new. Second, a replacement: the new implementation of one bounded slice of behaviour. Third, a verification step that proves the new slice behaves identically to the old one before you send it real traffic. The hard part has never been the idea. It is the grind of reading unfamiliar code, writing characterisation tests, and building the replacement without introducing quiet regressions.

Where Claude Code fits

Claude Code works directly in your repository. It reads files, runs your test suite, searches for call sites, and proposes edits you review before anything lands. For a strangler fig migration, that maps onto the exact tasks that usually make the work slow and expensive.

  • Mapping the seam. Point Claude Code at the legacy module and ask it to trace every inbound call site. It reads the code paths and produces the list of entry points you need before you cut anything.

  • Writing characterisation tests. Before you change behaviour, you pin it. Claude Code can generate tests that capture what the old code does today, including the odd edge cases, so you have a safety net that fails loudly if the replacement drifts.

  • Building the replacement slice. With the tests in place, Claude Code drafts the new implementation, runs the suite, and iterates until it is green. You review the diff rather than typing it.

  • Keeping the router honest. Claude Code adds and updates the feature flag or routing logic that decides old versus new, so the switch for each slice stays a small, auditable change.

A playbook you can run this quarter

Here is the sequence we use on client engagements. It assumes you have a test runner, version control, and a way to toggle behaviour in production, whether that is a feature flag service or a simple configuration switch.

  • Pick the smallest valuable slice. Not the hardest module, the smallest one with clear boundaries: a single report, one API endpoint, one calculation.

  • Ask Claude Code to characterise it. Generate tests against current behaviour and run them against the legacy code until they pass. This is your contract.

  • Build the replacement behind a flag. Claude Code writes the new path; the flag keeps it dark until you are ready.

  • Shadow first. Run new and old in parallel, compare outputs on real traffic, and only promote the new slice once the comparison is clean.

  • Delete the old slice. Once traffic is fully on the new path and stable, remove the dead code. The legacy trunk shrinks by one branch.

  • Repeat. Each cycle is independent, reviewable, and reversible.

What it costs, and what it saves

The economics are what make this approachable for a small team. A traditional rewrite of a mid-sized business system quoted through a Sydney or Melbourne agency can run from $180,000 to well past $400,000, and takes the better part of a year before anything ships. During that time your existing system still needs maintenance, so you are paying twice.

A strangler fig migration run with Claude Code changes the shape of that spend. You pay for the tool on a monthly plan, and one experienced engineer supervising the agent can move through slices at a pace that used to need a small team. On a recent modernisation we scoped, a body of work an agency had quoted near $220,000 came in under $70,000 of combined engineering time and tooling, spread across the quarter, with production shipping continuously the whole way through. The saving is real, but the larger win is that the business never stops moving while the work happens.

Guardrails for regulated and sensitive code

If your system touches personal information, financial records, or anything covered by the Privacy Act, the strangler fig approach is an advantage rather than a risk. Because every slice is small and independently verified, you keep a clean audit trail of what changed and when. For businesses under APRA or AUSTRAC obligations, that traceability matters as much as the code itself. Keep the characterisation tests as living documentation of the rules the old system encoded, and have a human review every diff before it merges. Claude Code proposes; your team decides.

The other guardrail is scope discipline. The pattern only works if each slice stays small enough to reason about. Resist the urge to rewrite three modules at once because the agent makes it feel easy. Small slices keep the work reversible, and reversibility is the whole point.

Getting started

You do not need a grand modernisation programme to begin. Pick one annoying module, put a seam in front of it, and run a single slice through the full cycle. The first one teaches your team the rhythm; the rest go faster. If you want help scoping that first slice or setting up the guardrails for a regulated codebase, book a short call with us and we will map it out together.

Ready to move from AI pilot to production?

We help mid-market Australian businesses deploy AI automations that actually reach production and deliver measurable ROI.