# Claude Code vs OpenClaw: 510K vs 530K Lines Source Code Showdown

> After Claude Code's source leak exposed 512K lines of TypeScript, we finally get a true apples-to-apples comparison with OpenClaw — architecture, agent definitions, security, and design philosophy.

- Author: zhuermu
- Published: 2026-04-01
- Updated: 2026-04-01
- Web version: https://zhuermu.com/en/blog/the-real-showdown-after-the-source-leak-claude-code-vs-openclaw-510k-lines-vs-530k-lines/

---
> This article merges and supersedes two earlier pieces on the OpenClaw vs Claude Code architecture — now updated with the full leaked Claude Code source, so both sides can finally be compared line-for-line.

## 1. Updated Numbers: Two 500K-Line TypeScript Behemoths

Last time we could only compare OpenClaw's full source against Claude Code's config layer. Now we can finally see the complete picture:

| Dimension | Claude Code (Leaked) | OpenClaw (Latest main) |
|-----------|---------------------|----------------------|
| Source files | 1,884 .ts/.tsx (no tests) | 3,044 .ts (no tests) |
| Lines of code | ~512,000 | ~530,000 |
| Core language | TypeScript + React (Ink) | TypeScript (ESM) |
| Build tool | Bun bundler | tsdown + pnpm workspace |
| UI framework | Ink (React terminal rendering) | TUI (custom terminal UI) |
| Built-in tools | 42 tool directories | Plugin dynamic registration |
| Slash commands | 86 command directories | Registered via commands/ |
| Multi-agent | Swarm (Tmux/iTerm/in-process) | Sub-agent registry + ACP |
| LLM support | Anthropic Claude only | 30+ providers |
| Interfaces | CLI + IDE + Web + Mobile | 40+ channels + TUI + Web |

OpenClaw hasn't been idle either — growing from 450K to 530K lines since our last analysis, adding ACP (Agent Control Plane), a TUI terminal interface, Canvas Host, image generation, media understanding, TTS voice synthesis, device pairing, secrets management, and more. Both projects are evolving at breakneck speed.

---

## 2. Agent Loop: Single-Threaded Minimalism vs Distributed Runtime

### Claude Code: The Main Loop Codenamed nO

The leaked source reveals Claude Code's core — a single-threaded agent loop in `QueryEngine.ts`. The design philosophy is **radical simplicity**: `while(tool_call) → execute tool → feed results back → repeat`. The loop naturally terminates when the model returns plain text with no tool calls.

An async dual-buffer queue (`h2A`) lets users inject new instructions in real-time while the agent is working. A context compressor (`wU2`) auto-triggers summarization at ~92% context window usage. A token budget tracker controls continuation at a 90% threshold, stopping when 3 consecutive increments fall below 500 tokens (diminishing returns).

```typescript
// Task.ts — 7 task types hint at ambitions far beyond a CLI tool
export type TaskType =
  | 'local_bash'           // Local shell
  | 'local_agent'          // Local sub-agent
  | 'remote_agent'         // Remote agent
  | 'in_process_teammate'  // In-process teammate
  | 'local_workflow'       // Local workflow
  | 'monitor_mcp'          // MCP monitoring
  | 'dream'                // Dream mode (autonomous background execution)
```

### OpenClaw: New ACP (Agent Control Plane)

OpenClaw's latest version introduces `src/acp/` — an Agent Control Plane with an approval classifier, session mapper, policy engine, and event translator. OpenClaw is evolving from an "agent runtime" into an "agent management platform."

```
src/acp/
├── approval-classifier.ts    # Approval classifier
├── policy.ts                 # Policy engine
├── session-mapper.ts         # Session mapping
├── translator.ts             # Event translator
├── control-plane/            # Control plane core
└── runtime/                  # ACP runtime
```

The divergence remains clear: Claude Code chooses **single-threaded + radical simplicity**, OpenClaw chooses **distributed + radical flexibility**. But OpenClaw's ACP module signals a push toward enterprise-grade agent orchestration.

---

## 3. Tool System: 42 Hand-Crafted Tools vs Plugin-Based Infinite Extension

### Claude Code: BashTool Is the Crown Jewel

42 tools, each with its own directory. BashTool alone spans 18 files, implementing 7 layers of security: segmented command permissions, injection detection, dangerous command identification, mode validation, sandbox isolation, classifier approval, and subprocess environment variable scrubbing.

```typescript
// Tool.ts — The tool base class interface is remarkably rich
interface Tool<Input, Output> {
  call(input, context): Promise<Output>
  isReadOnly(input): boolean
  isDestructive?(input): boolean
  checkPermissions(input, context): PermissionResult
  toAutoClassifierInput(input): unknown  // Input for auto-classifier
  renderToolUseMessage(input): ReactNode // Terminal UI rendering
  // ... 20+ methods
}
```

