Quanta

← Back to Briefings

Claude Code Batch Refactors a 4,200-Package Monorepo

Coding agents at scaleEN60 reads

01 · One Nightly Window, 4,200 Packages, and a Fixed Token Budget

Teams running heavy sustained workloads rarely refactor a monorepo because the code smells. They refactor because a deadline, an SDK migration or a security advisory makes the old shape expensive to keep. The team behind this comparison runs four engineers, one monorepo of roughly 4,200 packages, and a six hour nightly automation window. Their job was to replace an internal logging facade everywhere it appeared, a change that touched imports, call sites and test fixtures in almost equal measure. The chosen vehicle was Claude Code in non-interactive mode: a scripted invocation that receives a prompt, performs the edit, emits a patch and exits with no human in the loop.

Non-interactive mode turns an assistant into a workload. It can be scheduled, retried and metered, and every run begins with a clean context rather than a conversation that slowly drifts off task. It also forces the team to decide what the agent is allowed to see. Each invocation was given one package directory, the shared interface definition and the repository lint rules, and nothing else. That constraint, not the model, did most of the work of keeping the patch reviewable.

The brief allowed one balance and one meter. Every call would be billed on real tokens, with cache writes and cache reads priced separately, so the two candidate strategies had to be compared on more than patch quality. They had to be compared on spend per accepted package.

02 · The Mega-Prompt Sweep Against Manifest-Driven Shards

Strategy one was a sweep: one long prompt that described the facade replacement in prose, pointed at the interface file, and asked the agent to work outward from the repository root. Strategy two was sharded: a manifest listing every affected package, with one non-interactive run per package and a fixed prompt template filled in per row.

Head to head, the two approaches behaved like different tools rather than different settings.

  • › First pass coverage. The sweep moved quickly through the first hundred directories and then slowed, because each new directory was processed inside a context that already held the previous ones. Shards started cold every time, but they started the same way every time.
  • › Blast radius. A sweep failure meant re-running the sweep. A shard failure meant re-running one package. Over 4,200 packages, that difference decides whether the budget goes to refactoring or to repetition.
  • › Context reuse. The sweep amortised its instructions: the prompt was written once and absorbed repeatedly, which showed up as cache reads rather than fresh input. Shards repeated the template each time, which showed up as cache writes on every cold start.
  • › Review load. Sweep output arrived as one enormous diff that nobody could read in a single sitting. Shard output arrived as small patches with a package name attached, so reviewers could accept or reject each one independently.
  • › Resume cost. When the nightly window closed mid-sweep, the team lost the run. When it closed mid-shard, the manifest marked the completed rows and the next night resumed at the first unfinished package.

The sharded approach won on everything except raw prompt repetition, and the team accepted the repetition because it bought restartability.

03 · Claude Haiku 4.5 for the Mechanical Middle, Claude Opus 5.5 for the Edges

Sharding changes the model question. Once runs are small and repeatable, the team can afford a ladder instead of a single choice. Most packages in a facade swap are mechanical: rename an import, adjust two call sites, fix one fixture. For that middle, Claude Haiku 4.5 was the workhorse, fast enough to keep the nightly window filled and cheap enough that a rejected patch cost almost nothing to re-run.

A minority of packages were not mechanical. Some services wrapped the facade in their own abstractions, some carried vendored copies of the old interface, and a handful asserted on log output line by line. Those went to Claude Opus 5.5, which was better at reading intent across several files before editing any of them. The routing rule was written directly into the manifest: if a package contained more than one definition of the facade symbol, escalate it; otherwise run the cheap model and let the test suite judge.

The escalation rule is the part teams skip and later regret. Without it, an expensive model is burned on rename work, or a fast model confidently produces a patch that compiles while subtly changing logging behaviour. With it, model spend tracks the real difficulty distribution of the repository instead of the worst case inside it.

04 · Cache Writes, Cache Reads, and the Price of Starting Cold

The accounting matters as much as the code here. Every call in this rollout was metered on real tokens, with cache writes and cache reads priced separately, which is exactly the shape that makes a sharded design look expensive on paper and cheap in practice. A shard starting cold pays a cache write for its instructions. A shard that later runs against an unchanged package mostly pays cache reads.

Three habits kept the meter flat across the refactor.

  • › Keep the prompt template byte-stable between nights, so the system content that can be cached is actually cached instead of rewritten.
  • › Send only the package directory and the shared interface, not the whole repository, so input does not scale with monorepo size.
  • › Triage cheaply first and pay for depth only where triage flags a package, so expensive context is never purchased speculatively.

For a team running this kind of volume, one balance covering Claude alongside GPT, Gemini, DeepSeek, Kimi, GLM, Qwen and Grok is convenient for exactly one reason: the fallback model becomes a configuration change instead of a procurement task. Quanta works that way, metering real tokens against a single API base address that works with Claude Code directly, with cache writes and cache reads billed separately. Anyone who brings another heavy user onto the platform also earns 19% of their top-ups.

05 · Dry Runs, Diff Gates, and the Kill Switch for 4,200 Patches

None of the strategy debate matters if the output is unsafe, so the rollout carried four gates. First, a dry run on a random sample of twenty five packages, reviewed line by line before any automation was trusted at scale. Second, a per-shard test gate: if the package tests failed after the edit, the patch was discarded and the row was marked for escalation, never patched twice. Third, a repository-wide compile and lint gate run once per night, which caught the handful of packages whose local tests passed but whose shared interface usage drifted. Fourth, a kill switch: the loop halted on the third consecutive failure in any directory subtree, on the reasoning that three failures in a row usually mean the prompt is wrong, not the code.

What the team measured at the end was not lines changed. It was accepted packages per night, rejected patches per thousand, and the share of nightly spend that went to cache reads versus cache writes. The sharded design with a two model ladder moved all three in the right direction, and the sweep was retired except for reconnaissance, where its ability to describe a repository quickly still earns its keep.

If your team has a facade swap, a deprecation or a format migration waiting inside a monorepo that nobody wants to touch by hand, open an account on Quanta once, point Claude Code at its base address, and run the same manifest-driven loop against a window you control.