A team of three engineers would have needed about a year to port Bun from Zig to Rust, according to its creator. Instead, 64 AI agents did it in 11 days.
That story is being quoted in every board deck that mentions technical debt, usually with one number attached: $165,000.
The number is real, but it is a floor, not a quote.
This guide breaks down what the $165K covers, what it leaves out and how to budget AI code migration for your own codebase.
Quick Summary
Bun's Zig-to-Rust port took 11 days to complete by 64 parallel Claude agents for the sum of $165,000. The cost reflects API tokens only, with verification, security review, CI, and human curation adding up on top of that to form the necessary due diligence for a production-grade migration.
The real-world implication is that the cost of an AI-assisted code migration is disproportionally determined by the quality of your test suite and rulebook rather than the size of your codebase in lines of code.
Key Highlights
- $165K covers 5.9 billion uncached input tokens and 690 million output tokens, not the full project.
- The human alternative was about three engineers with full context for roughly a year, plus a feature freeze.
- The rewrite was not one-shot. It relied on a 600-line porting rulebook, isolated environments, automated compiler feedback, adversarial AI code reviews, and a comprehensive CI system.
- Post-port cleanup was heavy: 19 known regressions, eleven rounds of security review, and about 4% of the Rust code initially inside unsafe blocks.
- One independent analyst speculated the all-in cost could approach $800K if agent spend continued at $10K a day. That is an estimate, not a reported figure.
Why AI-Assisted Code Migration Suddenly Has a Price Tag
For years, the mantra of 'never rewrite from scratch' was sound advice due to the years of engineering time that it takes to rewrite code and migrate a runtime. Bun changed the inputs to this equation, and is the first widely-documented case where an AI code migration of a production runtime has a public number attached to it.
The context here is important- Bun has 22 million monthly downloads and is used in software such as Claude Code. The migration had been running in production for months in Claude code prior to release, and the Rust build came from a version that had been in production for months inside Claude Code. Bun 1.4, the first Rust release, was shipped on 20 August 2026, which was 99 days after v1.3.14.
A caveat on sourcing- since Anthropic acquired Bun in December 2025, this is a vendor-adjacent case study. Please treat the headline figure as credible, but not independently audited.
Reported scope also varies by how lines are counted, ranging from about 535,000 lines of Zig to about 780,000 lines in the full codebase.
AI Code Migration Cost: What the $165K Actually Covers
The token bill is the only line item that was published. Everything else has to be estimated.
| Cost component | Reported in Bun's case | What to expect on your project |
|---|---|---|
| API tokens | $165K (5.9B input / 690M output tokens) | Scales with LOC and retries; the most predictable line |
| Compiler/test iteration | ~16,000 compiler errors fixed by agents | Included in tokens, but rework inflates it |
| Human planning (rulebook, architecture) | ~600-line porting rulebook | Senior engineer time, front-loaded |
| Verification and review | 11 security review rounds, 19 regressions fixed | Often the largest hidden cost |
| CI and continued agent usage | Not published | Speculative estimates run far higher than $165K |
Bun's figure works out to roughly $210 to $310 per 1,000 lines, depending on which line count you use. Applying that rate gives a rough token-only floor:
| Codebase size | Token-only floor (basis: $165K ÷ 535K–780K lines) |
|---|---|
| 50K LOC | ~10K–15K |
| 250K LOC | ~53K–77K |
| 500K LOC | ~105K–155K |
So what you're asking for are planning floors, not quotes. They take Bun-grade testing coverage and an experienced team. A weakly tested legacy system will cost more because agents waste tokens trying again and again when they have no reliable pass/fail signal.
As a working assumption, budget total project cost at 1.5x to 5x the token floor (poorly tested code being on the upper end), and the upper bound is calculated from the speculative 800K-against-165K gap so is our assumption, not a published benchmark.
If you want to pressure-test these numbers against your repositories, our AI strategy consulting team can scope a migration assessment before you commit budget.
AI Migration vs. Manual Rewrite: How the Economics Compare
| Factor | Manual rewrite | AI-assisted migration |
|---|---|---|
| Calendar time | 1–2 years (Bun: ~3 engineers, ~1 year) | Days to weeks for the first pass |
| Feature freeze | Usually required | Shorter, but verification still competes for attention |
| Cost driver | Engineer salaries | Tokens plus senior review time |
| Output style | Idiomatic target-language code | Functionally correct, may need idiomatic cleanup |
| Main risk | Scope creep, lost knowledge | Verification gaps, audit backlog |
The fair criticism of the "$165K vs. a year of salaries" comparison is that a human team would have produced idiomatic Rust, while the AI port left a structural audit backlog behind it. About 4% of the new Rust code sits in unsafe blocks, roughly 13,000 unsafe keywords. The speed is real, but so is the cleanup.
7 Signs Your Codebase Is Ready for AI Legacy Code Migration
AI can make a large code migration much faster, but it cannot fix a weak foundation.
Before giving an AI coding agent access to thousands or even millions of lines of legacy code, you need to know whether your codebase is actually ready for that kind of change. A poorly tested or badly documented system can turn a fast AI migration into a long and expensive debugging project.
Here are seven signs that your codebase is ready for AI-assisted migration.
1. You Have a Test Suite You Can Trust
The first question is simple: Do your tests actually tell you when something has broken?
A migration is only as safe as the tests used to validate it. If important edge cases are known only by a few senior developers and are not covered by automated tests, an AI agent has no reliable way to know what behavior must be preserved.
Before starting a migration, identify the most important user flows, APIs, and edge cases and turn them into executable tests.
2. Your Product Behavior Is Clearly Defined
Legacy systems often contain rules that were never properly documented.
Developers may know that a certain API returns a specific format, or that a particular input produces a certain result, but that knowledge may exist only in old code, internal documentation, or someone's memory.
AI agents need something more concrete.
API contracts, snapshots, golden outputs, integration tests, and other reference points give the agent a clear definition of what "correct" means.
3. Your Codebase Has Clear Module Boundaries
Large migrations become much easier when the codebase is divided into well-defined components.
If different modules have clear responsibilities and limited dependencies, multiple AI agents can work on different parts of the system without constantly interfering with each other.
This is one reason large-scale agent-based migrations can run in parallel.
Bun's migration is a useful example. The work was divided across many agents, allowing different parts of the codebase to be handled simultaneously rather than forcing one agent to process the entire project from beginning to end.
4. Your CI Pipeline Is Fast Enough to Give Agents Feedback
AI agents work through an iterative process.
They make a change, run the compiler, execute tests, inspect the result, and then make another change.
But if your CI pipeline takes 30 minutes, an hour, or longer to tell an agent whether its changes are correct, the cost of the migration can grow quickly.
Fast builds and reliable automated tests become part of the migration infrastructure itself.
Before starting, look at your build and test times. If your development team already considers the CI pipeline
The Pillars of a Safe AI Software Modernization
Anthropic's own published process for large migrations follows six steps: create rulesets, analyze dependencies, stress test translation rules, then deploy multiple agents for iterative translation, review, and fixing. In practice this reduces to four pillars:
- Rules before agents. A written translation ruleset, stress-tested on a small slice, prevents thousands of inconsistent decisions later.
- Tight feedback loops. Compiler output, unit tests, and integration tests give agents an objective signal. Without that signal, they produce plausible but wrong code.
- Adversarial review. A separate agent, or several, reviews the first agent's output with the goal of finding faults, not approving it.
- Human-owned verification. Fuzzing, security review, and regression triage stay under human accountability. As one analysis put it, the Bun rewrite shows agents can compress implementation time, not that verification time can be removed.
What an AI Code Migration Engagement Should Include
- Codebase and dependency assessment, including test-coverage audit
- Migration ruleset and target-architecture spec
- Agent orchestration setup (parallel workers, isolated environments, CI hooks)
- Iterative translation, review, and fix cycles
- Verification harness: regression suites, fuzzing, and security review
- Post-migration audit of unsafe patterns, performance, and idiomatic cleanup
- Documentation and knowledge transfer to your team
Engagement Models and How to Budget
| Model | Best for | How cost is structured |
|---|---|---|
| Assessment sprint | Deciding if a migration is viable | Fixed fee, 2–4 weeks; outputs coverage report and token-floor estimate |
| Pilot module | Proving the ruleset on one component | Fixed scope plus a capped token budget |
| Full migration | Well-tested, bounded codebases | Milestone-based, with token spend passed through transparently |
| Ongoing modernization | Large portfolios of legacy services | Monthly retainer plus usage |
Whatever model you choose, ask for token spend and human review hours to be reported separately. Bun's $165K headline is a reminder of what happens when only one of those numbers is public.
The Landscape: Who Does AI-Assisted Code Migration?
You have three realistic options. In-house teams with agent tooling such as Claude Code is ideal for mature engineering organizations with senior developers and thorough test suites.
Platform vendors and consultancies will offer turnkey migration solutions for an appropriate fee while independent agentic AI specialists such as RejoiceHub can build bespoke multi-agent pipelines around your existing stack
No path fits every case. In-house is cheapest if you already have the expertise, and vendors are fastest to start. A specialist partner earns its fee when the codebase is business-critical, poorly documented, or spans several languages. Explore how we approach AI agent development and enterprise AI integration if you're weighing options.
Technical Deep-Dive: The Verification Tail
You have three realistic options. In-house teams with agent tooling such as Claude Code works well when you have senior engineers and strong tests. Platform vendors and consultancies provide packaged migration services. Boutique agentic AI firms, RejoiceHub among them, build custom multi-agent pipelines around your stack.
No path fits every case. In-house is cheapest if you already have the expertise, and vendors are fastest to start. A specialist partner earns its fee when the codebase is business-critical, poorly documented, or spans several languages. Explore how we approach AI agent development and enterprise AI integration if you're weighing options.
Conclusion
Bun's $165k rewrite is the type of migration that previously took years of engineers' effort to accomplish in days. It is not an argument for migrations being generally cheaper since the bill for verification, security reviews, and clean-up have merely been deferred to later dates.
When you plan on doing one, always budget that your tokens will be the minimum you will spend and prioritize testing, policies, and reviewers. You should also consider conducting an initial assessment or pilot module before migrating everything.
Frequently Asked Questions
How much does AI code migration cost?
AI code migration cost starts around $210 to $310 per 1,000 lines in tokens, based on Bun's $165K rewrite. That is only a floor. Testing, reviews, and CI can easily push the total to roughly 1.5 to 5 times higher.
Did Bun's AI rewrite really cost $165,000?
Only the AI token bill was reported at $165,000. That covers 5.9 billion input tokens and 690 million output tokens. Human review time, CI, security checks, and ongoing agent use were not published, so the full cost is likely higher.
How long did Bun's AI code migration take?
The Bun port took 11 days using 64 parallel AI agents. Doing it by hand would have taken about three engineers roughly a full year. The final public release took longer, shipping 99 days after Bun's last Zig version arrived.
What is AI-assisted code migration?
AI-assisted code migration means using AI coding agents to convert code between languages or frameworks. Humans write the rules and tests, the agents do most of the translation, and human reviewers check the result before anything ships to real users.
Is AI code migration cheaper than a manual rewrite?
Usually yes, and much faster overall. Bun's $165K token bill looked cheaper than a year of salaries for three engineers. But testing and cleanup add extra cost, and human teams often write cleaner, more natural code in the new language.
What are the risks of AI legacy code migration?
The main risks are hidden behavior changes, new security bugs, and code that is hard to maintain. Bun's port had 19 known regressions, and about 4% of its Rust code started in unsafe blocks, which needed careful review.
What do you need before starting an AI code migration?
You need a solid test suite, a written set of clear translation rules, fast CI pipelines, and reviewers who know the codebase. Without tests, AI agents have no reliable way to check their work, and costs and risk climb quickly.
Can AI agents replace engineers in a code migration?
No. Agents can write and fix code very fast, but engineers still set the rules, design the tests, and review the output. Bun's team still spent a lot of time on security reviews, fuzzing, and fixing regressions after the port.
Why did Bun's Rust release take so long after the rewrite?
The port merged in May 2026, but the release needed more testing and compatibility work first. Bun 1.4 shipped on 20 August 2026, 99 days after the last Zig release. It also fixed 128 bugs from the older Zig version.