### OpenClaw: New Image Generation, Media Understanding, TTS

OpenClaw's latest tool ecosystem has expanded significantly:
- `src/image-generation/` — Image generation provider registry, multi-model support
- `src/media-understanding/` — Audio transcription, video understanding, image analysis
- `src/tts/` — Text-to-speech with multiple TTS providers
- `src/web-search/` — Standalone web search runtime
- `src/link-understanding/` — Link content understanding

OpenClaw's tools aren't 42 hand-crafted built-ins — they're an **extensible capability framework**. Each capability module has its own provider registry, supporting plugin-based extension.

---

## 4. Multi-Agent: Visual Swarm vs Structured Sub-Agent Registry

### Claude Code: A Complete Swarm System

This was the biggest surprise in the leaked source. 22 files implement full multi-agent collaboration:

- **Team Lead** orchestrates tasks, delegates to multiple **Teammates**
- Three backends: Tmux split panes, iTerm2 split panes, in-process
- `SendMessageTool` enables peer-to-peer messaging between agents
- `coordinator/coordinatorMode.ts` implements coordinator mode
- The `dream` task type hints at autonomous background execution

### OpenClaw: Sub-Agent Registry + Orphan Recovery

OpenClaw's sub-agent system is also evolving. The latest code has 20+ `subagent-registry` related files, adding:
- `subagent-orphan-recovery.ts` — Orphaned sub-agent recovery
- `subagent-registry-cleanup.ts` — Registry cleanup
- `subagent-registry-persistence.ts` — Persistence
- `subagent-announce-queue.ts` — Announcement queue

The difference: Claude Code's Swarm is **visual** (you can see multiple terminal panes working simultaneously), while OpenClaw's multi-agent is **structural** (code defines strict hierarchies and lifecycles).

---

## 5. Agent Definition: Declarative Markdown vs Imperative TypeScript

Even with both sources now fully visible, this is where the two projects diverge most sharply — not in scale, but in *what they believe an agent is*.

### Claude Code: one agent = one file of intent

Claude Code's plugin-layer agents are defined declaratively. A complete `code-reviewer` agent is just a YAML header plus a natural-language prompt:

```markdown
---
name: code-reviewer
description: Reviews code for bugs, logic errors, security vulnerabilities...
tools: Glob, Grep, LS, Read, WebFetch, WebSearch
model: sonnet
---

You are a code reviewer. Your job is to...
(the rest is pure natural-language system prompt)
```

Its `code-review` command goes further: a ~200-line Markdown file describes a **7-step pipeline orchestrating 10+ parallel sub-agents** — in plain English, with zero lines of code. The runtime parses the prose and schedules the agents.

**Design philosophy: trust the model's comprehension. Natural language *is* code.**

### OpenClaw: the agent is an engineered system

OpenClaw resolves agents through explicit configuration structures (`src/agents/agent-scope.ts`) — model with fallback chains, workspace isolation, sandbox policy, tool allow/deny lists. Sub-agent spawn control is the tell:

```typescript
export function resolveSubagentCapabilities(params: {
  depth: number; maxSpawnDepth?: number;
}) {
  const role = resolveSubagentRoleForDepth(params); // "main" | "orchestrator" | "leaf"
  return {
    role,
    canSpawn: role === "main" || role === "orchestrator",
    canControlChildren: role !== "leaf",
  };
}
```

A `leaf` agent *cannot* spawn — enforced structurally in code, not by a prompt asking the model to please stop recursing.

**Design philosophy: don't trust the model's self-restraint. Build deterministic boundaries in code.**

This single contrast — declarative intent vs imperative enforcement — is the root from which every other difference below grows.

---

## 6. Prompt Orchestration: Claude Code's Real Moat

The leaked source confirms: **all of Claude Code's "intelligence" comes from carefully orchestrated prompts.** No special APIs, no proprietary protocols — CLAUDE.md, Skills, Memories are all injected as plain text into the context window.

`prompts.ts` contains 20+ section generator functions that dynamically assemble the system prompt, with a caching mechanism (`systemPromptSection()` computes once, `DANGEROUS_uncachedSystemPromptSection()` recomputes every turn but requires a stated reason).

