← AI Coding Guides β€Ί Deep Dives
Clean-Room Implementation β€’ v2.1.91 β€’ 61 Files β€’ 1,581 Tests β€’ Nightly Releases

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.

(Alright, ad over. Back to the serious technical analysis.)

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 TypeDescription
stream_request_startBeginning of API request
stream_eventRaw SSE event from API
thinkingExtended thinking blocks
assistantAssistant message content
tool_progressStreaming tool input
resultTool call result
compactionContext compaction triggered
hookPermissionResultPermission hook response
errorError during execution
stopAgent requested to stop

Key characteristics of the loop:

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; }
};
CategoryTools
Core file opsRead, Edit, Write, Glob, Grep
ShellBash (SIGTERM→SIGKILL, background jobs, 1MB limit)
AgentAgent (spawn subagents), SendMessage, EnterWorktree, ExitWorktree
WebWebFetch, WebSearch, ToolSearch (deferred discovery)
TaskTodoWrite, CronCreate/Delete/List, NotebookEdit, MultiEdit
SystemSkill, 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:

OperationDescription
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:

HookCan Block?Description
PreToolUseYesBefore tool execution
PostToolUseNoAfter tool execution, can modify results
StopYesPrevent agent from stopping
NotificationNoFire-and-forget events
PrePromptNoModify user input
PostResponseNoModify 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:

ModeBehavior
defaultInteractive permission prompts
autoApprove known safe operations
planRead-only mode, no edits
acceptEditsAccept all edits without prompting
bypassPermissionsNo permission checks
dontAskSilent 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:

TransportDescription
stdioSpawn child process, stdin/stdout communication
SSEServer-Sent Events over HTTP
WebSocketBidirectional WebSocket
streamable-httpPOST 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:

  1. .claude/settings.local.json β€” local, gitignored
  2. .claude/settings.json β€” project, shared
  3. ~/.claude/settings.json β€” user global
  4. 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:

AspectClaude CodeOpen Claude Code
ArchitectureBun + React/Ink TUITypeScript/Node
Agent LoopCallback-basedAsync generator (13 events)
Tool Count40+25
Slash Commands40+40
MCP Transports3 (stdio, SSE, WS)4 (+ streamable-http)
Permission Modes66
AI ProvidersAnthropic-first5 (Anthropic, OpenAI, Google, AWS, GCP)
HooksPreToolUse, PostToolUse, Stop7 event types
TestsExtensive1,581 passing

Architecture Patterns Used

Key Files

FileSizePurpose
v2/src/core/agent-loop.mjs16KBMain async generator loop
v2/src/ui/commands.mjs16.8KB40 slash commands
v2/src/tools/bash.mjs4.7KBShell execution
v2/src/tools/grep.mjs4.8KBRegex search
v2/src/core/providers.mjs7.4KBMulti-provider support
v2/src/config/env.mjs12.8KB104 env vars
v2/src/tools/registry.mjs3.3KBTool registration
archive/open_claude_code/cli.mjs7.3MBDecompiled 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.