# Claw Code > Claw Code is an open-source AI coding agent framework — a clean-room Python and Rust rewrite of the Claude Code agent harness architecture. 48k+ GitHub Stars. No proprietary code. No model weights. ## Project Overview Claw Code (instructkr/claw-code) is a clean-room reimplementation of Anthropic's Claude Code agent harness, built from scratch in Python (27.1%) and Rust (72.9%). Created by Sigrid Jin (@sigridjineth) on March 31, 2026, after the Claude Code source code was accidentally leaked via a 59.8 MB source map file in npm package @anthropic-ai/claude-code v2.1.88. The project became one of the fastest repositories in GitHub history to reach 30,000 stars, currently at 48k+ stars and 56k+ forks. The project does NOT contain any Anthropic proprietary source code, model weights, API keys, or user data. It is architecturally informed but legally independent. ## Architecture The codebase has a dual-layer architecture: ### Python Layer (src/) 60+ modules for agent orchestration: - query_engine.py — Central orchestration: sessions, turn loops (max_turns=8, max_budget_tokens=2000), streaming, compaction - tools.py — Tool inventory management: loads from JSON snapshot, filtering, permission gating - commands.py — Slash command inventory: 15 commands with categorization (builtin/plugin/skill) - runtime.py — Prompt routing, session bootstrapping, turn loop execution - models.py — Shared data models: Subsystem, PortingModule, PermissionDenial, UsageSummary - permissions.py — ToolPermissionContext with deny_names and deny_prefixes - session_store.py — JSON-based session persistence in .port_sessions/ - transcript.py — In-memory transcript with compaction (keep_last=10) - bootstrap_graph.py — 7 bootstrap stages from prefetch to query engine loop - context.py — Workspace discovery: source, tests, assets, archive roots - main.py — CLI entrypoint with 27 subcommands ### Rust Layer (rust/) 6-crate workspace for high-performance runtime: 1. **api** — Anthropic Messages API client with retry (statuses: 408, 409, 429, 500, 502, 503, 504), SSE streaming, OAuth PKCE. Constants: DEFAULT_BASE_URL="https://api.anthropic.com", ANTHROPIC_VERSION="2023-06-01", DEFAULT_MAX_RETRIES=2 2. **runtime** — 16 modules: bash (shell execution with timeout), bootstrap (12 phases), compact (preserve_recent=4, max_tokens=10000), config (3 sources: User/Project/Local), conversation (ConversationRuntime with max_iterations=16), file_ops (read/write/edit/glob/grep), json (zero-dep parser), mcp (tool naming: mcp__{server}__{tool}), mcp_client (6 transports), oauth (PKCE, credentials at ~/.claude/credentials.json), permissions (Allow/Deny/Prompt modes), prompt (SystemPromptBuilder, MAX_INSTRUCTION_FILE_CHARS=4000), remote, session (MessageRole: System/User/Assistant/Tool), sse, usage (pricing: sonnet $15/$75, haiku $1/$5, opus $15/$75 per million tokens) 3. **tools** — 19 tool specs with JSON schemas: bash, read_file, write_file, edit_file, glob_search, grep_search, WebFetch, WebSearch, TodoWrite, Skill, Agent, ToolSearch, NotebookEdit, Sleep, SendUserMessage, Config, StructuredOutput, REPL, PowerShell 4. **commands** — 15 slash commands: /help, /status, /compact, /model, /permissions, /clear, /cost, /resume, /config, /memory, /init, /exit, /diff, /version, /export, /session (11 of 15 support resume) 5. **compat-harness** — TypeScript compatibility layer 6. **rusty-claude-cli** — Terminal binary: DEFAULT_MODEL="claude-sonnet-4-20250514", braille spinner, syntect syntax highlighting (base16-ocean.dark), pulldown_cmark markdown rendering, crossterm raw mode line editor, OAuth login/logout, output formats (Text/Json/Ndjson) ## Key Features - **19 Built-in Tools**: Permission-gated capabilities including file I/O, shell execution, web fetching, notebook editing, sub-agent spawning, and more - **15 Slash Commands**: Interactive session control with resume support, cost tracking, model switching, and compaction - **Multi-Agent Orchestration**: Sub-agent ("swarm") spawning for parallel task decomposition - **MCP Integration**: 6 transport types (Stdio, SSE, HTTP, WebSocket, SDK, ClaudeAiProxy) with OAuth authentication - **Session Persistence**: JSON-based session store with transcript compaction and context discovery - **Permission System**: Three modes (Allow, Deny, Prompt) with per-tool granularity via BTreeMap policy - **Provider-Agnostic**: Abstraction layer supporting Claude, OpenAI, and local LLM providers ## Environment Variables ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN, ANTHROPIC_BASE_URL, ANTHROPIC_MODEL, RUSTY_CLAUDE_PERMISSION_MODE, CLAUDE_CONFIG_HOME, CLAUDE_CODE_REMOTE, CLAUDE_CODE_REMOTE_SESSION_ID, CLAUDE_CODE_UPSTREAM, CLAWD_WEB_SEARCH_BASE_URL ## Origin The Claude Code source leak on March 31, 2026 revealed: ~40 tools (29K lines of TypeScript), query engine (46K lines), multi-agent swarms, IDE bridge (JWT auth), KAIROS mode (proactive assistant), ULTRAPLAN mode (remote Opus planning), autoDream service (background memory consolidation), and 44 feature flags (20 hidden). Claw Code reimplements these architectural patterns without copying proprietary code. ## Links - Website: https://claw-code.codes/ - GitHub: https://github.com/instructkr/claw-code - Author: Sigrid Jin (@sigridjineth) - Community: https://instruct.kr/ (instructkr Discord) ## Documentation Pages - Architecture: https://claw-code.codes/architecture - Tool System (19 tools): https://claw-code.codes/tool-system - Commands (15 slash commands): https://claw-code.codes/commands - Rust Runtime (6 crates): https://claw-code.codes/rust-runtime - Query Engine: https://claw-code.codes/query-engine - Session Management: https://claw-code.codes/session-management - Permission System: https://claw-code.codes/permissions - MCP Integration: https://claw-code.codes/mcp-integration - API Client: https://claw-code.codes/api-client - Getting Started: https://claw-code.codes/getting-started - Source Leak Timeline: https://claw-code.codes/source-leak-timeline - Comparison (vs Claude Code): https://claw-code.codes/comparison