Old and new code printouts side by side, illustrating AI Rust rewrites
Geeky

AI Rust Rewrites: Why Porting Code Got Cheap

Rewriting a big program in another language used to be the classic bad idea. You spend a year rebuilding something that already works, ship nothing new, and hope the copy behaves like the original.

This year, two well-known projects did it anyway, and AI agents wrote most of the code. Bun, the JavaScript runtime, went from Zig to Rust in 11 days. GitHub moved the engine behind Copilot from TypeScript to more than 800,000 lines of Rust without pausing its releases.

AI Rust rewrites aren’t a stunt anymore. They’re a budget decision, and the budget just got a lot smaller. Here’s what the two projects did, what made them work, and what I saw porting much smaller programs with Claude Code and Codex.

Two AI Rust Rewrites, Two Very Different Clocks

Bun: 11 days, up to 64 Claudes at once

Bun’s creator, Jarred Sumner, documented the port in Rewriting Bun in Rust. The original was 535,496 lines of Zig. Work started on May 3, 2026, and merged on May 14. About 50 automated Claude workflows ran during those 11 days, with roughly 64 Claude instances working in parallel at the peak.

The bill was about 5.9 billion uncached input tokens and 690 million output tokens, which Sumner prices at around $165,000 at API rates. His estimate for doing it by hand: three engineers who already know the codebase, working for about a year.

One disclosure matters. Anthropic bought Bun in December 2025, Sumner works there, and he used a pre-release version of Claude Fable 5. Nobody at Bun actually wrote a $165,000 check.

GitHub Copilot: 14.5 weeks, one engineer steering

GitHub’s port was slower and more careful. In GitHub’s write-up, Microsoft engineer Stephen Toub describes moving the Copilot agent runtime, the engine behind the Copilot CLI, the SDK, and Copilot inside VS Code and Office, one piece at a time from May 12 to August 21, 2026. About 430,000 lines of TypeScript became 832,378 lines of production Rust, plus 468,689 lines of Rust unit tests, across 128 pull requests.

GitHub’s post doesn’t give a dollar figure. The Register reports about $120,000 in tokens. Toub’s own estimate is that without agents, the job would have taken a whole team a year or two.

BunGitHub Copilot runtime
From → toZig → RustTypeScript on Node.js → Rust
Original size535,496 linesAbout 430,000 lines
Time11 daysAbout 14.5 weeks
Token costAbout $165,000 (API pricing)About $120,000 (reported)
Estimate without agents3 engineers, about a yearA team, 1-2 years
Memory result6,745 MB → 609 MB1,383 MB → 126 MB

Don’t read 11 days versus 14.5 weeks as a Claude-versus-Copilot score. Bun did a fast mechanical translation with its test suite as the finish line. GitHub ported in place, a slice at a time, and shipped 135 CLI releases while it did.

The Agents Wrote the Code. The Tests Signed Off.

Parts passing an inspection gauge, like tests checking AI-written code

What made both rewrites possible isn’t the model. It’s that both projects already had a way to prove the new code behaved like the old code.

Bun’s test suite is written in TypeScript, so it doesn’t care what language the runtime underneath uses. That made it a ready-made conformance suite: a checklist of behavior the new version had to match. Sumner reports zero tests skipped or deleted. Every Claude writing code also had at least two reviewer Claudes in separate sessions, shown only the diff and told to assume it was wrong. They caught real bugs before merge.

GitHub ran its full end-to-end tests against the Rust code at every step. A pull request that failed a required test didn’t land, and agents weren’t allowed to edit those tests without permission.

That rule earned its keep. At one point, a port deleted a method the SDK exposed, and the agent slapped a schema-break-ok label on the pull request to get the checks passing. Toub rejected it, and the method came back. An agent’s idea of “done” isn’t always yours, which is why I keep a checklist for reviewing AI pull requests.

Why Agents Keep Landing on Rust

Bulky and compact backpacks showing the memory savings of AI Rust rewrites

Rust is strict. Its compiler refuses to build code that misuses memory, and it explains exactly why. For a human, that’s a steep learning curve. For an agent that can retry thousands of times, it’s a reviewer that never gets tired. Sumner sums it up: compiler errors are “a better feedback loop than a style guide.”

The payoff shows up in memory. Bun’s worst bugs were leaks and crashes from managing memory by hand next to a garbage-collected JavaScript engine. In a test of 2,000 back-to-back builds, the last Zig version climbed to 6,745 MB, while the first Rust version stayed at 609 MB. For Copilot, The Register reports a 10-client batch dropping from 1,383 MB to 126 MB. I covered the wider trend in why so many apps are switching to Rust earlier this month.

The compiler has limits, though. Consultant Lisa Crossman made the point at RustConf: Rust stops an agent from writing memory-unsafe code, but “it does not stop the agent writing the wrong program correctly.” That’s the tests’ job again.

What I Learned Porting Code With Claude Code and Codex

My ports are tiny next to these. At work, I moved a project from Go to Node.js. On my own time, I rewrote a small program that handles some manual chores on my Windows PC from C# to Rust, mostly to learn the language. I used Claude Code and Codex for both.

What made them work is the same thing that made Bun and Copilot work: tests. Unit tests and end-to-end tests told me whether the new version did what the old one did, so I never had to take the agent’s word for it.

Would I do it again? Yes, but saving time isn’t the reason. What I wanted was lower memory usage, which is exactly the win GitHub and Bun are bragging about.

Pro Tip: Before you ask an agent to port anything, check that your tests exercise behavior, not internals. Tests that drive the program from the outside, through its CLI, its API, or its output files, survive a language change. Tests that poke at private classes have to be rewritten too, and then nothing is checking the agent.

Cheap Rewrites Change the Math

For decades, the rule was “never rewrite from scratch,” because the cost was counted in team-years. When that cost drops to weeks and a six-figure token bill, the rule needs an update.

That doesn’t mean every project should jump to Rust. It means reasons that never justified a rewrite before can now pay for themselves: cutting memory use, dropping a whole runtime, or wiping out a class of crash bugs. Part of GitHub’s motivation was that every SDK client dragged along its own Node.js process, on the order of 100 MB each, just to run the agent.

Two caveats. Anthropic and GitHub both sell the agents they’re praising, so treat their numbers as vendor reports. And not everyone is impressed. Zig creator Andrew Kelley argued that Bun’s test suite had already missed bugs in the Zig code, so it can’t vouch for a million lines nobody read line by line. He has a point, and it’s the same point: a rewrite is only as good as the tests guarding it.

Your Tests Are the Real Budget

If you’re eyeing a rewrite of your own, the token bill isn’t the number to worry about. The number that matters is how much of your program’s behavior your tests actually cover.

Bun had around 60,000 tests per platform and a fuzzer running around the clock. GitHub had end-to-end suites no agent was allowed to touch. That’s what turned a million agent-written lines into something worth shipping. Write those tests first. The Rust part is cheap now.

Keep reading about: AIMicrosoftNewsOpen sourceProgramming

Related

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.