Skip to content

Cyberforker/claude-cli-rs

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ‡ claude-cli-rs

A rabbit-fast Rust reimplementation inspired by Claude Code, with native TUI, deeper tooling, and a cleaner path for terminal-first AI development.

Rust License: MIT


Performance vs Original TypeScript/Bun

Metric TypeScript/Bun (v2.1.88) Rust (claude-cli-rs) Improvement
Cold startup ~200 ms ~15 ms 13Γ— faster
Warm startup ~120 ms ~8 ms 15Γ— faster
Memory (idle REPL) ~150 MB ~25 MB 6Γ— less
Memory (active session) ~300 MB ~60 MB 5Γ— less
Binary size 22 MB bundle + Bun runtime ~20 MB single static binary No runtime dependency
File read (10k lines) ~12 ms ~1.5 ms 8Γ— faster
Glob (100k files) ~800 ms ~120 ms 6.7Γ— faster
Grep (large repo) ~600 ms ~80 ms 7.5Γ— faster
Diff generation ~15 ms ~2 ms 7.5Γ— faster
SSE parse throughput ~40 MB/s ~200 MB/s 5Γ— faster
First token latency Network bound Network bound ~Same

Note: numbers are projected estimates based on comparable Rust vs TypeScript benchmarks. Formal benchmarks will be added in a future release.

Why Rust?

  • Zero-runtime deployment: single static binary, no Node/Bun/npm required
  • Deterministic memory: no GC pauses during streaming or tool execution
  • Native async: Tokio task model vs Node event loop β€” better parallelism for concurrent tools
  • Startup: JIT-free cold start means instant claude --help, instant REPL

Prerequisites

Windows

  1. Rust toolchain (1.85+):

    • Download and run rustup-init.exe
    • During installation, you will be prompted to install Visual Studio Build Tools (select the "Desktop development with C++" workload). This is required for compiling Rust projects. If you already have Visual Studio 2019/2022 with the C++ desktop development components installed, you can skip this step.
    • After installation, restart your terminal (PowerShell / CMD) and verify:
      rustc --version   # Should show rustc 1.85.0 or higher
      cargo --version
  2. Network proxy (required if crates.io is unreachable): If you use a local proxy (e.g. Clash, V2Ray), configure cargo to route through it:

    # Create or edit ~/.cargo/config.toml (i.e. C:\Users\<USERNAME>\.cargo\config.toml)
    # Add the following (change the port to match your proxy):
    [http]
    proxy = "http://127.0.0.1:10809"
    [https]
    proxy = "http://127.0.0.1:10809"

    Alternatively, use a mirror registry (no proxy needed):

    [source.crates-io]
    replace-with = "ustc"
    [source.ustc]
    registry = "sparse+https://mirrors.ustc.edu.cn/crates.io-index/"

macOS

# Xcode command line tools (provides C linker)
xcode-select --install

# Rust toolchain
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env

Linux (Ubuntu/Debian)

sudo apt update && sudo apt install -y build-essential pkg-config libssl-dev
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env

Installation

From source

git clone https://github.com/liberbinjio/claude-cli-rs.git
cd claude-cli-rs
cargo build --release

After building, the executable is located at:

  • Windows: target\release\claude.exe
  • macOS/Linux: target/release/claude

Optional: install to your system PATH (so you can run claude from any directory):

cargo install --path crates/cli

Verify Installation

# Run from the project directory (no install needed)
cargo run -- --version
# Output: claude 0.1.0

cargo run -- --help
# Output:
# Claude Code (Rust) β€” AI coding assistant
#
# Usage: claude.exe [OPTIONS] [PROMPT] [COMMAND]
#
# Commands:
#   self-test  Run internal diagnostics
#   help       Print this message or the help of the given subcommand(s)
#
# Arguments:
#   [PROMPT]  Initial prompt to send (non-interactive when combined with --print)
#
# Options:
#   -p, --print            Print the response and exit (non-interactive mode)
#       --model <MODEL>    Model to use [default: claude-sonnet-4-20250514]
#       --cwd <CWD>        Working directory (defaults to current directory)
#       --resume <RESUME>  Resume a previous session by ID
#   -v, --verbose          Enable verbose/debug logging
#   -h, --help             Print help
#   -V, --version          Print version

# If installed to PATH, you can run directly:
claude --version
claude --help

Quick Start

Set API Key

You must set an Anthropic API key before running:

Windows PowerShell:

$env:ANTHROPIC_API_KEY = "sk-ant-your-key-here"

Windows CMD:

set ANTHROPIC_API_KEY=sk-ant-your-key-here

macOS / Linux:

export ANTHROPIC_API_KEY=sk-ant-your-key-here

Tip: To persist the key, add the command to your shell profile (PowerShell: $PROFILE, Bash: ~/.bashrc, Zsh: ~/.zshrc).

Launch

# Interactive REPL mode (default)
cargo run

# One-shot mode (print response and exit)
cargo run -- -p "Write a Hello World in Rust"

# Specify a model
cargo run -- --model claude-sonnet-4-20250514 -p "Explain this project architecture"

# Resume a previous session
cargo run -- --resume <session-id>

# If installed to PATH:
claude
claude -p "Explain this code"

Other Authentication Methods

# AWS Bedrock
# Windows PowerShell:
$env:CLAUDE_CODE_USE_BEDROCK = "1"
$env:AWS_REGION = "us-east-1"

# macOS/Linux:
export CLAUDE_CODE_USE_BEDROCK=1
export AWS_REGION=us-east-1

Project Architecture

claude-cli-rs/
β”œβ”€β”€ Cargo.toml                     # Workspace root
β”œβ”€β”€ LICENSE                        # MIT
β”œβ”€β”€ README.md                      # This file
β”œβ”€β”€ rustfmt.toml                   # Code formatting
β”œβ”€β”€ clippy.toml                    # Lint config
β”‚
β”œβ”€β”€ crates/
β”‚   β”œβ”€β”€ cli/                       # Binary entry point
β”‚   β”‚   └── src/
β”‚   β”‚       β”œβ”€β”€ main.rs            # fn main β€” startup orchestration
β”‚   β”‚       β”œβ”€β”€ args.rs            # CLI argument parsing (clap)
β”‚   β”‚       └── setup.rs           # Initialization flow
β”‚   β”‚
β”‚   β”œβ”€β”€ core/                      # Core types (shared by all crates)
β”‚   β”‚   └── src/
β”‚   β”‚       β”œβ”€β”€ lib.rs
β”‚   β”‚       β”œβ”€β”€ message.rs         # Message, ContentBlock, UserMessage, AssistantMessage
β”‚   β”‚       β”œβ”€β”€ tool.rs            # Tool trait, ToolRegistry, ToolUseContext, ToolResult
β”‚   β”‚       β”œβ”€β”€ permission.rs      # PermissionMode, PermissionResult, rules
β”‚   β”‚       β”œβ”€β”€ config.rs          # ClaudeConfig, ProjectSettings, load/save
β”‚   β”‚       β”œβ”€β”€ state.rs           # AppState, AppStateHandle
β”‚   β”‚       └── task.rs            # TaskType, TaskStatus, TaskState
β”‚   β”‚
β”‚   β”œβ”€β”€ api/                       # Anthropic API client
β”‚   β”‚   └── src/
β”‚   β”‚       β”œβ”€β”€ lib.rs
β”‚   β”‚       β”œβ”€β”€ client.rs          # ApiClient, provider routing
β”‚   β”‚       β”œβ”€β”€ streaming.rs       # SSE parser, MessageStream
β”‚   β”‚       β”œβ”€β”€ errors.rs          # ApiError classification
β”‚   β”‚       β”œβ”€β”€ retry.rs           # Exponential backoff
β”‚   β”‚       └── normalize.rs       # Message β†’ API request format
β”‚   β”‚
β”‚   β”œβ”€β”€ tools/                     # 28 built-in tools
β”‚   β”‚   └── src/
β”‚   β”‚       β”œβ”€β”€ lib.rs
β”‚   β”‚       β”œβ”€β”€ registry.rs        # ToolRegistry impl, register_all_tools()
β”‚   β”‚       β”œβ”€β”€ bash.rs            # BashTool β€” command execution
β”‚   β”‚       β”œβ”€β”€ grep.rs            # GrepTool β€” code search
β”‚   β”‚       β”œβ”€β”€ file_read.rs       # FileReadTool β€” read with line ranges
β”‚   β”‚       β”œβ”€β”€ file_write.rs      # FileWriteTool β€” atomic write
β”‚   β”‚       β”œβ”€β”€ file_edit.rs       # FileEditTool β€” precise string replacement
β”‚   β”‚       β”œβ”€β”€ glob.rs            # GlobTool β€” file matching
β”‚   β”‚       β”œβ”€β”€ web_fetch.rs       # WebFetchTool β€” HTTP + HTMLβ†’Markdown
β”‚   β”‚       β”œβ”€β”€ web_search.rs      # WebSearchTool β€” search API
β”‚   β”‚       β”œβ”€β”€ agent.rs           # AgentTool β€” sub-agent orchestration
β”‚   β”‚       β”œβ”€β”€ mcp_tool.rs        # MCPTool β€” MCP server tool proxy
β”‚   β”‚       β”œβ”€β”€ todo_write.rs      # TodoWriteTool
β”‚   β”‚       β”œβ”€β”€ lsp.rs             # LSPTool
β”‚   β”‚       β”œβ”€β”€ notebook_edit.rs   # NotebookEditTool
β”‚   β”‚       β”œβ”€β”€ task_create.rs     # TaskCreateTool
β”‚   β”‚       β”œβ”€β”€ task_get.rs        # TaskGetTool
β”‚   β”‚       β”œβ”€β”€ task_update.rs     # TaskUpdateTool
β”‚   β”‚       β”œβ”€β”€ task_list.rs       # TaskListTool
β”‚   β”‚       β”œβ”€β”€ task_stop.rs       # TaskStopTool
β”‚   β”‚       β”œβ”€β”€ task_output.rs     # TaskOutputTool
β”‚   β”‚       β”œβ”€β”€ skill.rs           # SkillTool
β”‚   β”‚       β”œβ”€β”€ config_tool.rs     # ConfigTool
β”‚   β”‚       β”œβ”€β”€ team_create.rs     # TeamCreateTool
β”‚   β”‚       β”œβ”€β”€ team_delete.rs     # TeamDeleteTool
β”‚   β”‚       β”œβ”€β”€ send_message.rs    # SendMessageTool
β”‚   β”‚       β”œβ”€β”€ utils.rs           # Internal helpers
β”‚   β”‚       β”œβ”€β”€ shared/            # Cross-tool shared logic
β”‚   β”‚       β”‚   └── mod.rs
β”‚   β”‚       └── prompts/           # Tool description templates
β”‚   β”‚           β”œβ”€β”€ file_read.txt
β”‚   β”‚           β”œβ”€β”€ file_write.txt
β”‚   β”‚           β”œβ”€β”€ file_edit.txt
β”‚   β”‚           β”œβ”€β”€ glob.txt
β”‚   β”‚           β”œβ”€β”€ web_fetch.txt
β”‚   β”‚           β”œβ”€β”€ web_search.txt
β”‚   β”‚           β”œβ”€β”€ agent.txt
β”‚   β”‚           └── mcp_tool.txt
β”‚   β”‚
β”‚   β”œβ”€β”€ query/                     # Conversation engine
β”‚   β”‚   └── src/
β”‚   β”‚       β”œβ”€β”€ lib.rs
β”‚   β”‚       β”œβ”€β”€ engine.rs          # QueryEngine β€” multi-turn orchestration
β”‚   β”‚       β”œβ”€β”€ query_loop.rs      # Single-turn: APIβ†’toolβ†’resultβ†’continue
β”‚   β”‚       β”œβ”€β”€ compact.rs         # Context window compaction
β”‚   β”‚       └── system_prompt.rs   # System prompt construction
β”‚   β”‚
β”‚   β”œβ”€β”€ commands/                  # Slash command system (/help, /compact, ...)
β”‚   β”‚   └── src/
β”‚   β”‚       β”œβ”€β”€ lib.rs
β”‚   β”‚       β”œβ”€β”€ command.rs         # Command trait, CommandContext, CommandResult
β”‚   β”‚       β”œβ”€β”€ registry.rs        # CommandRegistry, slash parsing
β”‚   β”‚       └── builtin/           # 20 built-in commands
β”‚   β”‚           β”œβ”€β”€ mod.rs
β”‚   β”‚           β”œβ”€β”€ help.rs
β”‚   β”‚           β”œβ”€β”€ exit.rs
β”‚   β”‚           β”œβ”€β”€ clear.rs
β”‚   β”‚           β”œβ”€β”€ compact.rs
β”‚   β”‚           β”œβ”€β”€ model.rs
β”‚   β”‚           β”œβ”€β”€ cost.rs
β”‚   β”‚           β”œβ”€β”€ config.rs
β”‚   β”‚           β”œβ”€β”€ version.rs
β”‚   β”‚           β”œβ”€β”€ resume.rs
β”‚   β”‚           β”œβ”€β”€ session.rs
β”‚   β”‚           β”œβ”€β”€ permissions.rs
β”‚   β”‚           β”œβ”€β”€ mcp.rs
β”‚   β”‚           β”œβ”€β”€ init.rs
β”‚   β”‚           β”œβ”€β”€ memory.rs
β”‚   β”‚           β”œβ”€β”€ diff.rs
β”‚   β”‚           β”œβ”€β”€ commit.rs
β”‚   β”‚           β”œβ”€β”€ theme.rs
β”‚   β”‚           β”œβ”€β”€ vim.rs
β”‚   β”‚           β”œβ”€β”€ status.rs
β”‚   β”‚           └── voice.rs
β”‚   β”‚
β”‚   β”œβ”€β”€ mcp/                       # MCP (Model Context Protocol) client
β”‚   β”‚   └── src/
β”‚   β”‚       β”œβ”€β”€ lib.rs
β”‚   β”‚       β”œβ”€β”€ client.rs          # McpClient β€” single server connection
β”‚   β”‚       β”œβ”€β”€ transport.rs       # stdio / SSE transport
β”‚   β”‚       β”œβ”€β”€ types.rs           # MCP protocol types
β”‚   β”‚       └── manager.rs         # McpConnectionManager β€” multi-server
β”‚   β”‚
β”‚   β”œβ”€β”€ tui/                       # Terminal UI (ratatui + crossterm)
β”‚   β”‚   └── src/
β”‚   β”‚       β”œβ”€β”€ lib.rs
β”‚   β”‚       β”œβ”€β”€ terminal.rs        # Terminal init/restore, panic hook
β”‚   β”‚       β”œβ”€β”€ event.rs           # Event loop (Key/Mouse/Resize/Tick)
β”‚   β”‚       β”œβ”€β”€ theme.rs           # Color themes (light/dark/auto)
β”‚   β”‚       β”œβ”€β”€ app.rs             # App struct, main render loop
β”‚   β”‚       β”œβ”€β”€ repl.rs            # REPL layout (messages + status + input)
β”‚   β”‚       β”œβ”€β”€ message_view.rs    # Message list rendering
β”‚   β”‚       β”œβ”€β”€ prompt_input.rs    # Multi-line input widget
β”‚   β”‚       β”œβ”€β”€ spinner.rs         # Loading animation
β”‚   β”‚       β”œβ”€β”€ diff_view.rs       # Unified/side-by-side diff
β”‚   β”‚       β”œβ”€β”€ permission_dialog.rs # Modal permission dialog (y/n/always)
β”‚   β”‚       β”œβ”€β”€ onboarding.rs      # First-run onboarding flow
β”‚   β”‚       β”œβ”€β”€ markdown_render.rs # Markdown + syntax highlighting
β”‚   β”‚       β”œβ”€β”€ status_line.rs     # Bottom bar (model/cost/tokens)
β”‚   β”‚       └── keybindings.rs     # Vim mode (optional)
β”‚   β”‚
β”‚   β”œβ”€β”€ auth/                      # Authentication
β”‚   β”‚   └── src/
β”‚   β”‚       β”œβ”€β”€ lib.rs
β”‚   β”‚       β”œβ”€β”€ oauth.rs           # OAuth 2.0 PKCE flow
β”‚   β”‚       β”œβ”€β”€ api_key.rs         # API key management
β”‚   β”‚       β”œβ”€β”€ keychain.rs        # OS keychain (macOS/Windows/Linux)
β”‚   β”‚       └── providers.rs       # Provider routing (Anthropic/Bedrock/Vertex)
β”‚   β”‚
β”‚   β”œβ”€β”€ services/                  # Application services
β”‚   β”‚   └── src/
β”‚   β”‚       β”œβ”€β”€ lib.rs
β”‚   β”‚       β”œβ”€β”€ session.rs         # Session storage (JSONL save/load/list)
β”‚   β”‚       β”œβ”€β”€ analytics.rs       # Event tracking (no-op by default)
β”‚   β”‚       β”œβ”€β”€ cost.rs            # Token & cost tracking
β”‚   β”‚       β”œβ”€β”€ compact.rs         # Compaction strategy
β”‚   β”‚       β”œβ”€β”€ plugins.rs         # Plugin system skeleton
β”‚   β”‚       └── tips.rs            # Usage tips
β”‚   β”‚
β”‚   β”œβ”€β”€ bridge/                    # Remote bridge (claude.ai WebSocket relay)
β”‚   β”‚   └── src/
β”‚   β”‚       β”œβ”€β”€ lib.rs
β”‚   β”‚       β”œβ”€β”€ websocket.rs       # WebSocket connection management
β”‚   β”‚       β”œβ”€β”€ messaging.rs       # Message protocol serialization
β”‚   β”‚       β”œβ”€β”€ session.rs         # Remote session creation
β”‚   β”‚       └── auth.rs            # Bridge JWT authentication
β”‚   β”‚
β”‚   └── utils/                     # Shared utilities
β”‚       └── src/
β”‚           β”œβ”€β”€ lib.rs
β”‚           β”œβ”€β”€ git.rs             # Git operations (root, diff, log, branch)
β”‚           β”œβ”€β”€ shell.rs           # Subprocess execution, process tree kill
β”‚           β”œβ”€β”€ platform.rs        # OS/platform detection
β”‚           β”œβ”€β”€ fs.rs              # File I/O, binary detection, atomic write
β”‚           β”œβ”€β”€ diff.rs            # Text diff, string replace & uniqueness
β”‚           β”œβ”€β”€ tokens.rs          # Token count estimation
β”‚           β”œβ”€β”€ markdown.rs        # Markdown rendering, HTMLβ†’Markdown
β”‚           └── env.rs             # Environment variables, CI detection
β”‚
└── tests/
    └── integration/               # End-to-end integration tests
        β”œβ”€β”€ mod.rs
        β”œβ”€β”€ helpers/
        β”‚   β”œβ”€β”€ mod.rs
        β”‚   └── mock_api.rs        # wiremock-based Anthropic API mock
        β”œβ”€β”€ test_cli.rs            # CLI argument tests
        β”œβ”€β”€ test_query_loop.rs     # Query loop cycle tests
        β”œβ”€β”€ test_tools.rs          # Tool execution tests
        β”œβ”€β”€ test_commands.rs       # Slash command tests
        β”œβ”€β”€ test_session.rs        # Session save/restore tests
        └── test_mcp.rs            # MCP client tests

Crate Dependency Graph

cli ──┬── core
      β”œβ”€β”€ api ────── core, auth
      β”œβ”€β”€ query ──── core, api, tools, commands, utils
      β”œβ”€β”€ commands ─ core, utils
      β”œβ”€β”€ tools ──── core, utils, mcp
      β”œβ”€β”€ tui ────── core, query, utils
      β”œβ”€β”€ auth ───── core
      β”œβ”€β”€ services ─ core, api, utils
      β”œβ”€β”€ bridge ─── core, api
      β”œβ”€β”€ mcp ────── core
      └── utils ──── (standalone)

Development

Command Reference

cd claude-cli-rs   # All commands must be run from the project root

# === Build ===
cargo check --workspace                  # Quick type-check all crates (no binary output)
cargo build                              # Compile debug build (~7s incremental)
cargo build --release                    # Compile release build (~3 min first time, with LTO)

# === Run ===
cargo run                                # Launch CLI (runs target/debug/claude)
cargo run -- --version                   # Show version
cargo run -- --help                      # Show help
cargo run -- -p "Your question"          # One-shot mode
cargo run -- self-test                   # Run internal diagnostics

# === Test ===
cargo test --workspace                   # Run all unit tests
cargo test --workspace -- --test-threads=1  # Serial execution (avoids env var races)
cargo test -p claude_core                # Run tests for a specific crate
cargo test --test integration            # Run integration tests

