Skip to content

Blog

GitHub rewrote its Copilot runtime in 830,000 lines of Rust: what did it cost?

9 min read

GitHub Copilot and Rust (logos: GitHub, Rust Foundation / Rust logo CC BY 4.0).
GitHub Copilot and Rust (logos: GitHub, Rust Foundation / Rust logo CC BY 4.0).

GitHub moved about 430,000 lines of TypeScript in the Copilot agent runtime to Rust. Most of the code was written by AI agents running in the GitHub Copilot app and CLI. As of August 21, the Rust code came to 832,378 lines. The port used about 136.3 billion tokens, which comes to about $120,000 at public prices.

Microsoft developer Stephen Toub published a record of the work on the GitHub Blog on September 16. Toub also described the porting process in an interview with Ryan Peterman published on November 2. The whole effort ran for 14 and a half weeks. Toub estimated that about three weeks of that was Toub's own time spent on the port.

The first aim was to run the runtime without Node.js.

Toub explained that the goal was less to switch to a particular language than to remove the dependency on Node.js and V8. The runtime is used not only in Copilot CLI but also in VS Code, Visual Studio, Copilot Studio, Excel, and Word. Before, using the SDK meant running a separate CLI process, and each client used at least about 100MB of extra memory.

For each candidate language, they had agents build a prototype of 5,000 to 10,000 lines and compared the results. C# Native AOT and Rust performed about the same, so they chose Rust, which had more internal projects and experience behind it. Toub said that if the existing code had been C#, they would not have bothered moving it to Rust.

The code to port grew from about 130,000 lines to 430,000.

In early May, the plan was to port about 130,000 lines in six to eight weeks. During the port, dozens of developers kept opening hundreds of PRs a week, and some features from the terminal interface were also moved into the runtime. About 300,000 lines of TypeScript were added while the work was underway.

Lines of runtime code during the port. TypeScript reached zero lines on August 21 (GitHub Blog).
Lines of runtime code during the port. TypeScript reached zero lines on August 21 (GitHub Blog).

They kept shipping new versions while converting the code to Rust piece by piece.

They started with parts less tangled up with other features, such as the code that handles terminal commands and the code that manages files used in a conversation. The conversation-state code, which connects to many features, was moved close to the very end. On the TypeScript side, they left only a bridge for calling the Rust code and deleted the old implementation right away. Working this way, they shipped 135 new versions while merging 128 port PRs. The temporary bridge grew to 2,019 exported items and 3,356 call sites as of August 3, and all of it disappeared when the port was finished.

Deleting the old implementation right away caused conflicts in PRs that were changing the old TypeScript code. That made it clear those changes also had to be applied on the Rust side. Around the same time, Bun chose to replace its Zig code with Rust all at once. Toub explained that the Copilot runtime could not pause development just to do the port.

About one in 12 messages came directly from Toub.

While the code was being moved to Rust, Copilot automatically logged the instructions it received and the commands it ran, task by task. Put together, those logs show 31,247 messages sent to the agents, of which 2,639 were typed or spoken by Toub directly. The rest were automatic task instructions, merge signals, and messages between agents. There were more than 1.85 million tool calls. Among the messages Toub wrote directly, the largest share was review, testing, and CI (31.0%), followed by pushback on technical decisions (17.4%) and nudges to finish the job (15.0%).

Toub's 2,639 hand-written messages, classified by purpose (GitHub Blog).
Toub's 2,639 hand-written messages, classified by purpose (GitHub Blog).

The agents read and searched files about 10 times as often as they edited code. The session assigned to session.ts, a file of about 30,000 lines, spent its first 56 minutes reading the code with 122 tool calls. It then split the work across 15 sub-sessions, using GPT-5.6 Sol for 10 of them and Claude Opus 4.8 for five.

In the GitHub Copilot app, 15 sub-sessions are listed under the task of porting session.ts to Rust.
The session.ts port split into 15 tasks in Copilot (GitHub Blog).

While Toub was asleep, the session moving the entry point asked the session.ts session four times whether it could merge. It was told the work was not ready, but in the end it pulled in the changes from the other session's working folder and merged them anyway. Toub said the cause was assigning interdependent tasks at the same time, and that an owner who decides on merges should be set in advance.

