
pi_agent_rust - High-performance AI coding agent CLI written in Rust
Why Should You Care? • TL;DR • Methodology • Quick Start • Features • Installation • Commands • Configuration
# Install latest release
curl -fsSL "https://raw.githubusercontent.com/Dicklesworthstone/pi_agent_rust/main/install.sh?$(date +%s)" | bash
You want an AI coding assistant in your terminal, but existing tools are: - Slow to start: Node.js/Python runtimes add 500ms+ before you can type - Memory hungry: Electron apps or heavy runtimes eat gigabytes - Unreliable: Streaming breaks, sessions corrupt, tools fail silently - Hard to extend: Closed ecosystems or complex plugin systems
pi_agent_rust is a from-scratch Rust port of Pi Agent by Mario Zechner (made with his blessing!). Single binary, instant startup, stable streaming, and 8 built-in tools.
Rather than a direct line-by-line translation, this port builds on two purpose-built Rust libraries: - asupersync: A structured concurrency async runtime with built-in HTTP, TLS, and SQLite - rich_rust: A Rust port of Rich by Will McGugan, providing beautiful terminal output with markup syntax
# Start a session
pi "Help me refactor this function to use async/await"
# Continue a previous session
pi --continue
# Single-shot mode (no session)
pi -p "What does this error mean?" < error.log
If you already use Pi Agent, especially through OpenClaw, this project keeps the core workflow while upgrading the engine under the hood:
Security is a first-class design goal here, not a bolt-on:
tool/exec/http/session/ui/events)exec enforcement: capability gate first, then command mediation that blocks critical shell classes by default (for example recursive delete, disk/device writes, reverse shell) and can tighten to block high-tier classes in strict/safe policypending -> acknowledged -> trusted -> killed) with kill-switch audit logs and explicit operator provenanceasupersync for more predictable cancellation/lifecycle behaviorThe Rust port is designed around large-session, multi-agent, and extension-heavy workloads. Release-facing performance numbers are published only when the checked-in evidence artifacts are current, have matching run provenance, and report no CI no-data or data-contract failures. Historical benchmark snapshots are retained in planning/evidence artifacts, but they are not treated as current README claims until the performance evidence gate is regenerated cleanly.
Extension runtime guarantees are also concrete:
| Extension assurance signal | Why you should care |
|---|---|
Two-stage exec guard (exec capability policy + command-level mediation + DCG/heredoc AST signals) |
Dangerous shell intent is caught before spawn, including destructive payloads hidden in multiline wrappers |
Trust lifecycle + kill switch (pending/acknowledged/trusted/killed) |
You can quarantine an extension instantly, log who pulled the switch and why, and require explicit re-acknowledgement before restoring access |
Hostcall lane kill-switch controls (forced_compat_global_kill_switch, forced_compat_extension_kill_switch) |
Fast-path regressions can be contained immediately by forcing compatibility-lane execution without disabling the extension system |
| Deterministic hostcall reactor mesh (shard affinity, bounded SPSC lanes, backpressure telemetry, optional NUMA slab tracking) | Runtime behavior stays predictable under contention; queue pressure and routing decisions are observable instead of opaque |
| Startup prewarm + warm isolate reuse for JS runtimes | Runtime creation overlaps startup and warm reuse keeps repeated extension runs low-latency without a Node/Bun process model |
Tamper-evident runtime risk ledger (verify / replay / calibrate) |
Security decisions are hash-linked and can be replayed or threshold-tuned from real runtime traces |
Bottom line: Pi's architecture targets lower latency, lower memory use, and stronger extension runtime safety under real workload pressure; current numeric claims must come from fresh, provenance-matched evidence artifacts.
Data source: docs/planning/BENCHMARK_COMPARISON_BETWEEN_RUST_VERSION_AND_ORIGINAL__GPT.md (latest secure-path + full orchestrator checkpoints, 2026-04-23).
All numeric performance claims in this README include inline citations with format:
*(from [artifact-path], run [correlation-id])*
Example: *(from [artifact-path], run [correlation-id])*
CI checks both file freshness and artifact content so stale, no-data, or correlation-mismatched evidence cannot back user-facing performance claims. The README evidence checker reports line-numbered proof obligations for cited claims and extracts claim-gated performance phrases for reviewer audit. Explicit historical snapshot citations are mapped separately and do not satisfy current release-facing claims.
In this README, we means the project owner and collaborating coding agents.
The speed gains come from runtime design, not one trick.
| Technique | What we do | Runtime effect |
|---|---|---|
| Cold-start minimization | Single static binary, no Node/Bun runtime bootstrap, no JIT warmup, startup prewarm for extension runtime paths | Faster time-to-first-interaction |
| Less copying on hot paths | Arc/Cow message flow, zero-copy hostcall/tool payload handling, reduced clone-heavy provider/session paths |
Lower CPU and allocation pressure |
| Deterministic dispatch core | Typed hostcall opcodes, fast-lane/compat-lane routing, bounded shard queues with reactor-mesh telemetry | Better tail latency under concurrent extension load |
| Efficient long-session storage | SQLite session index + v2 sidecar (segmented log + offset index) with O(index+tail) reopen path | Fast resume on large histories |
| Streaming parser tuned for real networks | SSE parser tracks scanned bytes, handles UTF-8 tails, normalizes chunk boundaries, interns event-type strings | Lower streaming overhead and fewer parser stalls |
| Safe fast-path controls | Shadow dual execution sampling, automatic backoff on divergence/overhead, compatibility-lane kill switches for containment | Keeps optimizations fast without silent behavior drift |
| CI-level performance governance | Scenario matrices, strict artifact contracts, fail-closed perf gates | Regressions are caught before release |
If you want the full implementation inventory, see Performance Engineering.
The benchmark evidence policy is designed to keep results realistic, reproducible, and hard to game.
What we measured:
100k up to 5M token-class session states.--help, --version) separately from long-session workflows.How we kept comparisons fair:
pi_agent_rust vs legacy coding-agent)How we kept claims honest:
If you want full details, see:
docs/planning/BENCHMARK_COMPARISON_BETWEEN_RUST_VERSION_AND_ORIGINAL__GPT.md (methodology + results + caveats + raw artifact paths)| Feature | Pi (Rust) | Typical TS/Python CLI |
|---|---|---|
| Startup | <100ms | 500ms-2s |
| Binary size | ~21.1 MiB (default release) | 100MB+ (with runtime) |
| Memory (idle) | <50MB | 200MB+ |
| Streaming | Native SSE parser | Library-dependent |
| Tool execution | Process tree management | Basic subprocess |
| Sessions | JSONL with branching | Varies |
| Unsafe code | Forbidden | N/A |
# 1) Start an interactive session
pi
# 2) Ask a codebase question
pi "Summarize the architecture in src/"
# 3) Attach a file inline
pi @src/main.rs "Explain startup flow"
# 4) Run single-shot mode for scripting
pi -p "List likely regression risks for this diff"
# 5) Continue your last project session
pi --continue
# 6) Inspect available models/providers
pi --list-models
pi --list-providers
asupersync is a structured concurrency async runtime designed for applications that need predictable resource cleanup. Key features used by pi_agent_rust:
Cx): Async functions receive an explicit context that controls what they can do (HTTP, filesystem, time). This makes testing deterministic.pi_agent_rust runs on asupersync end-to-end today (runtime + HTTP/TLS + cancellation). Provider streaming uses a minimal HTTP client (src/http/client.rs) feeding a custom SSE parser (src/sse.rs).
rich_rust is a Rust port of Will McGugan's Rich Python library. It provides:
[bold red]error[/] renders as bold red textThe terminal UI uses rich_rust for all output formatting, providing the same visual quality as Rich-based Python tools.
# Install latest release binary
curl -fsSL "https://raw.githubusercontent.com/Dicklesworthstone/pi_agent_rust/main/install.sh?$(date +%s)" | bash
If you already have the original TypeScript pi installed, the installer asks
whether to make Rust Pi canonical as pi and automatically create legacy-pi
for the old command.
export ANTHROPIC_API_KEY="sk-ant-..."
# Interactive mode
pi
# With an initial message
pi "Explain this codebase structure"
# Read files as context
pi @src/main.rs "What does this do?"
Real-time token streaming with extended thinking support:
pi "Write a quicksort implementation"
Watch the response appear token-by-token, with thinking blocks shown inline.
| Tool | Description | Example |
|---|---|---|
read |
Read file contents, supports images | Read src/main.rs |
write |
Create or overwrite files | Write a new config file |
edit |
Surgical string replacement | Fix the typo on line 42 |
hashline_edit |
Precise edits using LINE#HASH tags | Apply edits to specific lines using hashline anchors |
bash |
Execute shell commands with t |
$ claude mcp add pi_agent_rust \
-- python -m otcore.mcp_server <graph>