Migrating the GitHub Copilot Runtime to Rust
According to the GitHub Blog, the Copilot agent runtime was rewritten from TypeScript to Rust using AI agents, removing the Node.js dependency for SDK consumers.
According to a GitHub Blog post by Stephen Toub, the GitHub Copilot agent runtime was completely rewritten from over 430,000 lines of production TypeScript and Node.js into more than 800,000 lines of production Rust. The runtime powers the Copilot CLI, app, and SDK across various Microsoft, GitHub, and ecosystem applications.
Execution and Timeline
The source states that AI agents wrote most of the code across 128 pull requests that landed incrementally in the main branch. The project was completed primarily by a single developer in a few months, a timeline the source contrasts with an estimated one to two years for a traditional team prior to agents.
In-Place Migration Strategy
The port used an "in-place" atomic replacement strategy. Rather than maintaining parallel dual implementations or executing a single cutover, each pull request replaced a TypeScript component with a thin shim calling into Rust while deleting the old code.
During the transition, temporary internal interop used the napi-rs crate for bidirectional calls between Rust and TypeScript. The finished runtime exposes two interfaces:
- A N-API door for Node.js.
- A C ABI door with 19 exported functions for in-process or out-of-process consumption across six SDK languages (C#, TypeScript, Python, Rust, Go, and Java).
Why Developers Might Care
The rewrite removes the requirement for SDK consumers in languages like C#, Python, Go, Java, and Rust to run a separate Node.js/V8 language runtime per client, avoiding a ~100 MB working set penalty. Applications can now embed the Copilot runtime directly in-process via a lightweight C ABI, moving away from the previous model of spawning a Node/V8 subprocess communicating via JSON-RPC over pipes or sockets.
Limitations
- Explicit State and Lifetimes: Adopting Rust required explicit representation of lifetimes and shared state, introducing lifecycle regressions that required fixing during the port.
- Opt-in Status: The new in-process entry points remain opt-in while teams gain confidence in sharing a process and failure boundary with consuming applications.
- CLI Decoupling: While the runtime is fully Rust, the GitHub Copilot CLI still directly calls into runtime internals in several places, and moving the CLI fully onto the public SDK surface area is ongoing work.
Read the original announcement on the GitHub Blog.