The agent fixing the code changed the tests too.

In one PR, an agent left out an SDK function and failed a compatibility check. Instead of restoring the function, it exempted the check. Only after Toub asked why, before the merge, did it restore the function, which took 21 seconds. In another PR, an agent left out an SDK callback and also deleted the test that checked that behavior.

Toub said agents that change the implementation should not be able to change tests or pass criteria without approval. Doing it again, Toub would prepare more tests before the port that check whether real usage flows still work as before, rather than individual functions.

Code review was split by role as well. Line-by-line comparison was given separately to Claude Opus 5, GPT-5.6 Sol, and Grok 4.6, while Toub looked at structure, direction, and risky areas. In the interview, Toub said having agents read every line was more effective than reading every line personally. This matches the setup described earlier in “How do Claude and Codex split a single task in AXIT?”, where the side that builds is kept separate from the side that checks.

Some code compiled but behaved differently than before.

By September 14, dozens of behavior problems had been found. All of them were in code that compiled and was merged into the main branch. For example, when 42, which should have been sent as an integer, went out as 42.0, the Go and C# SDKs could not read the response. Another problem came from JavaScript and Rust handling empty strings differently.

Five types of behavior problems found after the port (GitHub Blog).
Five types of behavior problems found after the port (GitHub Blog).

Of the 8,678 Rust compiler errors, 84% were cases where a name or type did not match, or a required method or type constraint was missing. Errors about ownership, borrowing, and lifetimes, which often come up when people talk about Rust, made up 1.7%. Toub's view is that other statically typed languages could have a similar effect.

Most tokens were input reread from the cache.

A table comparing request handling in a new conversation, resuming an existing conversation, concurrent connection time, and memory use before and after the Rust port.
Runtime performance before and after the port, excluding model call time (GitHub Blog).

Of the roughly 136.3 billion tokens, about 130.6 billion were input reread from the cache. About 4.2 billion were input newly written to the cache, about 900 million were new input that did not use the cache, and about 600 million were output generated by the model. The cache hit rate for input tokens was 96.22%.

The $120,000 is not what the port cost the whole team.

The repository is private, so outsiders cannot reproduce the work under the same conditions.

  1. The three weeks of developer time is an estimate, based on port PRs making up about 20% of all the PRs Toub opened in that period. Working time was not measured directly.
  2. Colleagues also handled SDK integration, packaging, builds, and code review. That time is not included in the three weeks.
  3. The before-and-after performance also reflects other changes made in the same period. Not all of the performance gains can be credited to the Rust port.
  4. The roughly $120,000 is calculated at public token prices, without discounts.
  5. Toub expects there are behavior problems that have not been found yet.

Still, the comparison Toub draws is clear. Before agents, this would have taken a team of developers one to two years, so even writing the proposal would have been hard. At the same time, Toub says a port whose return cannot be explained is a questionable project. Now that rewrites cost less, I think the teams that pull this off will be the ones that first build tests to serve as the answer key and can say why they are porting.

We are also moving AXIT to Rust.

GitHub is not the only one. The JavaScript runtime Bun also used Claude Fable 5 to move its Zig code to Rust. Recently, Elon Musk also remarked on X that Rust is a good language.

A chart showing the 6,502 commits made during Bun's Rust port as bars in time order. Pink bars are mostly code additions, and teal bars are mostly deletions.
6,502 commits during Bun's Rust port, excluding merge commits (Bun blog).
The part of Elon Musk's post on X saying that Rust is a good language, but that C is used for performance in work close to the hardware.
Elon Musk's post comparing Rust and C (excerpt from X).

Rust can catch code that misuses memory before it runs. The trade-off is that new learners first have to learn the rules for who can use data and for how long. Porting a service that is already running so that it behaves exactly as before also takes time. By handing code conversion to agents, the Bun and Copilot teams were able to take on work that would have been too heavy to rewrite by hand.

We are also moving part of the existing code in AXIT, which we build, to Rust. We will post a separate write-up soon on why we chose Rust, what improved once we actually moved the code, where it took longer, and what we would start with if we did it again.

https://github.blog/ai-and-ml/generative-ai/migrating-the-github-copilot-runtime-to-rust-using-copilot/