Open-source alternative to Claude Code, built from scratch in Rust.
Inspired by Claude Code's agentic workflow -- open source, Rust-native, works with any LLM.
English | δΈζ
Status: Active Development -- 46 built-in tools Β· 33 slash commands Β· 6 permission modes Β· three-layer multi-agent architecture Β· file-history rewinding Β· extended thinking Β· TUI with 188 spinner verbs Β· 3800+ tests Β· 24 crates Β· ~129k LOC.
Claude Code pioneered the agentic coding CLI -- an AI that doesn't just suggest code, but thinks, plans, and executes autonomously in your terminal.
Crab Code brings that experience to the open-source world, independently built from the ground up in Rust:
- Fully open source -- Apache 2.0, no feature-gating, no black box
- Rust-native performance -- instant startup, minimal memory, no Node.js overhead
- Model agnostic -- Claude, GPT, DeepSeek, Qwen, Ollama, or any OpenAI-compatible API
- Secure -- 6 permission modes + tool-level allow/deny lists
- MCP compatible -- stdio, SSE, and WebSocket transports
- Claude Code aligned -- CLI flags, slash commands, tools, and workflows match Claude Code behavior
git clone https://github.com/lingcoder/crab-code.git
cd crab-code
cargo build --release
# Set your API key
export ANTHROPIC_API_KEY=sk-ant-...
# Interactive TUI mode
./target/release/crab
# Single-shot mode
./target/release/crab "explain this codebase"
# Print mode (non-interactive, reads from stdin if no prompt given)
./target/release/crab -p "fix the bug in main.rs"
# With a specific provider
./target/release/crab --provider openai --model gpt-4o "refactor auth module"Crab Code reads Claude Code's settings.json format, including the env field:
// ~/.crab/settings.json
{
"env": {
"ANTHROPIC_AUTH_TOKEN": "cr_...",
"ANTHROPIC_BASE_URL": "http://your-proxy/api"
},
"model": "claude-opus-4-6"
}- Streaming SSE -- real-time token-by-token output from LLM APIs
- Tool execution cycle -- model reasoning β tool call β permission check β execute β result β next turn
- Extended thinking --
budget_tokenssupport for deep reasoning (Anthropic thinking blocks) - Retry + fallback -- automatic retry on transient errors, model fallback on overload
- Effort levels -- low / medium / high / max mapped to API parameters
- Auto-compaction -- heuristic summarizer triggers at 80% context-window watermark;
/compactto invoke manually
| Category | Tools |
|---|---|
| File I/O | Read, Write, Edit, Glob, Grep, ImageRead |
| Execution | Bash, PowerShell (Windows) |
| Sub-agents | Agent, TeamCreate, TeamDelete, SendMessage |
| Tasks | TaskCreate, TaskGet, TaskList, TaskUpdate, TaskStop, TaskOutput, TodoWrite |
| Scheduling | CronCreate, CronDelete, CronList |
| Planning | EnterPlanMode, ExitPlanMode, VerifyPlanExecution |
| Notebook | NotebookEdit, NotebookRead |
| Web | WebFetch, WebSearch, WebBrowser |
| LSP | LSP (definition, references, hover, symbols) |
| Worktree | EnterWorktree, ExitWorktree |
| MCP | ListMcpResources, ReadMcpResource, McpAuth |
| Files | SendUserFile |
| Other | AskUserQuestion, Skill, Sleep, Snip, Brief, Config, ToolSearch, Monitor, RemoteTrigger |
Three conceptually distinct layers in crates/agent/:
- Teams β base infrastructure:
WorkerPool, per-agent mailbox router, sharedTaskList(fd-lockfile-lockedclaim_taskfor cross-process teammates), spawner backends (in-process, tmux). - Swarm β the default flat topology (
TeamMode::PeerToPeer). No extra module β it's just how teammates cooperate when no overlay is active. - Coordinator Mode β a star-topology overlay gated on
CRAB_COORDINATOR_MODE=1. The coordinator's tool registry is reduced to{Agent, SendMessage, TaskStop}; workers it spawns lose{TeamCreate, TeamDelete, SendMessage}; the coordinator's system prompt carries an anti-pattern guardrail.
Every session snapshots file edits under ~/.crab/file-history/{session_id}/ (at most 100 per session, LRU-evicted). /rewind [path] restores a file to an earlier version. Tool-level track_edit hooks on Edit / Write / Notebook are a planned follow-up; the file_history primitive is already unit-tested.
6 modes aligned with Claude Code behaviour:
- default β prompt for potentially dangerous operations
- acceptEdits β auto-approve file edits, still prompt for Bash
- trust-project β auto-approve in-project writes; out-of-project and dangerous ops still prompt
- dontAsk β auto-approve everything (no prompts)
- dangerously β auto-approve everything except
denied_tools(use with care) - plan β read-only planning mode; mutations require explicit plan approval
Plus tool-level filtering via --allowedTools / --disallowedTools with glob patterns (Bash(git:*), mcp__*, Edit).
The REPL intercepts input matching /<letter>β¦ and dispatches through SlashCommandRegistry before the prompt reaches the LLM, so paths like /tmp/foo still pass through as prompts.
/help /clear /compact /cost /status /memory /init /model /config /permissions /resume /history /export /doctor /diff /review /plan /exit /fast /effort /add-dir /files /thinking /rewind /skills /plugin /mcp /branch /commit /theme /keybindings /copy /rename
- Anthropic β Messages API with SSE streaming (default
claude-sonnet-4-6) - OpenAI-compatible β Chat Completions API (GPT, DeepSeek, Qwen, Ollama, vLLM, β¦)
- AWS Bedrock β SigV4 signing with inference profile discovery
- GCP Vertex AI β Application Default Credentials
- stdio, SSE, and WebSocket transports
McpToolAdapterbridges MCP tools to the nativeTooltrait- Configure via
~/.crab/settings.jsonor--mcp-config
- Auto-save conversation history to
~/.crab/sessions/ --continue/-cresumes the last session--resume <id>resumes a specific session--fork-sessionbranches on resume instead of continuing in-place--namefriendly session names- Per-session file-history snapshots for
/rewind
PreToolUse/PostToolUse/UserPromptSubmittriggers- Shell command execution with
Allow/Deny/Modifyresponses - Configure in
settings.json
ratatui+crosstermterminal UI, immediate-mode rendering- Markdown rendering with syntax highlighting
- Vim-mode editing
- Autocomplete for slash commands and file paths
- Permission dialogs
- Cost tracking status bar
- 188 spinner verbs mirrored from Claude Code
24 Rust crates organised in 4 layers:
Layer 4 (Entry) cli daemon
| |
Layer 3 (Orch) agent engine session
| | |
Layer 2 (Service) api tools mcp tui skill plugin telemetry acp ide job remote sandbox
| | | | | | |
Layer 1 (Found) common core config auth fs memory process
Key design decisions:
- Async runtime β tokio (multi-threaded)
- LLM dispatch β
enum LlmBackend; zero dynamic dispatch, exhaustive match - Tool system β
trait Tool+ToolRegistry+ToolExecutor, discovered via JSON Schema - TUI β
ratatui+crossterm, immediate-mode - Error handling β
thiserrorfor libraries,anyhowfor the application
Full architecture details:
docs/architecture.md
# Global
~/.crab/settings.json # API keys, provider settings, MCP servers
~/.crab/memory/ # Persistent memory files
~/.crab/sessions/ # Saved conversation sessions
~/.crab/file-history/ # Per-session pre-edit snapshots
~/.crab/skills/ # Global skill definitions
# Project
your-project/CRAB.md # Project instructions (like CLAUDE.md)
your-project/.crab/settings.json # Project-level overrides
your-project/.crab/skills/ # Project-specific skillscrab # Interactive TUI mode
crab "your prompt" # Single-shot mode
crab -p "your prompt" # Print mode (non-interactive)
crab -c # Continue last session
crab --provider openai # Use an OpenAI-compatible provider
crab --model opus # Model alias (sonnet / opus / haiku)
crab --permission-mode plan # Plan mode
crab --effort high # Set reasoning effort
crab --resume <session-id> # Resume a saved session
crab doctor # Run diagnostics
crab auth login # Configure authenticationInsider toggles (no CLI flag, env only β keeps the surface hidden from --help):
CRAB_COORDINATOR_MODE=1β enables Coordinator Mode overlayCRAB_AUTO_DREAM=1β arms theauto-dreammemory-consolidation gate (requires theauto-dreamcargo feature)
cargo build --workspace # Build all
cargo test --workspace # Run all tests (3800+)
cargo clippy --workspace -- -D warnings # Lint (CI treats warnings as errors)
cargo fmt --all --check # Check formatting
cargo run --bin crab # Run CLIExperimental cargo features (all default off):
auto-dreamoncrab-agentβ CCB-aligned memory-consolidation scheduler (runner still stubbed)proactiveoncrab-agentβ placeholder matching CCB'sfeature('PROACTIVE')posturemem-rankeroncrab-agentβ re-exportscrab-memory/mem-ranker
| Crab Code | Claude Code | OpenCode | Codex CLI | |
|---|---|---|---|---|
| Open Source | Apache 2.0 | Proprietary | MIT | Apache 2.0 |
| Language | Rust | TypeScript (Bun) | TypeScript | Rust |
| Model Agnostic | Any provider | Anthropic + AWS/GCP | Any provider | OpenAI only |
| Self-hosted | Yes | No | Yes | Yes |
| MCP Support | stdio + SSE + WS | 6 transports | LSP | 2 transports |
| TUI | ratatui | Ink (React) | Custom | ratatui |
| Built-in Tools | 46 | 52 | ~10 | ~10 |
| Permission Modes | 6 | 6 | 2 | 3 |
Areas where we'd love help:
- Claude Code feature alignment β remaining gaps include the
auto-dreamforked-agent runner, tool-leveltrack_edithooks on Edit / Write / Notebook, and theproactivemini-agent - OS-level sandboxing (Landlock / Seatbelt / Windows Job Object)
- End-to-end integration testing
- Additional LLM provider testing
- Documentation & i18n
Built with Rust by lingcoder
Claude Code showed us the future of agentic coding. Crab Code makes it open for everyone.