The most explosive finding is the `feature()` function controlling unreleased capabilities — we found **89 distinct feature flags** in the source, covering a massive set of built-but-unshipped features:
- **PROACTIVE / KAIROS**: Proactive mode, agent initiates actions autonomously
- **COORDINATOR_MODE**: One Claude orchestrating multiple Claudes
- **TRANSCRIPT_CLASSIFIER**: AFK mode, agent continues working when user is away
- **ant-only internal tools**: Available only to Anthropic employees
- **VOICE_MODE**: Voice command mode
- **WEB_BROWSER_TOOL**: Real browser control via Playwright
- **KAIROS_DREAM**: Autonomous background execution + self-wake
- **KAIROS_GITHUB_WEBHOOKS**: GitHub webhooks triggering agents
- Plus BUDDY (companion sprite), ULTRAPLAN, ULTRATHINK, VERIFICATION_AGENT, and dozens more

All of this code is already written — just excluded at compile time. Anthropic's cadence of shipping a new feature every two weeks isn't because they develop fast — it's because **everything is already done**.

---

## 7. Security Model: Classifier Approval vs Code Enforcement

Claude Code's Auto mode uses an **independent classifier** to approve each operation (classifier input strips tool results to prevent injection), backed by OS-level sandboxing. Three permission tiers: Plan (read-only), Default (confirm each action), Auto (classifier approval, labeled "research preview").

OpenClaw uses **code enforcement** — tool profiles (minimal/coding/messaging/full), owner-only filtering, path traversal detection, and an exec approval system (`src/infra/exec-approvals.ts` with 20+ related files).

Neither trusts the model's self-restraint. Claude Code uses another AI to supervise AI. OpenClaw uses code to constrain AI.

---

## 8. Easter Eggs

- **187 Spinner Verbs**: From `Clauding` to `Flibbertigibbeting` to `Whatchamacalliting` — users can even customize them
- **Buddy Companion Sprite**: `src/buddy/` hides a terminal companion character with its own prompt and sprite graphics
- **Full Vim Engine**: motions, operators, text objects, transitions — not just keybindings, a complete Vim implementation
- **Bridge Remote Control**: 30 files implementing phone/browser control of local Claude Code sessions, with JWT auth and trusted device management

---

## 9. Impact of the Leak & Personal Takeaways

### Impact on Anthropic

This is the second time Claude Code has leaked via source maps (the first was February 2025). Making the same mistake twice points to a systemic gap in Anthropic's CI/CD pipeline for build artifact verification. That said, the leak involves client implementation code — no model weights, no user data — so the direct security risk is limited.

The real impact is **competitive intelligence**. 510K lines of carefully crafted TypeScript, including complete prompt orchestration strategies, security model implementations, multi-agent collaboration architecture, and 89 feature flags controlling unreleased capabilities — all of Anthropic's hard-won engineering know-how is now public.

### Impact on the Chinese Tech Ecosystem: A Claude Code Clone Wave Is Coming

This is the point I most want to make.

The Claude Code source leak may impact China's AI coding tool ecosystem more than it impacts Anthropic itself. The reason is simple: **510K lines of battle-tested TypeScript code is a ready-made product blueprint.**

What we can expect:
1. **Major tech companies will move fast.** Claude Code's architecture (single-threaded main loop + prompt orchestration + tool system + multi-agent Swarm) is now a proven product pattern. Chinese AI coding tools (Tongyi Lingma, Doubao MarsCode, Baidu Comate, etc.) now have a detailed reference implementation.
2. **Open-source "tribute" projects will proliferate.** People are already organizing the deobfuscated source on GitHub. Reimplementations in various languages will follow.
3. **Prompt orchestration methodology will be widely adopted.** Claude Code's 20+ dynamic section assembly, caching strategies, feature flag control — this prompt engineering methodology is more practical than any research paper.
4. **Security models will be studied and improved.** BashTool's 7-layer security checks, Auto mode's classifier approval — these implementation details are valuable reference material for the entire industry's agent security practices.

But let me also throw some cold water: **copying architecture is easy; copying experience is hard.** A huge portion of Claude Code's 510K lines goes into Ink terminal rendering, Vim mode, theming, the Buddy sprite, 187 spinner verbs — all these "useless" details. It's precisely these details that make Claude Code *feel right*. That product feel can't be replicated by forking a repo.

### Impact on OpenClaw

As an open-source project, OpenClaw may actually benefit from this leak. Two reasons:

1. **Design direction validated.** Many of OpenClaw's architectural decisions (plugin-based tool system, multi-model fallback, sub-agent depth control) have counterparts in Claude Code's source. Two teams thinking independently arrived at similar conclusions.
2. **Differentiation is now crystal clear.** Claude Code is a single-vendor, developer-focused polished tool; OpenClaw is a multi-vendor, multi-platform agent runtime. The leak turns this positioning difference from "speculation" into "confirmation."

OpenClaw's latest additions — ACP (Agent Control Plane), TUI, device pairing, secrets management — show it pushing toward enterprise agent platform territory, an area Claude Code doesn't currently cover.

### Personal Take

The biggest insight from this leak isn't a technical detail — it's a confirmation of product philosophy:

**The core competitive advantage of AI agents isn't the model. It's the engineering.**

Both Claude Code and OpenClaw are 500K-line TypeScript engineering efforts. Their "intelligence" comes from carefully orchestrated prompts, precisely controlled security boundaries, and extensive UX polish — not from some mysterious model capability.

This means the competition in AI agents is fundamentally a **competition in engineering capability**. Whoever can make prompt orchestration more precise, security models deeper, and user experience more polished — wins.

Models are infrastructure. Engineering is the moat.

---

## 10. Which Approach Should You Build On?

The split between the two projects comes down to a single question: **can an AI model's comprehension replace code's determinism?** Claude Code answers *yes*; OpenClaw answers *no*. Both are right — it depends on what you are shipping.

**Go the Claude Code route (declarative / Markdown-driven) when:**

- Your agent targets a single, well-defined scenario (code review, doc generation, feature development)
- You trust the underlying model and will trade code for prompt engineering
- You want non-programmers to define agent behavior
- Your users are developers and your interface is a terminal or IDE
- You prioritize rapid iteration over runtime control

**Go the OpenClaw route (imperative / code-driven) when:**

- Your agent must support multiple LLM providers
- You need precise control over behavior boundaries, especially in multi-user scenarios
- You must deploy across platforms (messaging channels, APIs, native clients)
- You need deterministic security guarantees that cannot depend on model "self-discipline"
- You are building an agent *platform*, not a single agent

### Convergence ahead

The most interesting observation is that these two architectures are **converging from opposite directions.** Claude Code keeps adding code-level controls — sandboxing, managed settings, deterministic hooks via external scripts. OpenClaw keeps adding declarative configuration — YAML skills, Markdown knowledge bases, convention-over-configuration patterns.

The ultimate answer is probably a hybrid: declarative where the model can be trusted (creative tasks, knowledge synthesis, code generation), imperative where it cannot (security boundaries, multi-tenancy isolation, financial transactions). The frameworks that figure out where to draw that line will define the next generation of AI infrastructure.

---

*This article is based on the Claude Code v2.1.88 source leaked on March 31, 2026 (1,884 TypeScript files, 512,664 lines of code) and OpenClaw's latest main branch (3,044 non-test TypeScript files, ~530,000 lines of code).*

*Disclaimer: This article is for technical analysis and academic discussion only. Analysis of the leaked Claude Code source is based on publicly available information.*

---

**Reference pages for both projects**: [Claude Code](/tools/claude-code/) and
[OpenClaw](/tools/openclaw/) — positioning, model support and how to get started.
Comparable source size does not mean comparable use case; if you are actually choosing
between them, these two pages tell you more than the line counts do.

---

## Frequently asked

### How big is the leaked Claude Code source code compared to OpenClaw?

The Claude Code v2.1.88 leak contains 1,884 TypeScript/TSX files totaling about 512,000 lines (no tests), while OpenClaw's latest main branch has 3,044 non-test TypeScript files at roughly 530,000 lines. Claude Code ships 42 built-in tool directories and 86 slash commands; OpenClaw uses plugin-based dynamic registration and supports 30+ LLM providers.

### What is the main architectural difference between Claude Code and OpenClaw?

Claude Code bets on declarative simplicity: a single-threaded agent loop, agents defined as Markdown files with YAML headers, and intelligence driven by prompt orchestration — trusting the model's comprehension. OpenClaw bets on imperative engineering: explicit TypeScript configuration, sub-agent depth control enforced in code, and an Agent Control Plane. Interestingly, both architectures are converging from opposite directions.

### What unreleased features were found in the leaked Claude Code source?

The source contains 89 distinct feature flags controlling built-but-unshipped capabilities, including PROACTIVE/KAIROS proactive mode, COORDINATOR_MODE (one Claude orchestrating multiple Claudes), VOICE_MODE, a Playwright-based WEB_BROWSER_TOOL, KAIROS_DREAM autonomous background execution, GitHub webhook triggers, and a Buddy companion sprite. The code is already written and merely excluded at compile time.


---

## References

- [Claude Code repository](https://github.com/anthropics/claude-code) — GitHub
- [OpenClaw repository](https://github.com/openclaw/openclaw) — GitHub
- [Claude Code documentation](https://code.claude.com/docs) — Anthropic
- [OpenClaw documentation](https://docs.openclaw.ai/) — OpenClaw
