README.md

May 2, 2026 · View on GitHub

Crab Code

Open-source alternative to Claude Code, built from scratch in Rust.

Rust License CI PRs Welcome

English | 中文


Active Development — 4700+ tests · 27 crates · ~149k LOC

Crab Code is a Rust-native agentic coding CLI. It aligns with Claude Code's toolset, permission model, and interaction patterns while supporting any LLM provider (Anthropic / OpenAI / DeepSeek / Bedrock / Vertex).

Quick Start

git clone https://github.com/lingcoder/crab-code.git && cd crab-code
cargo build --release
export ANTHROPIC_API_KEY=sk-ant-...

./target/release/crab                   # Interactive TUI
./target/release/crab "explain this codebase"   # Single-shot
./target/release/crab -p "fix the bug"  # Non-interactive

See crab --help for more. Config lives at ~/.crab/config.toml (snake_case TOML); the full loading & merge spec is in docs/config-design.md.

Configuration

Config sources, low → high priority:

defaults  <  plugin  <  user  <  project  <  local  <  --config <file>     (file layer)
                                                            <
                                                       env  <  CLI flag    (runtime layer)
  • User: ~/.crab/config.toml (or $CRAB_CONFIG_DIR/config.toml)
  • Project: $PWD/.crab/config.toml (committed)
  • Local: $PWD/.crab/config.local.toml (gitignored)
  • --config <path>: CLI-injected file
  • -c key.path=value: dotted runtime override (TOML grammar; repeatable)

Example config.toml:

api_provider = "deepseek"
base_url = "https://api.deepseek.com/v1"
model = "deepseek-chat"
api_key = "sk-..."           # optional; env wins if both set

[permissions]
allow = ["Bash(git:*)", "Read", "Edit"]
deny  = ["Bash(rm:*)"]       # deny always wins over allow

Environment Variables

Env (runtime layer) always wins over file. Mutually-exclusive variants apply highest-first.

CategoryVariablePurpose
ProviderCRAB_API_PROVIDEROverride provider: anthropic, openai, deepseek, bedrock, vertex, custom
ProviderCRAB_API_KEYUniversal API key (any provider; highest priority)
ProviderCRAB_MODELOverride model name
ProviderCRAB_BASE_URLUniversal base URL override
ProviderCRAB_CONFIG_DIRRelocate config root (default ~/.crab/)
ProviderANTHROPIC_API_KEY / ANTHROPIC_AUTH_TOKENAnthropic provider only
ProviderANTHROPIC_BASE_URLAnthropic base URL (only when CRAB_API_PROVIDER=anthropic)
ProviderOPENAI_API_KEYOpenAI provider
ProviderOPENAI_BASE_URLOpenAI base URL (only when CRAB_API_PROVIDER=openai)
ProviderDEEPSEEK_API_KEYDeepSeek provider
ProviderDEEPSEEK_BASE_URLDeepSeek base URL (only when CRAB_API_PROVIDER=deepseek)
BedrockAWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEYStatic credentials
BedrockAWS_SESSION_TOKENOptional session token (temporary credentials)
BedrockAWS_REGION / AWS_DEFAULT_REGIONAWS region
BedrockAWS_ROLE_ARNIAM role ARN to assume
BedrockAWS_WEB_IDENTITY_TOKEN_FILEOIDC token file (web-identity role assumption)
BedrockAWS_EXTERNAL_IDExternal ID for cross-account role assumption
BedrockAWS_ROLE_SESSION_NAMESession name for assumed role
VertexGOOGLE_CLOUD_PROJECT / GCLOUD_PROJECTGCP project ID
VertexGOOGLE_CLOUD_REGIONGCP region (default: us-central1)
VertexGOOGLE_APPLICATION_CREDENTIALSPath to service account key JSON
ShellCRAB_SHELLPath to bash/zsh binary (overrides auto-detection for the Bash tool)
ShellSHELLPOSIX fallback when CRAB_SHELL is unset
ShellCRAB_USE_POWERSHELL_TOOLTruthy value exposes the PowerShell tool on Windows (default off)
AgentCRAB_COORDINATOR_MODE1 enables Agent Teams coordinator mode
AgentCRAB_AUTO_DREAM1 enables background memory consolidation between sessions
AgentCRAB_AUTO_DREAM_MIN_HOURSMinimum hours between consolidations (default: 6)
AgentCRAB_AUTO_DREAM_MIN_SESSIONSMinimum sessions before consolidation triggers (default: 2)
TLSCRAB_CA_BUNDLEPath to custom CA certificate bundle (PEM)
TLSSSL_CERT_FILE / SSL_CERT_DIRStandard OpenSSL CA overrides

Comparison

Crab CodeClaude CodeOpenCodeCodex CLI
Open SourceApache 2.0ProprietaryMITApache 2.0
LanguageRustTypeScriptTypeScriptRust
ModelsAny providerAnthropicAny providerOpenAI only
MCP3 transports6 transportsLSP2 transports

Architecture

27 Rust crates in 4 layers. See docs/architecture.md for details.

Entry     cli · daemon · acp
Engine    agents · engine · session · tui · remote
Service   api · tools · commands · hooks · mcp · skills · plugin · telemetry · ide · sandbox · swarm · cron · fs · memory · process
Foundation core · utils · config · auth

Build & Test

cargo build --workspace
cargo nextest run --workspace          # or: cargo test --workspace
cargo clippy --workspace -- -D warnings

Contributing

PRs welcome.

License

Apache License 2.0