2026-04-01 03:55:00 +00:00
# 🦞 Claw Code — Rust Implementation
A high-performance Rust rewrite of the Claw Code CLI agent harness. Built for speed, safety, and native tool execution.
2026-04-04 15:23:22 +00:00
For a task-oriented guide with copy/paste examples, see [`../USAGE.md` ](../USAGE.md ).
2026-04-01 03:55:00 +00:00
## Quick Start
```bash
2026-04-04 15:23:22 +00:00
# Inspect available commands
2026-04-01 03:55:00 +00:00
cd rust/
2026-04-04 15:23:22 +00:00
cargo run -p rusty-claude-cli -- --help
# Build the workspace
cargo build --workspace
2026-04-01 03:55:00 +00:00
2026-04-04 15:23:22 +00:00
# Run the interactive REPL
2026-06-04 00:30:13 +09:00
cargo run -p rusty-claude-cli -- --model claude-opus-4-7
2026-04-01 03:55:00 +00:00
# One-shot prompt
2026-04-04 15:23:22 +00:00
cargo run -p rusty-claude-cli -- prompt "explain this codebase"
2026-04-01 03:55:00 +00:00
2026-04-04 15:23:22 +00:00
# JSON output for automation
cargo run -p rusty-claude-cli -- --output-format json prompt "summarize src/main.rs"
2026-04-01 03:55:00 +00:00
```
## Configuration
Set your API credentials:
```bash
export ANTHROPIC_API_KEY="sk-ant-..."
# Or use a proxy
export ANTHROPIC_BASE_URL="https://your-proxy.com"
```
2026-04-11 17:28:47 +00:00
Or provide an OAuth bearer token directly:
2026-04-01 03:55:00 +00:00
```bash
2026-04-11 17:28:47 +00:00
export ANTHROPIC_AUTH_TOKEN="anthropic-oauth-or-proxy-bearer-token"
2026-04-01 03:55:00 +00:00
```
2026-04-03 01:15:52 +00:00
## Mock parity harness
The workspace now includes a deterministic Anthropic-compatible mock service and a clean-environment CLI harness for end-to-end parity checks.
```bash
cd rust/
# Run the scripted clean-environment harness
./scripts/run_mock_parity_harness.sh
# Or start the mock service manually for ad hoc CLI runs
cargo run -p mock-anthropic-service -- --bind 127.0.0.1:0
```
Harness coverage:
- `streaming_text`
- `read_file_roundtrip`
- `grep_chunk_assembly`
- `write_file_allowed`
- `write_file_denied`
2026-04-03 04:00:33 +00:00
- `multi_tool_turn_roundtrip`
- `bash_stdout_roundtrip`
- `bash_permission_prompt_approved`
- `bash_permission_prompt_denied`
- `plugin_tool_roundtrip`
2026-04-03 01:15:52 +00:00
Primary artifacts:
- `crates/mock-anthropic-service/` — reusable mock Anthropic-compatible service
- `crates/rusty-claude-cli/tests/mock_parity_harness.rs` — clean-env CLI harness
- `scripts/run_mock_parity_harness.sh` — reproducible wrapper
2026-04-03 04:00:33 +00:00
- `scripts/run_mock_parity_diff.py` — scenario checklist + PARITY mapping runner
- `mock_parity_scenarios.json` — scenario-to-PARITY manifest
2026-04-03 01:15:52 +00:00
2026-04-01 03:55:00 +00:00
## Features
| Feature | Status |
|---------|--------|
2026-04-05 18:08:00 +00:00
| Anthropic / OpenAI-compatible provider flows + streaming | ✅ |
2026-04-11 17:28:47 +00:00
| Direct bearer-token auth via `ANTHROPIC_AUTH_TOKEN` | ✅ |
2026-04-01 03:55:00 +00:00
| Interactive REPL (rustyline) | ✅ |
| Tool system (bash, read, write, edit, grep, glob) | ✅ |
| Web tools (search, fetch) | ✅ |
2026-04-05 18:08:00 +00:00
| Sub-agent / agent surfaces | ✅ |
2026-04-01 03:55:00 +00:00
| Todo tracking | ✅ |
| Notebook editing | ✅ |
2026-06-04 16:36:04 +09:00
| CLAUDE.md / CLAW.md / AGENTS.md project memory | ✅ |
2026-04-05 18:08:00 +00:00
| Config file hierarchy (`.claw.json` + merged config sections) | ✅ |
2026-04-01 03:55:00 +00:00
| Permission system | ✅ |
2026-04-05 18:08:00 +00:00
| MCP server lifecycle + inspection | ✅ |
2026-04-01 03:55:00 +00:00
| Session persistence + resume | ✅ |
2026-04-05 18:08:00 +00:00
| Cost / usage / stats surfaces | ✅ |
2026-04-01 03:55:00 +00:00
| Git integration | ✅ |
| Markdown terminal rendering (ANSI) | ✅ |
| Model aliases (opus/sonnet/haiku) | ✅ |
2026-04-05 18:08:00 +00:00
| Direct CLI subcommands (`status` , `sandbox` , `agents` , `mcp` , `skills` , `doctor` ) | ✅ |
| Slash commands (including `/skills` , `/agents` , `/mcp` , `/doctor` , `/plugin` , `/subagent` ) | ✅ |
| Hooks (`/hooks` , config-backed lifecycle hooks) | ✅ |
| Plugin management surfaces | ✅ |
2026-06-04 03:58:35 +09:00
| Skills inventory / install / uninstall surfaces | ✅ |
2026-04-05 18:08:00 +00:00
| Machine-readable JSON output across core CLI surfaces | ✅ |
2026-04-01 03:55:00 +00:00
## Model Aliases
Short names resolve to the latest model versions:
| Alias | Resolves To |
|-------|------------|
2026-06-04 00:30:13 +09:00
| `opus` | `claude-opus-4-7` |
2026-04-01 03:55:00 +00:00
| `sonnet` | `claude-sonnet-4-6` |
| `haiku` | `claude-haiku-4-5-20251213` |
2026-04-05 18:08:00 +00:00
## CLI Flags and Commands
2026-04-01 03:55:00 +00:00
2026-04-05 18:08:00 +00:00
Representative current surface:
```text
2026-04-01 03:55:00 +00:00
claw [OPTIONS] [COMMAND]
2026-04-05 18:08:00 +00:00
Flags:
--model MODEL
2026-06-04 12:47:24 +09:00
--output-format text|json (case-insensitive; CLAW_OUTPUT_FORMAT supplies the default, flags override env)
2026-04-05 18:08:00 +00:00
--permission-mode MODE
2026-06-04 02:20:09 +09:00
--cwd PATH, -C PATH, --directory PATH
2026-06-04 01:51:21 +09:00
--dangerously-skip-permissions, --skip-permissions
2026-06-04 12:01:58 +09:00
--allowedTools TOOLS canonical snake_case names or aliases; status JSON exposes allowed_tools.available/aliases
2026-04-05 18:08:00 +00:00
--resume [SESSION.jsonl|session-id|latest]
--version, -V
Top-level commands:
prompt < text >
help
version
status
sandbox
2026-04-16 03:13:50 +00:00
acp [serve]
2026-04-05 18:08:00 +00:00
dump-manifests
bootstrap-plan
agents
mcp
skills
system-prompt
init
2026-04-01 03:55:00 +00:00
```
2026-05-15 11:40:53 +09:00
`claw acp` is a local discoverability surface for editor-first users: it reports the current ACP/Zed status without starting the runtime. As of April 16, 2026, claw-code does **not** ship an ACP/Zed daemon or JSON-RPC entrypoint yet, and `claw acp serve` is only a status alias until the real protocol surface lands. Status queries exit 0 and expose the same machine-readable contract via `--output-format json` ; malformed ACP invocations exit 1 with `kind: unsupported_acp_invocation` .
2026-06-04 12:47:24 +09:00
`--output-format` accepts `text` or `json` in any casing. `CLAW_OUTPUT_FORMAT=json` selects JSON as the default for non-interactive commands, explicit flags override it, repeated flags warn on stderr, and status JSON exposes `format_source` , `format_raw` , and `format_overridden` . Help and doctor output also surface `CLAW_LOG` / `RUST_LOG` as the logging environment knobs.
2026-06-04 15:55:08 +09:00
`claw version --output-format json` is the provenance probe for automation: it reports full `git_sha` , derived `git_sha_short` , `is_dirty` , `branch` , `commit_date` , `commit_timestamp` , `rustc_version` , runtime `executable_path` , and `binary_provenance` ; the text report is available as `human_readable` instead of a duplicate `message` field.
2026-06-04 17:07:00 +09:00
`status --output-format json` reports loaded project memory files under `workspace.memory_files[]` with each file's `path` , `source` (`claude_md` , `claw_md` , `agents_md` , or scoped/rule sources), `origin` , `scope_path` , `outside_project` , `chars` , and `contributes` ; `claw doctor --output-format json` includes a dedicated `memory` check. Root instruction-file priority is `CLAUDE.md` , then `CLAW.md` , then `AGENTS.md` , discovery is bounded to the current git root when present (otherwise cwd only), and all non-duplicate loaded files contribute to the rendered system prompt.
2026-06-04 18:31:58 +09:00
`claw mcp --output-format json` reports partial MCP config success: valid servers remain in `servers[]` while malformed siblings appear in `invalid_servers[]` , with `total_configured` , `valid_count` , and `invalid_count` split out for automation. `status` mirrors this as `mcp_validation` , and doctor includes an `mcp validation` check.
2026-06-04 23:42:58 +09:00
`status --output-format json` also reports partial hook config success under `hook_validation` : valid hook entries are retained while malformed or unknown-event siblings appear in `invalid_hooks[]` , with `valid_count` , `invalid_count` , and typed `kind` fields (`invalid_hooks_config` or `unknown_hook_event` ) for automation. `doctor --output-format json` includes a `hook validation` check, and `config --output-format json` includes `hook_validation` metadata with degraded status when invalid entries exist.
2026-06-04 13:25:15 +09:00
Shorthand prompt mode honors the POSIX `--` end-of-flags separator, so `claw -- "-prompt-with-dash"` and unknown dash-prefixed non-flag text stay on the prompt path instead of being treated as CLI options.
2026-06-04 02:46:44 +09:00
`claw dump-manifests` is self-contained: it emits the Rust resolver inventory for the selected workspace (commands, tools, agents, skills, and bootstrap phases) without requiring an upstream Claude Code TypeScript checkout. Use `--manifests-dir PATH` only to scope resolver discovery to another directory.
2026-04-16 03:13:50 +00:00
2026-04-05 18:08:00 +00:00
The command surface is moving quickly. For the canonical live help text, run:
```bash
cargo run -p rusty-claude-cli -- --help
```
2026-04-04 15:23:22 +00:00
2026-04-01 03:55:00 +00:00
## Slash Commands (REPL)
2026-04-04 15:23:22 +00:00
Tab completion expands slash commands, model aliases, permission modes, and recent session IDs.
2026-04-02 07:19:14 +00:00
2026-04-05 18:08:00 +00:00
The REPL now exposes a much broader surface than the original minimal shell:
- session / visibility: `/help` , `/status` , `/sandbox` , `/cost` , `/resume` , `/session` , `/version` , `/usage` , `/stats`
2026-04-11 17:28:47 +00:00
- workspace / git: `/compact` , `/clear` , `/config` , `/memory` , `/init` , `/diff` , `/commit` , `/pr` , `/issue` , `/export` , `/hooks` , `/files` , `/release-notes`
- discovery / debugging: `/mcp` , `/agents` , `/skills` , `/doctor` , `/tasks` , `/context` , `/desktop`
2026-04-05 18:08:00 +00:00
- automation / analysis: `/review` , `/advisor` , `/insights` , `/security-review` , `/subagent` , `/team` , `/telemetry` , `/providers` , `/cron` , and more
- plugin management: `/plugin` (with aliases `/plugins` , `/marketplace` )
Notable claw-first surfaces now available directly in slash form:
2026-06-04 03:58:35 +09:00
- `/skills [list|show <name>|install <path>|uninstall <name>|help]`
- `/agents [list|show <name>|create <name>|help]`
2026-04-05 18:08:00 +00:00
- `/mcp [list|show <server>|help]`
- `/doctor`
- `/plugin [list|install <path>|enable <name>|disable <name>|uninstall <id>|update <id>]`
- `/subagent [list|steer <target> <msg>|kill <id>]`
See [`../USAGE.md` ](../USAGE.md ) for usage examples and run `cargo run -p rusty-claude-cli -- --help` for the live canonical command list.
2026-04-04 15:23:22 +00:00
2026-04-01 03:55:00 +00:00
## Workspace Layout
2026-04-05 18:08:00 +00:00
```text
2026-04-01 03:55:00 +00:00
rust/
├── Cargo.toml # Workspace root
├── Cargo.lock
└── crates/
2026-04-05 18:08:00 +00:00
├── api/ # Provider clients + streaming + request preflight
├── commands/ # Shared slash-command registry + help rendering
2026-06-04 02:46:44 +09:00
├── compat-harness/ # Compatibility/parity harness utilities
2026-04-03 01:15:52 +00:00
├── mock-anthropic-service/ # Deterministic local Anthropic-compatible mock
2026-04-05 18:08:00 +00:00
├── plugins/ # Plugin metadata, manager, install/enable/disable surfaces
├── runtime/ # Session, config, permissions, MCP, prompts, auth/runtime loop
2026-04-01 03:55:00 +00:00
├── rusty-claude-cli/ # Main CLI binary (`claw` )
2026-04-04 15:23:22 +00:00
├── telemetry/ # Session tracing and usage telemetry types
2026-04-05 18:08:00 +00:00
└── tools/ # Built-in tools, skill resolution, tool search, agent runtime surfaces
2026-04-01 03:55:00 +00:00
```
### Crate Responsibilities
2026-04-11 17:28:47 +00:00
- **api** — provider clients, SSE streaming, request/response types, auth (`ANTHROPIC_API_KEY` + bearer-token support), request-size/context-window preflight
2026-04-05 18:08:00 +00:00
- **commands** — slash command definitions, parsing, help text generation, JSON/text command rendering
2026-06-04 02:46:44 +09:00
- **compat-harness** — compatibility and parity helpers for comparing behavior with upstream fixtures
2026-04-05 18:08:00 +00:00
- **mock-anthropic-service** — deterministic `/v1/messages` mock for CLI parity tests and local harness runs
- **plugins** — plugin metadata, install/enable/disable/update flows, plugin tool definitions, hook integration surfaces
- **runtime** — `ConversationRuntime` , config loading, session persistence, permission policy, MCP client lifecycle, system prompt assembly, usage tracking
- **rusty-claude-cli** — REPL, one-shot prompt, direct CLI subcommands, streaming display, tool call rendering, CLI argument parsing
- **telemetry** — session trace events and supporting telemetry payloads
- **tools** — tool specs + execution: Bash, ReadFile, WriteFile, EditFile, GlobSearch, GrepSearch, WebSearch, WebFetch, Agent, TodoWrite, NotebookEdit, Skill, ToolSearch, and runtime-facing tool discovery
2026-04-01 03:55:00 +00:00
## Stats
- **~20K lines** of Rust
2026-04-04 15:23:22 +00:00
- **9 crates** in workspace
2026-04-01 03:55:00 +00:00
- **Binary name:** `claw`
2026-06-04 00:30:13 +09:00
- **Default model:** `claude-opus-4-7`
2026-06-04 01:51:21 +09:00
- **Default permissions:** `workspace-write`
2026-04-01 03:55:00 +00:00
## License
See repository root.