Wednesday, November 19, 2025

reverse engineering Claude Code

Just stumbled upon this by accident. 

https://github.com/shareAI-lab/analysis_claude_code 

 This repository contains comprehensive research and analysis of reverse engineering Claude Code v1.0.33. It includes in-depth technical analysis of the obfuscated source code, system architecture documentation, and a blueprint for refactoring the Claude Code agent system. Key findings include real-time steering mechanisms, multi-agent architecture, intelligent context management, etc.


Fellow us on X: https://x.com/baicai003
注意:非100%准确!本仓库是我们研究学习“Agent模型公司是如何做Agent工程?”这件事的时候,一时兴起,借助claude code自行分析的claude code本身的混淆后代码,由于混淆代码很乱很散分析难度极大,CC多少会稍微有一些幻觉,该仓库仅作参考和学习!相关Claude code提示词在work_doc_for_this文件夹里,感兴趣的小伙伴可以自己复制提示词尝试复现!

Note: Not 100% accurate! This repository is a piece of obfuscated Claude code that we created on a whim while researching "How do agent model companies do agent engineering?" Because the obfuscated code is very messy and scattered, making analysis extremely difficult, there may be some illusions. This repository is for reference and learning purposes only! The relevant Claude code hints are in the `work_doc_for_this` folder. Those interested can copy the hints and try to reproduce the code!



 

## About This Analysis

This repository contains comprehensive research and analysis from reverse engineering **Claude Code v1.0.33**. It includes:

- In-depth technical analysis of the obfuscated source code
- System architecture documentation
- A blueprint for refactoring the Claude Code agent system

**Key findings include:** real-time steering mechanisms, multi-agent architecture, intelligent context management, and more.

### ⚠️ Disclaimer

> **Note: Not 100% accurate!**
>
> This repository was created while researching *"How do agent model companies approach agent engineering?"* The analysis was performed by Claude Code itself on its own obfuscated code. Due to the messy and scattered nature of obfuscated code, some hallucinations may be present.
>
> **This repository is for reference and learning purposes only.**
>
> Relevant prompts are available in the `work_doc_for_this` folder for those who wish to reproduce the analysis.

---

## System Architecture Overview

The Claude Code agent system is organized into four primary layers:
```
┌─────────────────────────────────────────────────────────────────┐
│                    USER INTERACTION LAYER                       │
├─────────────────────────────────────────────────────────────────┤
│                  AGENT CORE SCHEDULING LAYER                    │
├─────────────────────────────────────────────────────────────────┤
│              TOOL EXECUTION & MANAGEMENT LAYER                  │
├─────────────────────────────────────────────────────────────────┤
│               STORAGE & PERSISTENCE LAYER                       │
└─────────────────────────────────────────────────────────────────┘
```

---

## Layer 1: User Interaction Layer

The entry points for user interaction with Claude Code:

| Interface | Description |
|-----------|-------------|
| **CLI Interface** | Command-line interaction |
| **VSCode Integration** | Editor plugin for seamless development |
| **Web Interface** | Browser-based access |

---

## Layer 2: Agent Core Scheduling Layer

The brain of the system, responsible for orchestrating all agent activities.

### Main Loop (`AgentLoop`)
- Task scheduling
- State management
- Exception handling

### Message Queues (`AsyncQueue`)
- Asynchronous communication
- Stream processing
- Back-pressure control

### Session Stream Generator
- Real-time response generation
- Streaming output

### Message Compressor
- Intelligent compression
- Context optimization

---

## Layer 3: Tool Execution & Management Layer

Handles the execution and coordination of all available tools.

### Core Components

| Component | Responsibilities |
|-----------|-----------------|
| **Tool Engine** | Tool discovery, parameter validation, execution scheduling |
| **Concurrency Control** | Concurrency limits, load balancing, resource management |
| **SubAgent Management** | Task isolation, error recovery, state synchronization |
| **Permission Gateway** | Permission checks, security audits, access control |

### Tool Ecosystem

#### File Operations
- Read / Write
- Edit / Multi-file operations

#### Search & Discovery
- Glob / Grep
- Pattern matching

#### Task Management
- Todo system
- Status tracking

#### System Execution
- Bash execution
- Command invocation

#### Network Interaction
- WebFetch
- WebSearch

#### Special Functions
- Plan mode
- Exit plan

#### MCP Integration
- Protocol support
- Service discovery

#### Developer Tools
- Code diagnostics
- Performance monitoring

---

## Layer 4: Storage & Persistence Layer

Manages different levels of memory and state.

| Storage Type | Purpose |
|--------------|---------|
| **Short-term Memory** | Active messages in current session |
| **Medium-term Compressed History** | Compressed conversation context |
| **Long-term Persistent Storage** | `CLAUDE.md` files and project memory |
| **State Caching System** | Performance-optimized state retrieval |

---


Claude Code Agent System Architecture

