Skip to content

YmlyZA/claude-code-reverse-engineering-analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Claude Code CLI - Reverse Engineering Research

Research Project: Static analysis and reverse engineering of the Claude Code CLI (v2.1.5)

This project contains research findings and analysis tools for understanding the architecture of Anthropic's closed-source Claude Code CLI through static analysis of the compiled bundle.


Project Purpose

The Claude Code CLI is distributed as a pre-built, minified JavaScript bundle (~10.6 MB) with no source code included. This project documents findings from reverse engineering the CLI to understand its:

  • Internal architecture and design patterns
  • Extension mechanisms (MCP, plugins, skills, agents)
  • SDK tools API surface
  • Security and permission model
  • Native module integrations

★ Insight ─────────────────────────────────────

  • Closed-source distribution: Anthropic follows a distribution-only model for the CLI. The bundle explicitly states "Want to see the unminified source? We're hiring!"
  • Hybrid runtime architecture: JavaScript (esbuild bundle) + WebAssembly (tree-sitter, resvg) + Native binaries (ripgrep) - each chosen for specific performance characteristics
  • Protocol-based extensibility: MCP (Model Context Protocol) is the primary extension mechanism, allowing external tools without modifying the proprietary core ─────────────────────────────────────────────────

Quick Links

Document Description
REVERSE_ENGINEERING_ANALYSIS.md Complete technical findings
CLAUDE.md Project overview for Claude Code instances
Plan File ~/.claude/plans/silly-churning-moore.md - Detailed analysis plan with progress

Project Structure

claude-code/
├── analysis/                          # Analysis scripts & outputs
│   ├── extract-strings.js             # String literal extractor
│   ├── find-patterns.js               # Pattern search tool
│   ├── analyze-functions.js           # Function analysis & call graph
│   ├── extract-config.js              # Configuration extraction
│   ├── extract-tools.js               # Tool registry extraction
│   └── *.json                         # Generated analysis outputs (gitignored)
├── docs/                              # Research documentation
│   └── REVERSE_ENGINEERING_ANALYSIS.md # Complete technical findings
├── .claude/                           # Claude Code configuration
│   └── settings.local.json            # Local settings
├── node_modules/@anthropic-ai/claude-code/
│   ├── cli.js                         # Main bundle (11MB) - TARGET OF ANALYSIS
│   ├── sdk-tools.d.ts                 # TypeScript definitions
│   ├── tree-sitter*.wasm              # Code parsing WASM
│   ├── resvg.wasm                     # SVG rendering WASM
│   └── vendor/ripgrep/                # Platform-specific binaries
├── CLAUDE.md                          # Project guidance for Claude Code
├── README.md                          # This file
└── package.json                       # Wrapper package metadata

Analysis Tools

This project includes custom scripts for extracting information from the minified bundle:

# Run all analysis scripts
cd analysis
node extract-strings.js      # Extract 2,903+ strings
node find-patterns.js        # Search for patterns
node analyze-functions.js    # Build call graph
node extract-config.js       # Extract configuration
node extract-tools.js        # Extract tool registry

# Outputs are saved as JSON files (gitignored)

Extraction Results Summary

Category Count Description
Strings 2,903 URLs, errors, constants, commands
Environment Variables 395 CLAUDE_CODE_, ANTHROPIC_, etc.
Config Files 42 .json, .yml, .rc files referenced
CLI Flags 609 Command-line options
Tools 553 SDK tools, MCP tools, built-ins

Key Findings

Architecture Overview

┌─────────────────────────────────────────────────────────────┐
│                    Claude Code CLI (v2.1.5)                   │
│                    esbuild bundle (11MB)                      │
└─────────────────────────────────────────────────────────────┘
                              │
         ┌────────────────────┼────────────────────┐
         │                    │                    │
         ▼                    ▼                    ▼
┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐
│   CLI Commands  │  │   MCP System    │  │   Agent System  │
│  (Commander.js) │  │  (std/HTTP/SSE) │  │   (subagents)   │
└─────────────────┘  └─────────────────┘  └─────────────────┘
         │                    │                    │
         └────────────────────┼────────────────────┘
                              ▼
                    ┌─────────────────────┐
                    │   Tool Execution    │
                    │    (17 SDK tools)   │
                    └─────────────────────┘
                              │
         ┌────────────────────┼────────────────────┐
         │                    │                    │
         ▼                    ▼                    ▼
┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐
│  File System    │  │  Web/Network    │  │  User/System    │
│ (Read/Edit/Grep)│  │ (Search/Fetch)  │  │   (Bash/Ask)    │
└─────────────────┘  └─────────────────┘  └─────────────────┘

Extension Mechanisms

Mechanism Purpose Example
MCP Servers External tool integration .mcp.json configuration
Plugins Full-featured extensions .claude-plugin/ directory
Skills Permission-gated behaviors Skill(superpowers:using-superpowers)
Agents Specialized sub-agents file-search, learning, code
Hooks Lifecycle events PreToolUse, SessionStart

SDK Tools (17 Total)

File System: Read, Write, Edit, Glob, Grep, NotebookEdit Execution: Bash, TaskOutput, KillShell Agent: Agent (spawn subagents) MCP: McpInput, ListMcpResources, ReadMcpResource User/Web: AskUserQuestion, WebSearch, WebFetch Config: Config, TodoWrite, ExitPlanMode


Configuration Files

File Scope Purpose
~/.claude/settings.json User Global user settings
.claude/settings.json Project Project-specific settings
.claude/settings.local.json Project Local Local overrides (gitignored)
.mcp.json Project MCP server configuration
.claude-plugin/plugin.json Plugin Plugin manifest
CLAUDE.md Project Project documentation

Environment Variables

# Claude Code specific
CLAUDE_CODE_ENABLE_TELEMETRY=true|false
CLAUDE_CODE_DISABLE_BACKGROUND_TASKS=true|false
CLAUDE_CODE_OTEL_SHUTDOWN_TIMEOUT_MS=5000

# Anthropic API
ANTHROPIC_API_KEY=sk-ant-...
ANTHROPIC_BASE_URL=https://api.anthropic.com

# Development
DEBUG=*
DEV=true

Running the CLI

# Install dependencies
pnpm install

# Run Claude Code
npx claude

# Direct prompt mode
npx claude --prompt "your prompt here"

# Print mode
npx claude --print

# MCP CLI mode (for server interaction)
npx claude --mcp-cli

Research Documents

1. REVERSE_ENGINEERING_ANALYSIS.md

Complete technical analysis covering:

  • Bundle structure and metadata
  • Entry points and execution flow
  • MCP integration architecture
  • Agent system and spawning
  • SDK tools API surface
  • Native modules (WASM, ripgrep)
  • Plugin architecture
  • Configuration hierarchy
  • Security model

2. Plan File

~/.claude/plans/silly-churning-moore.md contains:

  • Detailed analysis phases
  • Progress tracking (Phase 1, 2, 4 completed)
  • Line number references for key findings
  • Next steps for further research

Key Discoveries

MCP Integration

  • 3 Transport Types: stdio, HTTP, SSE
  • Deferred Loading: Tools must be discovered via MCPSearch before use
  • Tool Naming: mcp__<server>__<tool>
  • 4 Configuration Scopes: local, project, user, dynamic

Plugin System

  • Directory: .claude-plugin/
  • Manifest: plugin.json or marketplace.json
  • 5 Component Types: commands, agents, skills, hooks, MCP servers
  • 6-Step Lifecycle: Discovery → Parse → Validate → Register → Initialize → Ready

Hook System (11 Events)

PreToolUse, PostToolUse, PostToolUseFailure
SessionStart, SessionEnd
UserPromptSubmit, PreCompact, Notification
SubagentStart, SubagentStop, PermissionRequest

Build Information

Property Value
Version 2.1.5
Build Date 2026-01-11T21:29:41Z
Bundler esbuild
Module System ESM
Node.js Required 18+

Bundle Header:

#!/usr/bin/env node
// (c) Anthropic PBC. All rights reserved.
// Version: 2.1.5
// Want to see the unminified source? We're hiring!
// https://job-boards.greenhouse.io/anthropic/jobs/4816199008

Resources


License

This research project is licensed under ISC. The underlying Claude Code CLI is subject to Anthropic's legal agreements. See https://code.claude.com/docs/en/legal-and-compliance for details.


Disclaimer

This is a reverse engineering research project. All findings are based on static analysis of the compiled bundle. The actual source code is proprietary and not included in the npm package.

Analysis completed: 2026-01-12 Package version: @anthropic-ai/claude-code@2.1.5

About

Claude Code CLI Reverse Engineering Analysis

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •