instructkr/claw-code
The fastest repo in history to surpass 50K stars ⭐, reaching the milestone in just 2 hours after publication. Better Harness Tools that make real things done. Now writing in Rust using oh-my-codex.
Rust port of Claude Code providing an AI coding assistant harness
User prompts flow through CLI to runtime, which orchestrates Claude API calls and tool executions in a conversational loop with session persistence
Under the hood, the system uses 3 feedback loops, 3 data pools, 4 control points to manage its runtime behavior.
Structural Verdict
A 10-component cli tool with 2 connections. 102 files analyzed. Minimal connections — components operate mostly in isolation.
How Data Flows Through the System
User prompts flow through CLI to runtime, which orchestrates Claude API calls and tool executions in a conversational loop with session persistence
- Input Processing — CLI parses user input, slash commands, and session restoration requests
- Conversation Setup — Runtime initializes session state, loads configuration, and prepares system prompts
- API Communication — AnthropicClient streams requests to Claude API with authentication and retry logic
- Tool Execution — Runtime executes tool calls in sandboxed environments with permission checks
- Response Processing — SSE parser converts streaming responses to structured events for real-time display
- Session Management — Conversations are persisted and compacted when approaching context limits
System Behavior
How the system actually operates at runtime — where data accumulates, what loops, what waits, and what controls what.
Data Pools
Conversation history and message persistence
Merged settings from multiple config sources
Cached authentication tokens
Feedback Loops
- API Retry Logic (retry, balancing) — Trigger: HTTP errors or rate limits. Action: Exponential backoff and request retry. Exit: Success or max retries exceeded.
- Session Compaction (auto-scale, balancing) — Trigger: Token count exceeds threshold. Action: Summarize old messages to preserve context. Exit: Under token limit.
- Permission Prompting (circuit-breaker, balancing) — Trigger: Tool requests dangerous operations. Action: Halt execution and prompt user. Exit: User grants or denies permission.
Delays & Async Processing
- API Rate Limiting (rate-limit, ~200ms to 2s exponential backoff) — Prevents API throttling but delays responses
- Tool Execution Timeout (async-processing, ~Configurable per command) — Prevents hung processes but may interrupt long operations
- OAuth Token Refresh (eventual-consistency) — Brief authentication delay when tokens expire
Control Points
- Permission Mode (env-var) — Controls: Tool execution security level
- Auto Compaction Threshold (env-var) — Controls: When to compress conversation history. Default: 200,000 tokens
- Sandbox Configuration (feature-flag) — Controls: Process isolation and security boundaries
- MCP Server Timeout (threshold) — Controls: External tool communication limits
Technology Stack
Primary language for performance and memory safety
HTTP client for Anthropic API communication
Async runtime for concurrent operations
JSON serialization/deserialization
Command-line argument parsing
Pattern matching for text processing
File pattern matching
Recursive directory traversal
Key Components
- ConversationRuntime (service) — Orchestrates multi-turn conversations between users and Claude with tool execution and session management
rust/crates/runtime/src/conversation.rs - AnthropicClient (service) — Handles HTTP communication with Anthropic's Claude API including streaming responses and authentication
rust/crates/api/src/client.rs - Session (model) — Maintains conversation state including message history and content blocks for persistence
rust/crates/runtime/src/session.rs - execute_bash (function) — Executes bash commands in sandboxed environments with timeout and isolation controls
rust/crates/runtime/src/bash.rs - SseParser (service) — Parses Server-Sent Events from Claude API streaming responses into structured events
rust/crates/api/src/sse.rs - compact_session (function) — Summarizes and compresses conversation history when context limits are approached
rust/crates/runtime/src/compact.rs - CommandRegistry (service) — Manages available slash commands and their execution routing
rust/crates/commands/src/lib.rs - McpServerManager (service) — Manages Model Context Protocol servers for external tool integration via stdio communication
rust/crates/runtime/src/mcp_stdio.rs - RuntimeConfig (config) — Loads and merges configuration from multiple sources for runtime behavior control
rust/crates/runtime/src/config.rs - PermissionPolicy (service) — Enforces security boundaries for tool execution and file system access
rust/crates/runtime/src/permissions.rs
Configuration
src/commands.py (python-dataclass)
name(str, unknown)source_hint(str, unknown)prompt(str, unknown)handled(bool, unknown)message(str, unknown)
src/context.py (python-dataclass)
source_root(Path, unknown)tests_root(Path, unknown)assets_root(Path, unknown)archive_root(Path, unknown)python_file_count(int, unknown)test_file_count(int, unknown)asset_file_count(int, unknown)archive_available(bool, unknown)
src/cost_tracker.py (python-dataclass)
total_units(int, unknown) — default: 0events(list[str], unknown) — default: field(default_factory=list)
src/deferred_init.py (python-dataclass)
trusted(bool, unknown)plugin_init(bool, unknown)skill_init(bool, unknown)mcp_prefetch(bool, unknown)session_hooks(bool, unknown)
Explore the interactive analysis
See the full architecture map, data flow, and code patterns visualization.
Analyze on CodeSeaRelated Cli Tool Repositories
Frequently Asked Questions
What is claw-code used for?
Rust port of Claude Code providing an AI coding assistant harness instructkr/claw-code is a 10-component cli tool written in Rust. Minimal connections — components operate mostly in isolation. The codebase contains 102 files.
How is claw-code architected?
claw-code is organized into 5 architecture layers: CLI Entry, Runtime Core, API Client, Tool System, and 1 more. Minimal connections — components operate mostly in isolation. This layered structure keeps concerns separated and modules independent.
How does data flow through claw-code?
Data moves through 6 stages: Input Processing → Conversation Setup → API Communication → Tool Execution → Response Processing → .... User prompts flow through CLI to runtime, which orchestrates Claude API calls and tool executions in a conversational loop with session persistence This pipeline design reflects a complex multi-stage processing system.
What technologies does claw-code use?
The core stack includes Rust (Primary language for performance and memory safety), reqwest (HTTP client for Anthropic API communication), tokio (Async runtime for concurrent operations), serde (JSON serialization/deserialization), clap (Command-line argument parsing), regex (Pattern matching for text processing), and 2 more. A focused set of dependencies that keeps the build manageable.
What system dynamics does claw-code have?
claw-code exhibits 3 data pools (Session State, Configuration Store), 3 feedback loops, 4 control points, 3 delays. The feedback loops handle retry and auto-scale. These runtime behaviors shape how the system responds to load, failures, and configuration changes.
What design patterns does claw-code use?
5 design patterns detected: Multi-crate Workspace, Error Chain Propagation, Trait-based Abstractions, Builder Pattern, Event-driven Streaming.
Analyzed on April 1, 2026 by CodeSea. Written by Karolina Sarna.