- Published on
Rewriting Prime Agent in Rust
- Authors

- Name
- DeepHorus
Prime Agent has been rewritten from the ground up in Rust, delivering a faster, cleaner and more reliable version of the coding agent. Since its August launch, Prime Agent has been downloaded more than 300,000 times and processed over 8 trillion tokens. The Rust version is now shipping to users.
The rewrite was largely autonomous. Over two weeks, Prime Agent orchestrated more than 2,000 agents to rewrite itself end to end. The work ran across 10,000+ Prime Sandboxes and consumed over 200 billion tokens from Prime Inference’s GLM-5.3 endpoint. It stress-tested infrastructure for large-scale agent swarms and autonomous research.
To ensure feature parity with TypeScript, Prime Agent used subagents to topologically sort dependencies. Finite state machines structured looped computations and correctness checks. Runtime benchmarks and real Prime Agent traces then hillclimbed performance metrics and triaged bugs. The codebase was also modularized for easier maintenance.
The move to Rust addresses TypeScript limits. Its types are optional and disappear at runtime, errors travel as unchecked exceptions, and CPU-heavy rendering and parsing compete with keyboard input on a single event loop. Every process also pays for a JavaScript runtime and garbage collector.
Rust offers performance, concurrency and compile-time guarantees. Prime Agent is a long-running daemon with a worker process per session, and native code without a garbage collector accounts for most memory and startup gains. Send and Sync traits let the compiler check data shared between threads. Exhaustive enums, ownership and lifetimes rule out bug classes before code runs.
The rewrite also enabled Windows support, session crash isolation and a more consistent daemon protocol. Verification covered TUI, harness, protocol and feature parity. Differential tests compared TypeScript and Rust binaries side by side against scripted model runs. Agents could measure progress and catch regressions before changes shipped. The rewrite positions Prime Agent for continued scaling.