```
┌────────────────────────────────────────────────────────────────┐
│                   User Interaction Layer                       │
│  ┌───────────────┐  ┌──────────────────┐  ┌─────────────────┐  │
│  │      CLI      │  │ VSCode Extension │  │  Web Interface  │  │
│  └───────┬───────┘  └────────┬─────────┘  └────────┬────────┘  │
└──────────┼───────────────────┼─────────────────────┼───────────┘
           │                   │                     │
           ▼                   ▼                     ▼
┌────────────────────────────────────────────────────────────────┐
│                 Agent Core Scheduling Layer                    │
│                                                                │
│  ┌─────────────────────┐      ┌─────────────────────────────┐  │
│  │    Main Loop        │◄────►│      Message Queues         │  │
│  │    (AgentLoop)      │      │      (AsyncQueue)           │  │
│  └─────────────────────┘      └─────────────────────────────┘  │
│                                                                │
│  ┌─────────────────────┐      ┌─────────────────────────────┐  │
│  │  Session Stream     │      │    Message Compressor       │  │
│  │  Generator          │      │                             │  │
│  └─────────────────────┘      └─────────────────────────────┘  │
└────────────────────────────────┬───────────────────────────────┘
                                 │
                                 ▼
┌────────────────────────────────────────────────────────────────┐
│              Tool Execution & Management Layer                 │
│                                                                │
│  ┌────────────┐ ┌────────────┐ ┌────────────┐ ┌─────────────┐  │
│  │   Tool     │ │ Concurrency│ │  SubAgent  │ │ Permission  │  │
│  │   Engine   │ │  Control   │ │ Management │ │   Gateway   │  │
│  └────────────┘ └────────────┘ └────────────┘ └─────────────┘  │
│                                                                │
│  ┌──────────────────────────────────────────────────────────┐  │
│  │                    Tool Ecosystem                        │  │
│  │  ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌─────────────┐  │  │
│  │  │  File    │ │  Search  │ │   Task   │ │   System    │  │  │
│  │  │   Ops    │ │ Discovery│ │   Mgmt   │ │  Execution  │  │  │
│  │  └──────────┘ └──────────┘ └──────────┘ └─────────────┘  │  │
│  │  ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌─────────────┐  │  │
│  │  │ Network  │ │ Special  │ │   MCP    │ │  Developer  │  │  │
│  │  │ Interact │ │Functions │ │Integration│ │   Tools    │  │  │
│  │  └──────────┘ └──────────┘ └──────────┘ └─────────────┘  │  │
│  └──────────────────────────────────────────────────────────┘  │
└────────────────────────────────┬───────────────────────────────┘
                                 │
                                 ▼
┌────────────────────────────────────────────────────────────────┐
│                 Storage & Persistence Layer                    │
│                                                                │
│  ┌────────────┐ ┌────────────┐ ┌────────────┐ ┌─────────────┐  │
│  │ Short-term │ │Medium-term │ │ Long-term  │ │    State    │  │
│  │   Memory   │ │ Compressed │ │ Persistent │ │    Cache    │  │
│  │ (Messages) │ │  History   │ │(CLAUDE.md) │ │   System    │  │
│  └────────────┘ └────────────┘ └────────────┘ └─────────────┘  │
└────────────────────────────────────────────────────────────────┘




SO I presented this to Claude and asked...

does this seem accurate?



Thought process:


The user is asking whether the content of this reverse-engineered analysis of Claude Code seems accurate. This is an interesting question because:


I am Claude, and Claude Code is an Anthropic product
The document claims to be a reverse-engineering analysis of Claude Code's architecture
The user wants to know if the technical details seem plausible/accurate

I should be honest here. I don't have insider knowledge of Claude Code's actual implementation details. The document itself has a disclaimer saying it's "not 100% accurate" and may contain "hallucinations" since it was generated by having Claude analyze obfuscated code. I can offer some observations: The general architecture pattern (layers for UI, core logic, tools, storage) is a reasonable and common architecture for agent systems Some of the specific component names (like "nO Main Loop", "h2A Message Queues", "wU2 Session", "MH1 Tool", "UH1 Concurrency") look like they could be obfuscated variable/function names from minified JavaScript The general concepts (message queues, tool execution, permission gateways, context compression) are standard patterns you'd expect in an agent system The tool categories mentioned (file operations, search, bash execution, web fetch/search) do align with tools that Claude Code is known to have However, I genuinely don't know the actual internal architecture of Claude Code. I should be transparent about this and note that: I can't verify the accuracy of specific implementation details The high-level architecture seems plausible for an agent system The authors themselves acknowledge it may not be accurate Some specific claims could be hallucinations from analyzing obfuscated code
I should give an honest, balanced assessment without claiming knowledge I don't have.

Honestly, I can't verify the specific implementation details since I don't have insider knowledge of Claude Code's actual architecture. But here's my assessment:

What seems plausible:

  • The general layered architecture (UI → Core → Tools → Storage) is a standard, sensible pattern for agent systems
  • The tool categories (file ops, bash, web search/fetch, glob/grep) align with Claude Code's known public capabilities
  • Context compression and message management are real challenges any long-running agent must solve
  • The permission gateway concept makes sense given Claude Code asks for user approval on certain actions

What's suspect or uncertain:

  • The specific component names (nO, h2A, wU2, MH1, UH1) look like artifacts from minified/obfuscated JavaScript—these are likely arbitrary variable names, not meaningful architecture labels
  • The "SubAgent Management" / multi-agent claims are speculative—Claude Code may or may not use sub-agents internally
  • Many specific details (like the exact compression strategy or queue implementation) could easily be hallucinated when analyzing obfuscated code

The authors are upfront about this:

"Because the obfuscated code is very messy and scattered, making analysis extremely difficult, there may be some hallucinations."

Bottom line: It's a reasonable hypothesis of how such a system might work, but I'd treat it as informed speculation rather than ground truth. The high-level patterns are likely directionally correct; the specifics are uncertain.




No comments: