Migrating the GitHub Copilot runtime to Rust, using Copilot
GitHub successfully rewrote its Copilot agent runtime from TypeScript/Node.js to Rust, with AI agents writing most of the 800,000 lines of code, significantly improving performance and developer efficiency.
Intelligence analysis by Gemini 2.5 Flash

The core runtime for GitHub Copilot, which powers numerous Microsoft and GitHub products, was migrated to Rust to address performance, memory, and reliability issues inherent in its original TypeScript/Node.js architecture. This massive rewrite was largely accomplished by a single developer, aided by GitHub Copilot itself, demonstrating the power of AI in large-scale code modernizatio…
Imagine you have a super smart helper, Copilot, that lives in many different apps like your word processor or coding tool. This helper used to be built with a lot of tiny, slow parts that made it a bit sluggish and used up too much memory, like a big, old car that drinks a lot of gas. So, the engineers decided to rebuild it using super-fast, efficient parts, like a sleek electric car. The amazing part is that Copilot itself helped write most of the new, faster code, making the whole process much quicker and the helper much better for everyone.
Analysis
The GitHub Copilot agent runtime serves as the foundational engine for a broad spectrum of applications, including the Copilot CLI, Copilot app, VS Code, Visual Studio, and various Microsoft Office products. Its widespread adoption across such diverse environments underscored the critical need for a highly performant, reliable, and memory-efficient core. The original TypeScript on Node.js stack, while enabling rapid initial development, proved increasingly unsuitable for the demanding requirements of these varied integrations, particularly concerning startup times and memory footprint.
Copilot agent runtime
The Copilot agent runtime is not merely a backend for a single application but a shared, embedded harness providing AI capabilities across a growing ecosystem of Microsoft and GitHub solutions. This architectural choice ensures consistency in intelligence, security, and reliability, allowing a single fix or improvement to propagate across all consuming products. The decision to centralize the agent loop via the GitHub Copilot SDK enabled product teams to concentrate on their unique business value rather than reimplementing complex agent logic, which is crucial in a rapidly evolving AI landscape.
Initially, many products developed their own agent loops, but the shift to the SDK streamlined development and maintenance. The shared runtime, however, highlighted the limitations of its underlying technology stack when deployed in diverse, performance-sensitive contexts. The original design, optimized for rapid development of a terminal UI, struggled to meet the stringent demands of server-side density, low memory overhead, and fast startup required by enterprise applications.
TypeScript
The initial implementation in TypeScript, running on Node.js and the V8 JavaScript engine, was a pragmatic choice for the Copilot CLI's rapid development. TypeScript and Node.js offer broad accessibility and facilitate quick application iteration, which was essential for getting the Copilot CLI to market swiftly. For a console application, the performance characteristics in terms of startup, responsiveness, throughput, and memory consumption were deemed acceptable at the time.
However, these characteristics became significant drawbacks when the runtime needed to be embedded in other environments with different constraints. The overhead associated with V8, including parsing and JIT compilation of JavaScript, along with Node.js's threading model, led to suboptimal performance. This became particularly problematic as the runtime's scope expanded beyond simple console applications to more demanding integrations where every millisecond and megabyte counted, necessitating a more performant and resource-efficient language like Rust.
JSON-RPC protocol
The architectural intertwining of the Copilot CLI's terminal UI and its runtime initially led to a pragmatic but suboptimal solution for programmatic access. When an SDK was required, it was layered on top of the CLI, rather than the logical inverse. This meant the SDK would spawn the CLI as a subprocess, communicating with it via a JSON-RPC protocol over stdin/stdout to host the agent loop out-of-process.
While this approach was quick to implement and offered flexibility, it introduced significant performance and reliability penalties. Every SDK consumer had to launch a separate Node.js and V8 process, incurring substantial memory overhead (around 100 MB minimum per client) and startup latency. Furthermore, all function calls and data transfers were forced across a process boundary, adding communication overhead and increasing the risk of session crashes if the Node process failed. The migration to Rust aimed to eliminate this out-of-process communication, allowing for direct, in-process function calls and significantly reducing resource consumption.
Key points
- The GitHub Copilot agent runtime was completely rewritten from TypeScript/Node.js to Rust.
- AI agents, specifically GitHub Copilot, wrote over 800,000 lines of the new Rust code across 128 pull requests.
- The migration was primarily completed by a single developer in a few months, a task that would typically take a team years.
- The rewrite significantly improved the runtime's performance by orders of magnitude and reduced memory overhead.
- The original TypeScript/Node.js architecture, with its out-of-process JSON-RPC communication, led to performance, memory, and reliability issues for consuming applications.
The successful migration to Rust promises significantly improved performance, reduced memory consumption, and enhanced reliability for all applications leveraging the GitHub Copilot agent runtime. This efficiency gain will enable GitHub and Microsoft to scale AI capabilities more effectively across their product ecosystem, delivering a faster and more stable experience to millions of users.
Despite the successful migration, such a large-scale rewrite of 800,000 lines of code inherently carries risks of introducing subtle bugs or regressions, even with AI assistance. The complexity of integrating the new Rust runtime across numerous diverse products could also present ongoing challenges in ensuring seamless compatibility and consistent behavior.