Overview Architecture Tools Features Security Statistics
Source Code Analysis

Claude Code
Deep Dive Explorer

A comprehensive bilingual analysis of Anthropic's AI-powered CLI tool. Explore 1,884 TypeScript files, 45+ tools, multi-agent orchestration, and sophisticated architecture.

0 Source Files
0 Agent Tools
0 MB Source Code
0 Buddy Species

What is Claude Code?

Claude Code is Anthropic's official AI-powered CLI tool - internally codenamed "Tengu". It's a production-grade AI agent framework containing 1,884 TypeScript files across 55+ directories.

Runtime & Build

Built on Bun runtime with Node.js v18+ fallback. Uses TypeScript/TSX with Bun's native bundler and dead-code elimination via feature() flags.

Bun TypeScript React

Custom Terminal UI (Ink)

Custom React-based terminal renderer with 96 files. Features Yoga layout engine, ANSI colors, keyboard/mouse handling, and responsive terminal layouts.

React Yoga ANSI

Anthropic SDK Integration

Deep integration with @anthropic-ai/sdk for Claude API. Supports streaming, extended thinking, web search betas, prompt caching, and multi-model fallback.

Claude API Streaming MCP

State Management

React Context-based state with custom stores. Includes session persistence, conversation recovery, memory consolidation, and settings change detection.

React Context Zod Keychain

MCP Protocol

Full Model Context Protocol support with 25+ files. Server registry, OAuth integration, resource management, and enterprise XAA authentication.

MCP OAuth SSE

IDE Bridge Integration

Two-way VS Code bridge with 31 files (up to 2,999 lines). Supports file operations, terminal control, permission prompts, and real-time status updates.

VS Code LSP Bridge

System Architecture

The core architecture follows a layered design with CLI entry, LLM orchestration, tool execution, and API communication.

User Input (CLI/IDE)
main.tsx
4,683 lines - CLI Entry, Auth, Config
QueryEngine.ts
Core LLM Orchestration - Messages, Tokens, Tools
45+ Tools
Bash, File, Web, MCP, Agent, Task...
Services
API, MCP, OAuth, Analytics
Anthropic Claude API
Streaming, Thinking, Web Search
AppState (Store)
Ink Renderer
Analytics

Project File Structure

📁 src/ 33MB - Full source code
📄 main.tsx 4,683 lines - CLI Entry Point
📄 QueryEngine.ts ~46KB - Core LLM Engine
📄 Tool.ts 792 lines - Base Tool Interface
📁 tools/ 184 files - 45+ Agent Tools
📁 services/ API, MCP, OAuth, Analytics, Dreams
📁 utils/ 564 files - Utilities & Helpers
📁 ink/ 96 files - Terminal React Renderer
📁 commands/ 189 files - CLI Commands
📁 bridge/ 31 files - IDE Integration
📁 buddy/ 6 files - Tamagotchi Companion
📁 coordinator/ Multi-Agent Orchestration
📁 assistant/ KAIROS - Proactive Assistant
📁 vim/ Vim Mode Keybindings

45+ Integrated Tools

Claude Code includes a comprehensive toolkit spanning file operations, code execution, web search, agent management, and more.

FileReadTool

Reads files with PDF, notebook, and image support. Line limiting and compression.

FileEditTool

Multi-operation file editing: insert, delete, replace with safe diffing.

FileWriteTool

Atomic file creation with permission checking and validation.

GlobTool

Pattern-based file discovery across the codebase.

GrepTool

Content search with regex and multiline support.

BashTool

Shell command execution with streaming, environment control, and 98KB security validation.

PowerShellTool

Windows PowerShell execution with 16 supporting files.

NotebookEditTool

Jupyter notebook cell operations - create, edit, and run cells.

AgentTool

Spawns sub-agents with independent sessions for parallel work.

TeamCreateTool

Creates agent teams for coordinated multi-agent work.

SendMessageTool

Inter-agent messaging for team communication.

SkillTool

Executes MCP skills and custom prompts/plugins.

WebSearchTool

