Open Claude Code 2.0 (Nightly): The Reverse-Engineered Clone

Part of Agent Harness Field Guide.

Clean-Room Implementation • v2.1.91 • 61 Files • 1,581 Tests • Nightly Releases

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.

Shameless PlugWhile we're deep-diving into complex CLI tools... let's be honest. Are you tired of feeling like nerds are trying to gatekeep the terminal life by having you memorize 30 key combos just to do basic stuff? Do you lie awake at night dreading the moment you have to edit a cryptic dotfile just to change a font size? Same. It's the AI age, we can have a crazy UI on top of the terminal with shameless amounts of AI built in to do things for you.ButtonsCLI: The terminal for

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

  • 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; }
};
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

  • 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

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.