claw-code/rust/README.md

150 lines
4.5 KiB
Markdown

# ๐Ÿฆž Claw Code โ€” Rust Implementation
A high-performance Rust rewrite of the Claw Code CLI agent harness. Built for speed, safety, and native tool execution.
## Quick Start
```bash
# Build
cd rust/
cargo build --release
# Run interactive REPL
./target/release/claw
# One-shot prompt
./target/release/claw prompt "explain this codebase"
# With specific model
./target/release/claw --model sonnet prompt "fix the bug in main.rs"
```
## Configuration
Set your API credentials:
```bash
export ANTHROPIC_API_KEY="sk-ant-..."
# Or use a proxy
export ANTHROPIC_BASE_URL="https://your-proxy.com"
```
Or authenticate via OAuth:
```bash
claw login
```
## Features
| Feature | Status |
|---------|--------|
| Anthropic API + streaming | โœ… |
| OAuth login/logout | โœ… |
| Interactive REPL (rustyline) | โœ… |
| Tool system (bash, read, write, edit, grep, glob) | โœ… |
| Web tools (search, fetch) | โœ… |
| Sub-agent orchestration | โœ… |
| Todo tracking | โœ… |
| Notebook editing | โœ… |
| CLAUDE.md / project memory | โœ… |
| Config file hierarchy (.claude.json) | โœ… |
| Permission system | โœ… |
| MCP server lifecycle | โœ… |
| Session persistence + resume | โœ… |
| Extended thinking (thinking blocks) | โœ… |
| Cost tracking + usage display | โœ… |
| Git integration | โœ… |
| Markdown terminal rendering (ANSI) | โœ… |
| Model aliases (opus/sonnet/haiku) | โœ… |
| Slash commands (/status, /compact, /clear, etc.) | โœ… |
| Hooks (PreToolUse/PostToolUse) | ๐Ÿ”ง Config only |
| Plugin system | ๐Ÿ“‹ Planned |
| Skills registry | ๐Ÿ“‹ Planned |
## Model Aliases
Short names resolve to the latest model versions:
| Alias | Resolves To |
|-------|------------|
| `opus` | `claude-opus-4-6` |
| `sonnet` | `claude-sonnet-4-6` |
| `haiku` | `claude-haiku-4-5-20251213` |
## CLI Flags
```
claw [OPTIONS] [COMMAND]
Options:
--model MODEL Set the model (alias or full name)
--dangerously-skip-permissions Skip all permission checks
--permission-mode MODE Set read-only, workspace-write, or danger-full-access
--allowedTools TOOLS Restrict enabled tools
--output-format FORMAT Output format (text or json)
--version, -V Print version info
Commands:
prompt <text> One-shot prompt (non-interactive)
login Authenticate via OAuth
logout Clear stored credentials
init Initialize project config
doctor Check environment health
self-update Update to latest version
```
## Slash Commands (REPL)
| Command | Description |
|---------|-------------|
| `/help` | Show help |
| `/status` | Show session status (model, tokens, cost) |
| `/cost` | Show cost breakdown |
| `/compact` | Compact conversation history |
| `/clear` | Clear conversation |
| `/model [name]` | Show or switch model |
| `/permissions` | Show or switch permission mode |
| `/config [section]` | Show config (env, hooks, model) |
| `/memory` | Show CLAUDE.md contents |
| `/diff` | Show git diff |
| `/export [path]` | Export conversation |
| `/session [id]` | Resume a previous session |
| `/version` | Show version |
## Workspace Layout
```
rust/
โ”œโ”€โ”€ Cargo.toml # Workspace root
โ”œโ”€โ”€ Cargo.lock
โ””โ”€โ”€ crates/
โ”œโ”€โ”€ api/ # Anthropic API client + SSE streaming
โ”œโ”€โ”€ commands/ # Shared slash-command registry
โ”œโ”€โ”€ compat-harness/ # TS manifest extraction harness
โ”œโ”€โ”€ runtime/ # Session, config, permissions, MCP, prompts
โ”œโ”€โ”€ rusty-claude-cli/ # Main CLI binary (`claw`)
โ””โ”€โ”€ tools/ # Built-in tool implementations
```
### Crate Responsibilities
- **api** โ€” HTTP client, SSE stream parser, request/response types, auth (API key + OAuth bearer)
- **commands** โ€” Slash command definitions and help text generation
- **compat-harness** โ€” Extracts tool/prompt manifests from upstream TS source
- **runtime** โ€” `ConversationRuntime` agentic loop, `ConfigLoader` hierarchy, `Session` persistence, permission policy, MCP client, system prompt assembly, usage tracking
- **rusty-claude-cli** โ€” REPL, one-shot prompt, streaming display, tool call rendering, CLI argument parsing
- **tools** โ€” Tool specs + execution: Bash, ReadFile, WriteFile, EditFile, GlobSearch, GrepSearch, WebSearch, WebFetch, Agent, TodoWrite, NotebookEdit, Skill, ToolSearch, REPL runtimes
## Stats
- **~20K lines** of Rust
- **6 crates** in workspace
- **Binary name:** `claw`
- **Default model:** `claude-opus-4-6`
- **Default permissions:** `danger-full-access`
## License
See repository root.