Web search via Claude's native web_search tool.

WebFetchTool

HTTP fetch with HTML to Markdown conversion.

ToolSearchTool

Discovers and searches available tools dynamically.

TaskCreateTool

Creates structured task entries with metadata.

TaskUpdateTool

Updates task status: pending, in_progress, completed.

CronCreateTool

Creates cron schedules for recurring tasks.

RemoteTriggerTool

Schedules remote async agent execution.

EnterPlanModeTool

Enables extended planning sessions with 30-minute budget.

EnterWorktreeTool

Creates isolated git worktree for safe experimentation.

AskUserQuestionTool

Prompts the user for input when clarification is needed.

Hidden & Special Features

🍞

Buddy System (Tamagotchi Companion)

src/buddy/ - 6 files

A full Tamagotchi-style companion system with 18 species, 5 rarity tiers, deterministic generation using Mulberry32 PRNG seeded from userId, customizable eyes/hats, and AI-generated personality (Soul).

Species: Duck, Goose, Blob, Cat, Dragon, Octopus, Owl, Penguin, Turtle, Snail, Ghost, Axolotl, Capybara, Cactus, Robot, Rabbit, Mushroom, Chonk
Rarity: Common (60%) | Uncommon (25%) | Rare (10%) | Epic (4%) | Legendary (1%)
Stats: DEBUGGING, PATIENCE, CHAOS, WISDOM, SNARK
🌙

Dream System (Memory Consolidation)

src/services/autoDream/

Background memory consolidation via a subagent. The system Orients (reads MEMORY.md), Gathers (finds signals from daily logs), Consolidates (updates durable memory), and Prunes (keeps context efficient). Runs as a 30-minute background Opus session.

KAIROS (Proactive Assistant)

src/assistant/

An "always-on" proactive AI assistant that watches logs for signals and acts without waiting for explicit user input. Runs as a background agent with push notification support and GitHub webhook subscriptions.

👥

Coordinator Mode (Multi-Agent Swarm)

src/coordinator/coordinatorMode.ts (19KB)

Multi-agent orchestration enabling team-based task execution. Spawns worker agents for parallel work with internal-only tools: TeamCreate, TeamDelete, SendMessage, SyntheticOutput.

🚀

ULTRAPLAN (Extended Planning)

src/utils/ultraplan/

Remote Opus 4.6 session for complex tasks. Offloads to cloud for up to 30 minutes of deep planning, handling complex multi-step problems, then teleports context back to the main session.

🕵

Undercover Mode (Safety System)

src/utils/undercover.ts

Safety system for Anthropic employees contributing to public repos. Auto-strips model codenames, internal project names, attribution lines, and blocks internal info from commits.

Vim Mode

src/vim/

Native Vim keybindings with motions, operators, text objects, and full mode transitions (insert, normal, visual).

Security & Safety

🔒

Bash Security Validation

98KB validation module that detects dangerous commands: rm, dd, mkfs, shutdown. Includes variable substitution checks and destructive pattern detection.

98KB
📂

Path Validation

43KB path validation system ensuring file operations stay within authorized directories and preventing path traversal attacks.

43KB
👁

Read-Only Validation

68KB read-only validation module that classifies tools and operations as safe for read-only execution.

68KB
🛡

Permission Framework

Multi-level permission system: Default (prompt user), Auto (AI auto-approves safe ops), Bypass (user confirms all). 17+ permission files.

17+ files

By The Numbers

0
TypeScript Files
0
Agent Tools
0
Utility Files
0
CLI Commands
0
Ink UI Files
0
Directories
0
MB Source Size
0
Buddy Species

Feature Flags

Flag Purpose Status
KAIROS Proactive assistant mode Internal
COORDINATOR_MODE Multi-agent team orchestration Internal
VOICE_MODE Voice input/output (STT) Beta
BRIDGE_MODE IDE bridge integration Active
TRANSCRIPT_CLASSIFIER Auto-mode permission classification Internal
DIRECT_CONNECT Direct API connection mode Beta
SSH_REMOTE SSH remote execution Beta