Five defects found by auditing the agent stack, all of which let the harness act confidently on a wrong picture of its own state. 1. A turn that errored discarded the record of tools that had already run. The CLI hands run_turn a CLONE of the session; the turn appends the user message, each assistant reply, and a tool_result per executed tool to that clone alone. The error path dropped it while the side effects of those tools remained on disk, and the recovery path then replayed the same user input against a session showing no sign they had ever run — inviting a second execution of tools that are not idempotent. The clone is now adopted before teardown, and recovery resumes the turn instead of replaying it (new ConversationRuntime::resume_turn). 2. Every sizing guard was computed against the model NAME's context window. With a local server behind a cloud model alias that is 200k against a much smaller backend, which does not make the preflights inaccurate — it makes them unreachable. CLAW_CONTEXT_WINDOW now declares the real window; model_token_limit honours it and returns a limit for unrecognised models instead of None, max_tokens is capped to a quarter of it, and the auto-compaction threshold derives from it (70%) rather than defaulting to a 200k-window constant. 3. Whether to recover by discarding conversation history was decided by substring matching on rendered error prose, including strings that ordinary transport and decode failures also produce — so a dropped connection cost the session its transcript. Classification now happens in the API layer, where the error still has its type and the request is still in hand: typed overflow errors, plus ambiguous transport failures only when the request actually filled the window. The two copy-pasted detection blocks are gone. 4. The top-level agent loop had no iteration ceiling (usize::MAX) while spawned subagents were bounded at 32. It now gets the same bound, overridable with CLAW_MAX_TURN_ITERATIONS. 5. Auto-continue nudges were injected as USER turns, so harness-authored text was persisted, re-sent on every later request, and folded into compaction summaries as something the user had said. They are recorded as system turns now; the wire payload is unchanged. Also replaces the repository's own self-host section, which described a translator and a serving stack no longer in the request path. That file is folded into the system prompt verbatim, so it was briefing the model with an architecture that does not exist. (cherry picked from commit c8834cb4d1a3372eb70241429f641162a420297e)
🦞 Claw Code — Rust Implementation
A high-performance Rust rewrite of the Claw Code CLI agent harness. Built for speed, safety, and native tool execution.
For a task-oriented guide with copy/paste examples, see ../USAGE.md.
Quick Start
# Inspect available commands
cd rust/
cargo run -p rusty-claude-cli -- --help
# Build the workspace
cargo build --workspace
# Run the interactive REPL
cargo run -p rusty-claude-cli -- --model claude-opus-4-7
# One-shot prompt
cargo run -p rusty-claude-cli -- prompt "explain this codebase"
# JSON output for automation
cargo run -p rusty-claude-cli -- --output-format json prompt "summarize src/main.rs"
Configuration
Set your API credentials:
export ANTHROPIC_API_KEY="sk-ant-..."
# Or use a proxy
export ANTHROPIC_BASE_URL="https://your-proxy.com"
Or provide an OAuth bearer token directly:
export ANTHROPIC_AUTH_TOKEN="anthropic-oauth-or-proxy-bearer-token"
For local OpenAI-compatible servers such as Ollama, including Qwen reasoning
models, see ../docs/local-openai-compatible-providers.md.
Use the exact model tag exposed by the server, for example qwen3:latest, and
prefer OLLAMA_HOST for Ollama-specific local routing.
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.
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_textread_file_roundtripgrep_chunk_assemblywrite_file_allowedwrite_file_deniedmulti_tool_turn_roundtripbash_stdout_roundtripbash_permission_prompt_approvedbash_permission_prompt_deniedplugin_tool_roundtrip
Primary artifacts:
crates/mock-anthropic-service/— reusable mock Anthropic-compatible servicecrates/rusty-claude-cli/tests/mock_parity_harness.rs— clean-env CLI harnessscripts/run_mock_parity_harness.sh— reproducible wrapperscripts/run_mock_parity_diff.py— scenario checklist + PARITY mapping runnermock_parity_scenarios.json— scenario-to-PARITY manifest
Features
| Feature | Status |
|---|---|
| Anthropic / OpenAI-compatible provider flows + streaming | ✅ |
Direct bearer-token auth via ANTHROPIC_AUTH_TOKEN |
✅ |
| Interactive REPL (rustyline) | ✅ |
| Tool system (bash, read, write, edit, grep, glob) | ✅ |
| Web tools (search, fetch) | ✅ |
| Sub-agent / agent surfaces | ✅ |
| Todo tracking | ✅ |
| Notebook editing | ✅ |
| CLAUDE.md / CLAW.md / AGENTS.md project memory | ✅ |
Config file hierarchy (.claw.json + merged config sections) |
✅ |
| Permission system | ✅ |
| MCP server lifecycle + inspection | ✅ |
| Session persistence + resume | ✅ |
| Cost / usage / stats surfaces | ✅ |
| Git integration | ✅ |
| Markdown terminal rendering (ANSI) | ✅ |
| Model aliases (opus/sonnet/haiku) | ✅ |
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 | ✅ |
| Skills inventory / install / uninstall surfaces | ✅ |
| Machine-readable JSON output across core CLI surfaces | ✅ |
Model Aliases
Short model aliases resolve to canonical model IDs. Because the router selects a
provider from the resolved model, an alias also determines which backend and
credentials are used — choose the alias for the provider you have an API key for.
Alias resolution is case-insensitive (OPUS behaves the same as opus). Aliases
are the bare short names listed below: a prefixed form such as anthropic/opus
is not an alias, and is passed through as-is rather than expanded to
claude-opus-4-7.
| Alias | Resolves To | Provider | Auth env var |
|---|---|---|---|
opus |
claude-opus-4-7 |
Anthropic | ANTHROPIC_API_KEY |
sonnet |
claude-sonnet-4-6 |
Anthropic | ANTHROPIC_API_KEY |
haiku |
claude-haiku-4-5-20251213 |
Anthropic | ANTHROPIC_API_KEY |
grok, grok-3 |
grok-3 |
xAI | XAI_API_KEY |
grok-mini, grok-3-mini |
grok-3-mini |
xAI | XAI_API_KEY |
grok-2 |
grok-2 |
xAI | XAI_API_KEY |
kimi |
kimi-k2.5 |
DashScope (OpenAI-compatible) | DASHSCOPE_API_KEY |
Anthropic aliases track the latest published model versions. xAI models honor
XAI_BASE_URL and Kimi honors DASHSCOPE_BASE_URL for base-URL overrides. Alias
resolution is implemented in resolve_model_alias
(crates/api/src/providers/mod.rs); for
provider-specific request handling see
../docs/MODEL_COMPATIBILITY.md.
CLI Flags and Commands
Representative current surface:
claw [OPTIONS] [COMMAND]
Flags:
--model MODEL
--output-format text|json (case-insensitive; CLAW_OUTPUT_FORMAT supplies the default, flags override env)
--permission-mode MODE
--cwd PATH, -C PATH, --directory PATH
--dangerously-skip-permissions, --skip-permissions
--allowedTools TOOLS canonical snake_case names or aliases; status JSON exposes allowed_tools.available/aliases
--resume [SESSION.jsonl|session-id|latest]
--version, -V
Top-level commands:
prompt <text>
help
version
status
sandbox
acp [serve]
dump-manifests
bootstrap-plan
agents
mcp
skills
system-prompt
init
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.
--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.
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.
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.
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.
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.
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.
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.
The command surface is moving quickly. For the canonical live help text, run:
cargo run -p rusty-claude-cli -- --help
Slash Commands (REPL)
Tab completion expands slash commands, model aliases, permission modes, and recent session IDs.
The REPL now exposes a much broader surface than the original minimal shell:
- session / visibility:
/help,/status,/sandbox,/cost,/resume,/session,/version,/usage,/stats - 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 - 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:
/skills [list|show <name>|install <path>|uninstall <name>|help]/agents [list|show <name>|create <name>|help]/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 for usage examples and run cargo run -p rusty-claude-cli -- --help for the live canonical command list.
Workspace Layout
rust/
├── Cargo.toml # Workspace root
├── Cargo.lock
└── crates/
├── api/ # Provider clients + streaming + request preflight
├── commands/ # Shared slash-command registry + help rendering
├── compat-harness/ # Compatibility/parity harness utilities
├── mock-anthropic-service/ # Deterministic local Anthropic-compatible mock
├── plugins/ # Plugin metadata, manager, install/enable/disable surfaces
├── runtime/ # Session, config, permissions, MCP, prompts, auth/runtime loop
├── rusty-claude-cli/ # Main CLI binary (`claw`)
├── telemetry/ # Session tracing and usage telemetry types
└── tools/ # Built-in tools, skill resolution, tool search, agent runtime surfaces
Crate Responsibilities
- api — provider clients, SSE streaming, request/response types, auth (
ANTHROPIC_API_KEY+ bearer-token support), request-size/context-window preflight - commands — slash command definitions, parsing, help text generation, JSON/text command rendering
- compat-harness — compatibility and parity helpers for comparing behavior with upstream fixtures
- mock-anthropic-service — deterministic
/v1/messagesmock 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
Stats
- ~20K lines of Rust
- 11 crates in workspace
- Binary name:
claw - Default model:
claude-opus-4-7 - Default permissions:
workspace-write
License
See repository root.