Skip to content

qhkm/pi-rs

π (pi) — AI Coding Agent

Rust License: MIT Tests

Minimal core. Maximum extensibility. Your workflow, your way.

A high-performance, terminal-native AI coding agent built in Rust. This is a Rust port of pi-mono, originally created by Mario Zechner. Features 101+ LLM models across 17 cloud providers, advanced TUI with streaming responses, and extensible plugin architecture.

Philosophy: Pi provides primitives, not features. Sub-agents, plan mode, permission gates—build them yourself or install a package. Adapt pi to your workflows, not the other way around. Read more →

🤖 Vibe Coded — This is a vibecoded project. It's here to inspire, not to be a polished product. Fork it, tear it apart, or use it as a starting point to build your own AI coding agent.

🚀 Quick Start

# Clone and build
git clone https://github.com/qhkm/pi-rs
cd pi-rs
cargo build --release

# Run interactive mode
./target/release/pi

# Or with a specific model
pi --model claude-3-opus

# Run a one-off task
pi "Refactor src/main.rs to use async/await"

✨ Features

🧩 Philosophy: Primitives, Not Features

What Others Bake In How Pi Does It
Sub-agents Spawn via tmux, or build with extensions
Plan mode Write to files, or build with extensions
Permission popups Run in container, or build your own flow
Built-in to-dos Use TODO.md, or build with extensions
MCP integration Build as skills, or add via extensions

The result: A 15MB binary that starts in <50ms instead of 100MB+ and 1-3s.

🤖 AI Providers (17+ Supported)

  • Anthropic: Claude 3 Opus, Sonnet, Haiku
  • OpenAI: GPT-4o, GPT-4.1, o1, o3, o4-mini
  • Google: Gemini 2.5 Pro, 2.0 Flash
  • Azure: OpenAI GPT-4o, GPT-4.1
  • AWS: Bedrock (Claude, Llama 4)
  • Google Vertex: Gemini 2.5, Claude
  • Native: Mistral, Groq, xAI (Grok), Cerebras, OpenRouter, MiniMax, HuggingFace, Perplexity, DeepSeek

🖥️ Terminal UI

  • Streaming responses with animated cursor
  • Syntax highlighting for code blocks
  • Diff viewer (unified & side-by-side)
  • Model selector (Ctrl+L)
  • Thinking level selector (Shift+Tab)
  • Tool execution visualization
  • Fuzzy file search (@file expansion)
  • Theme system with hot-reload

🛠️ Developer Tools

  • 7 built-in tools: Read, Write, Edit, Bash, Grep, Find, Ls
  • Smart truncation with context preservation
  • Diff editing with conflict resolution
  • Concurrent tool execution
  • Path security (prevents directory traversal)

🔌 Extension System

  • Shell extensions: Bash scripts as tools
  • Binary extensions: JSON-RPC over stdio
  • WASM extensions: Sandboxed WebAssembly plugins
  • Hook system: Before/after turn events
  • Command registration: Custom slash commands

📝 Skills System

  • Markdown-based: Simple SKILL.md format
  • YAML frontmatter: Full metadata support
  • Git install: pi /skill:install https://github.com/user/skill
  • Tag-based discovery: Search by categories
  • Auto-converted to tools: Skills become available as agent tools

🔐 Authentication

  • OAuth 2.0 Device Flow: GitHub Copilot, Google Gemini, OpenAI Codex
  • Encrypted storage: XOR + keyring for tokens
  • Auto-refresh: Tokens refreshed before expiration
  • API key fallback: Environment variable support

📦 Installation

From Source

cargo install --path crates/pi-coding-agent

Homebrew (macOS/Linux)

brew tap qhkm/pi
brew install pi

🎯 Usage

Interactive Mode

pi                          # Start interactive session
pi --model gpt-4o          # Use specific model
pi --thinking high         # Set reasoning level

One-shot Mode

pi "explain this codebase"
pi --file src/main.rs "refactor this"

JSON Mode

pi --json "list all TODOs" | jq .

RPC Mode

pi --rpc-server            # Start JSON-RPC server

Slash Commands

