Open Claude Code 2.0 (Nightly): The Reverse-Engineered Clone
Open Claude Code is a ground-up open source rebuild of Anthropic's Claude Code CLI, targeting v2.1.91, created via "ruDevolution" β an AI-powered decompilation of the published npm package. With 1,581 passing tests and automated nightly releases, it demonstrates functional parity while adding unique architectural choices like multi-agent teams and git worktree isolation.
What is Open Claude Code?
Open Claude Code claims to be a clean-room implementation of Claude Code β not a fork, not a wrapper, but a complete rebuild informed by AI-assisted decompilation. The project uses a process called "ruDevolution" (Reverse Evolution through AI) to analyze the published npm package and generate functionally equivalent TypeScript code.
The key difference from a simple fork: this is an independent implementation that happens to produce the same results. It can be studied, modified, and redistributed under the MIT license.
Archive vs v2
The repository contains both an archive/ directory with the decompiled
original source (7.3MB!) and a v2/ directory with the clean-room
reimplementation. The archive is for reference; v2 is the working implementation.
Core Architecture β Async Generator Agent Loop
The heart of Open Claude Code is an async generator function that yields 13 distinct event types. This is architecturally unique in this field β most agents use a callback or promise-based loop:
| Event Type | Description |
|---|---|
stream_request_start | Beginning of API request |
stream_event | Raw SSE event from API |
thinking | Extended thinking blocks |
assistant | Assistant message content |
tool_progress | Streaming tool input |
result | Tool call result |
compaction | Context compaction triggered |
hookPermissionResult | Permission hook response |
error | Error during execution |
stop | Agent requested to stop |
Key characteristics of the loop:
- Recursive execution: After tool calls, recursively calls itself with
yield* run(null, { continuation: true }) - Token tracking: Accumulates input/output tokens from API responses
- Auto-compaction: Triggers context compaction at 80% threshold
- Hook integration: Runs PreToolUse/PostToolUse hooks, can block tool execution
- Permission checking: Before tool execution, checks permissions
Context Manager β Two-Tier Compaction
Open Claude Code implements a sophisticated two-tier compaction system:
Micro-Compaction
Truncates tool results older than 5 turns to just 100 characters. This preserves the fact that something happened while dramatically reducing token usage for repeated read operations.
Full Compaction
Summarizes older messages using the LLM, keeping the last 6 messages (~3 turns). More expensive but preserves semantic meaning for complex interactions.
Token estimation uses a simple character-based heuristic: 4 characters β 1 token. No external tokenizer dependency.
Tools System β 25 Tools
Tools follow a consistent validateInput/call interface pattern:
const Tool = {
name: 'ToolName',
description: '...',
inputSchema: { type: 'object', properties: {...}, required: [...] },
validateInput(input) { return []; }, // Returns array of errors
async call(input) { return result; }
};
| Category | Tools |
|---|---|
| Core file ops | Read, Edit, Write, Glob, Grep |
| Shell | Bash (SIGTERMβSIGKILL, background jobs, 1MB limit) |
| Agent | Agent (spawn subagents), SendMessage, EnterWorktree, ExitWorktree |
| Web | WebFetch, WebSearch, ToolSearch (deferred discovery) |
| Task | TodoWrite, CronCreate/Delete/List, NotebookEdit, MultiEdit |
| System | Skill, AskUser, LSP, ReadMcpResource |
Git Worktree Isolation
The EnterWorktree and ExitWorktree tools provide
isolated git worktrees for parallel agent tasks. This is unique among the
agents in this set β most use simple process spawning for subagents.
Multi-Agent Teams System
Open Claude Code implements a full agent-to-agent messaging system:
| Operation | Description |
|---|---|
register(agent) | Register a named agent |
send(agentName, message) | Send message to specific agent |
broadcast(message) | Send message to all teammates |
getTeammates() | List all registered agents |
Custom agents are loaded from .claude/agents/{name}/agent.md with YAML
frontmatter specifying name, description, model, and tools.
Hooks System β 7 Event Types
The hook system provides deep extensibility with 7 event types:
| Hook | Can Block? | Description |
|---|---|---|
PreToolUse | Yes | Before tool execution |
PostToolUse | No | After tool execution, can modify results |
Stop | Yes | Prevent agent from stopping |
Notification | No | Fire-and-forget events |
PrePrompt | No | Modify user input |
PostResponse | No | Modify assistant output |
Hooks support both command (shell) and function
implementations, configured via settings.json.
Permissions System β 6 Modes
Open Claude Code has a comprehensive permission system:
| Mode | Behavior |
|---|---|
default | Interactive permission prompts |
auto | Approve known safe operations |
plan | Read-only mode, no edits |
acceptEdits | Accept all edits without prompting |
bypassPermissions | No permission checks |
dontAsk | Silent denial for unapproved operations |
Additional security layers include sandboxing (bubblewrap on Linux, seatbelt on macOS), injection check for command injection detection, and path check for file path validation.
MCP Implementation β 4 Transports
More comprehensive MCP support than most agents:
| Transport | Description |
|---|---|
stdio | Spawn child process, stdin/stdout communication |
SSE | Server-Sent Events over HTTP |
WebSocket | Bidirectional WebSocket |
streamable-http | POST with SSE response (latest MCP spec) |
Auto-detection from server config prioritizes: explicit transport > command (stdio) > URL pattern (ws:// β websocket, /sse β SSE, else streamable-http).
Settings Chain β 4 Sources
Configuration uses a 4-source deep merge chain:
.claude/settings.local.jsonβ local, gitignored.claude/settings.jsonβ project, shared~/.claude/settings.jsonβ user global- Managed policy β enterprise
Environment variables: 104 supported via config/env.mjs.
Unique Features Summary
Async Generator Architecture
13 distinct event types via async generator β more sophisticated event model than most agents in this set.
Extended Thinking Support
Native support for thinking blocks with configurable budget, built into the core loop.
Git Worktree Isolation
Subagents can run in isolated git worktrees β unique among these agents.
File Checkpointing + Undo
Native undo support via checkpoints.mjs β checkpoints files
before dangerous operations.
Session Teleport
Export/import sessions between machines β useful for moving a session to a different environment.
Cron Scheduling
Built-in task scheduler with cron syntax for recurring tasks.
Comparison to Claude Code
As a clean-room implementation, Open Claude Code aims for functional parity with Claude Code. Key similarities and differences:
| Aspect | Claude Code | Open Claude Code |
|---|---|---|
| Architecture | Bun + React/Ink TUI | TypeScript/Node |
| Agent Loop | Callback-based | Async generator (13 events) |
| Tool Count | 40+ | 25 |
| Slash Commands | 40+ | 40 |
| MCP Transports | 3 (stdio, SSE, WS) | 4 (+ streamable-http) |
| Permission Modes | 6 | 6 |
| AI Providers | Anthropic-first | 5 (Anthropic, OpenAI, Google, AWS, GCP) |
| Hooks | PreToolUse, PostToolUse, Stop | 7 event types |
| Tests | Extensive | 1,581 passing |
Architecture Patterns Used
- Factory pattern β for agent loop, tools, permissions
- Registry pattern β for tools (
tools.get('ToolName')) - Event-driven β via async generator yielding events
- Middleware hooks β for extensibility
- Transport abstraction β for MCP (stdio/SSE/WS/http)
- Character-based token estimation β no external tokenizer
Key Files
| File | Size | Purpose |
|---|---|---|
v2/src/core/agent-loop.mjs | 16KB | Main async generator loop |
v2/src/ui/commands.mjs | 16.8KB | 40 slash commands |
v2/src/tools/bash.mjs | 4.7KB | Shell execution |
v2/src/tools/grep.mjs | 4.8KB | Regex search |
v2/src/core/providers.mjs | 7.4KB | Multi-provider support |
v2/src/config/env.mjs | 12.8KB | 104 env vars |
v2/src/tools/registry.mjs | 3.3KB | Tool registration |
archive/open_claude_code/cli.mjs | 7.3MB | Decompiled original |
Bottom Line
Open Claude Code is remarkable for being the most complete clone implementation in this set β a functional recreation of Claude Code through reverse engineering. Its async generator architecture and 7-type hook system represent architectural choices that differ from most other agents, while features like git worktree isolation, file checkpointing, and session teleport add capabilities the original doesn't have.
The 1,581 passing tests demonstrate functional parity in core functionality. For anyone wanting to understand how Claude Code works internally, this is the most transparent view available outside of Anthropic.