# === Code Quality ===
cargo clippy --workspace -- -D warnings  # Lint (zero warnings required)
cargo fmt --all                          # Auto-format
cargo fmt --all -- --check               # Check formatting without modifying

# === Debug ===
cargo run -- -v                          # Verbose mode with detailed logging
RUST_LOG=debug cargo run                 # More detailed logging (macOS/Linux)
$env:RUST_LOG="debug"; cargo run         # More detailed logging (Windows PowerShell)

Project Stats

Metric Value
Rust source files 121
Lines of code ~13,000
Unit tests 523
Crates 12

Troubleshooting

cargo build hangs or times out downloading dependencies

You may need to configure a proxy or a mirror registry. See the Prerequisites > Network proxy section above.

link.exe not found on Windows

Install the C++ desktop development component of Visual Studio Build Tools. Run Visual Studio Installer, click Modify, and check "Desktop development with C++".

cargo run reports error: a bin target must be available

Ensure your root Cargo.toml has default-members = ["crates/cli"]. If it does not, run:

cargo run --bin claude

or specify the crate:

cargo run -p claude_cli

error[E0658]: edition 2024 is not yet stable

Your Rust version is below 1.85. Update:

rustup update stable

TUI displays garbled text or keys repeat

  • Ensure your terminal supports UTF-8 (Windows Terminal is recommended; legacy CMD is not)
  • Windows users should use Windows Terminal or PowerShell 7

License

MIT

About

πŸ‡A rabbit-fast Rust reimplementation inspired by Claude Code, with native TUI, deeper tooling, and a cleaner path for terminal-first AI development.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Rust 91.2%
  • PowerShell 6.0%
  • Shell 2.8%