Command Description
/clear Clear conversation history
/compact Compact context to save tokens
/model <name> Switch AI model
/thinking <level> Set thinking level
/settings Open settings
/export Export conversation
/setkey <api-key> Set runtime API key for current session
/help Show help

⚙️ Configuration

Settings Hierarchy

~/.pi/settings.json        # User settings
./.pi/settings.json        # Project settings (overrides user)

Example .pi/settings.json

{
  "model": "claude-3-opus",
  "thinking_level": "medium",
  "auto_compact": true,
  "max_turns": 50,
  "theme": "dark"
}

AGENTS.md

Place an AGENTS.md in your project root for project-specific instructions:

# Project Guidelines

## Code Style
- Use snake_case for functions
- Use PascalCase for types
- Always handle errors explicitly

🧩 Creating Extensions

Extension Manifest (extension.json)

{
  "name": "my-extension",
  "version": "1.0.0",
  "description": "My custom tools",
  "tools": [
    {
      "name": "lint",
      "description": "Run linter",
      "executor": "shell",
      "command": "cargo clippy -- -D warnings"
    }
  ]
}

Installing Extensions

# Place in .pi/extensions/my-extension/extension.json
pi /extension:enable my-extension

📝 Creating Skills

Skill File (SKILL.md)

---
name: rust-best-practices
description: Rust coding standards
version: 1.0.0
author: Your Name
tags:
  - rust
  - style
---

# Rust Best Practices

- Use `?` operator for error propagation
- Prefer `&str` over `String` for parameters
- Document all public APIs

Installing Skills

pi /skill:install ./path/to/skill
pi /skill:install https://github.com/user/skill-repo

🎨 Theming

Built-in themes: dark, light, high-contrast

Custom theme (~/.pi/theme.json):

{
  "name": "custom",
  "fg": {
    "accent": "cyan",
    "success": "green"
  },
  "syntax": {
    "keyword": "magenta",
    "string": "green"
  }
}

🏗️ Architecture

┌─────────────────┐
│   pi (binary)   │
├─────────────────┤
│  pi-coding-agent│  ← CLI, modes, interactive
├─────────────────┤
│  pi-agent-core  │  ← Agent loop, tools, hooks
├─────────────────┤
│     pi-ai       │  ← LLM providers, streaming
├─────────────────┤
│     pi-tui      │  ← Terminal UI components
└─────────────────┘

Workspace Crates

Crate Purpose Tests
pi-ai LLM providers, OAuth, models 81
pi-agent-core Agent loop, tools, context 157
pi-tui Terminal UI framework 51
pi-coding-agent CLI, modes, extensions 28

🧪 Testing

# Run all tests
cargo test --workspace

# Run specific crate tests
cargo test -p pi-ai
cargo test -p pi-agent-core
cargo test -p pi-tui

📊 Comparison

Metric pi (Rust) Others (Node/TS)
Lines of Code ~45K ~128K+
Binary Size ~15MB 50-100MB+ (bundled)
Startup Time <50ms 1-3s
Memory Usage ~50MB 200MB+
Test Coverage 461+ tests Varies

🤝 Contributing

Contributions welcome! Please read our Contributing Guide.

Development

# Run with logging
RUST_LOG=debug cargo run --bin pi

# Check formatting
cargo fmt --check

# Run clippy
cargo clippy --workspace

📄 License

This project is licensed under the MIT License.

🙏 Acknowledgments

  • Based on pi-mono by Mario Zechner — thank you for the original inspiration
  • Inspired by Claude Code and similar AI coding assistants
  • Built with Tokio, Ratatui concepts, and the Rust ecosystem
  • Thanks to all contributors

🔗 Related Projects

  • ZeptoClaw — Ultra-lightweight (~4MB) personal AI assistant with multi-channel gateway (Telegram, Slack, Discord), container isolation, and agent swarms. A good complement if you need a server-deployable AI gateway rather than a terminal coding agent.

About

AI agent toolkit rewritten in Rust: unified LLM API, agent runtime, TUI, coding agent CLI, Slack bot, web UI, GPU pod manager

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages