Skip to content

Architecture Overview

The claw-code project is a clean-room reimplementation of Claude Code's agent harness in Rust, with a companion Python metadata workspace. It provides a working CLI agent (claw) that can converse with the Anthropic API, execute tools, manage sessions, and enforce permissions — all without depending on the original TypeScript codebase.

Two Implementations

The repository contains two distinct implementations:

ImplementationLanguagePurpose
rust/crates/RustA working CLI agent with agentic loop, tools, permissions, hooks, sessions, MCP
src/PythonA parity tracker that audits porting progress against JSON snapshots of the original TS surface

The Rust side is the real product — this documentation focuses on it.

Crate Dependency Graph

Key Insight

The runtime crate is the foundation — every other crate depends on it. It contains the conversation loop, permission system, hook runner, session persistence, compaction, config loading, MCP utilities, OAuth, prompt building, and more.

Module Map

Here's a quick reference of what lives where:

runtime (the foundation)

ModuleResponsibility
conversation.rsConversationRuntime — the agentic loop
permissions.rs3 escalation modes + 2 behavioral modes + PermissionPrompter trait
hooks.rsPreToolUse / PostToolUse shell hooks
session.rsSession persistence with custom JSON parser
compact.rsAuto-compaction algorithm
prompt.rsSystem prompt builder, CLAUDE.md discovery
config.rsRuntime config loader (settings.json, hooks, MCP)
mcp.rsMCP tool naming, server signatures, CCR proxy
oauth.rsPKCE OAuth flow, credential storage
bash.rsBash command execution
file_ops.rsRead/write/edit/glob/grep file operations
json.rsCustom JSON parser (no serde for sessions)
sandbox.rsSandbox environment support
usage.rsToken usage tracking
bootstrap.rsBootstrap/initialization utilities
remote.rsRemote session support
mcp_client.rsMCP client transports (Stdio, SSE, HTTP, WS, SDK)
mcp_stdio.rsMCP stdio process spawning, JSON-RPC, server manager
sse.rsIncremental SSE parser (separate from api crate's parser)

api (Anthropic API client)

ModuleResponsibility
client.rsAnthropicClient — auth, retry, streaming
sse.rsHand-rolled SSE parser
types.rsRequest/response types (Messages API)
error.rsAPI error types with retryability

tools (tool definitions)

ModuleResponsibility
lib.rsAll tool specs, execute_tool() dispatcher, agent subloop

commands (slash commands)

ModuleResponsibility
lib.rs22 slash command definitions, parser, help renderer

Data Flow

Next Steps

Dive deeper into each subsystem: