Skip to content

How we actually fix this

It's not magic. It's four steps of disciplined engineering work. Here's what each one looks like in practice.

01

Audit

Before we touch anything, we map what's there. Not a quick skim - we actually sit with the codebase.

On most repositories that means reading all of it. On a large one, tooling maps everything and we read the riskiest services first, line by line, then expand from there. The scope is agreed up front, and the report says which parts we read closely and which we only mapped.

We look at dependency trees, run static analysis, check test coverage (if tests exist), and review the architecture. We also check for the security mistakes AI-generated code tends to make (that's a check, not a penetration test). We look at the stuff tools can't catch: naming conventions, patterns that contradict each other, code that nobody calls anymore.

You get a report. Not a 50-page PDF - a clear, prioritized list of what's wrong and what to do about it.

Dependency analysisDead code scanTest coverageArchitecture reviewSecurity checkDocs gap report
02

Untangle

Not everything AI wrote is bad. Some of it's fine. Some of it's clever. Some of it will break in production at 2am on a Friday.

This step is about making those distinctions. We classify everything: keep as-is, needs changes, or needs to go. We rank by actual risk, not "code smell" hand-waving. We build dependency graphs so you can see which parts are tangled together and what the blast radius looks like if something breaks.

Complexity hotspotsCoupling analysisRisk rankingKeep/fix/remove triageDependency graphsDebt estimation
03

Refactor

This is the work. Actual engineers in your codebase, making deliberate changes.

We restructure modules so they have clear boundaries. We write tests that fail when the behavior is wrong, so a green suite means something. We add ADRs that record why a decision was made, so the what is not the whole story.

Every change goes through review. Every refactor is incremental - we don't disappear for three weeks and come back with a "big rewrite."

Architecture reworkPattern cleanupTest suitesAPI boundariesPerformance fixesDecision docs (ADRs)
04

Sustain

Cleaning up a codebase is pointless if it gets messy again in three months.

We set up the guardrails: linters configured for your stack, CI pipelines that gate quality, and code review templates. Agent rules keep your AI tools following the new structure. Onboarding docs mean new teammates aren't lost on day one. The boring infrastructure stuff that most teams skip and then regret.

When we leave, your team should be able to keep the codebase clean on their own. That's the whole point.

CI/CD pipelinesLinter configReview processAI agent rulesOnboarding docsMonitoringTeam workshops

Questions about the process

Do we have to do all four steps?

No. Most people start with the audit and decide after they have read the report. Some stop there and do the work themselves. The four steps are the order that works, not a package you have to buy.

Can we skip the audit and go straight to refactoring?

No, and we will turn that down. Refactoring without a map is how a codebase ends up with a third auth implementation instead of two. The audit is three to five working days, and it is what makes the rest cost a known amount instead of an open one.

Will this stop us shipping?

Mostly no. The audit is read only and runs alongside your work. Refactoring happens on a branch you review, in slices, so main stays shippable. If a piece of work does need a freeze, we say so before we start rather than in the middle.

How long does the whole thing take?

An audit takes three to five working days on a normal repository, longer if the codebase is large. What comes after depends on what it finds, and we scope that with you before anything starts. There is no fixed four week programme, because the state of the codebase decides the work and not the other way round.

Who actually does the work?

The engineers you talk to. There is no account manager and no other team behind the curtain, so the person who reads your codebase is the person who changes it.

What does Sustain leave behind?

Linters and CI that reject the patterns that got you here, review rules, agent files that put your conventions where Cursor and Copilot will read them, and docs a new hire can follow. The test is simple: when we leave, can your team keep the codebase clean without us? If not, Sustain is not finished.

Want to start with the audit?

That's usually how it goes. We look at what you've got, give you an honest assessment, and you decide what happens next.

For what the work covers and how a project starts, see AI code cleanup.

If you would rather look at your own codebase first, the AI codebase health checklist is twelve checks you can run this afternoon. No email required.