Version analyzed: March 31, 2026 leak
Total files: ~1,900 TypeScript files
Lines of code: 512,000+
Overview
The Claude Code source is organized into a clear, modular structure with ~35 major directories. Each directory has a specific responsibility in the system.
Root Level Files
The entry points and core orchestration files:
File Purpose main.tsxCLI entry point, Commander.js setup, initialization QueryEngine.tsCore agentic loop orchestrator query.tsAPI communication handler Tool.tsTool type definitions and interfaces tools.tsTool registry and initialization commands.tsCommand registry context.tsUser/system context gathering cost-tracker.tsToken usage and cost tracking history.tsCommand history management replLauncher.tsxREPL screen launcher setup.tsInitial setup and onboarding
Major Directories
/assistant - Assistant Mode (Kairos)
Feature-gated assistant mode functionality.
assistant/
└── sessionHistory.ts # Session history for assistant mode
/bootstrap - Global State
Early initialization and global state management.
bootstrap/
└── state.ts # Global state (session ID, CWD, model config, telemetry)
/bridge - IDE Integration
Connects Claude Code to VS Code and JetBrains IDEs.
bridge/
├── bridgeMain.ts # Main bridge orchestrator
├── bridgeApi.ts # API client for bridge service
├── bridgeMessaging.ts # Message passing
├── replBridge.ts # REPL bridge implementation
├── sessionRunner.ts # Session management
├── trustedDevice.ts # Device authentication
└── types.ts # Bridge type definitions
Key Features:
Bidirectional communication with IDEs
Remote control capabilities
Session synchronization
OAuth authentication
/buddy - Companion Sprite
Easter egg companion sprite feature.
buddy/
├── companion.ts # Companion logic
├── CompanionSprite.tsx # React component
├── sprites.ts # Sprite definitions
└── types.ts # Companion types
/cli - CLI Handlers
Non-interactive CLI mode and structured I/O.
cli/
├── handlers/ # Command handlers for CLI mode
│ ├── agents.ts
│ ├── auth.ts
│ ├── autoMode.ts
│ └── mcp.tsx
├── transports/ # Transport layers
│ ├── SSETransport.ts
│ ├── WebSocketTransport.ts
│ └── HybridTransport.ts
└── structuredIO.ts # JSON/NDJSON output
/commands - Slash Commands
50+ slash command implementations.
commands/
├── add-dir/ # /add-dir - Add working directory
├── commit.ts # /commit - Create git commit
├── compact/ # /compact - Compress context
├── config/ # /config - Settings management
├── diff/ # /diff - View changes
├── doctor/ # /doctor - Diagnostics
├── login/ # /login - Authentication
├── mcp/ # /mcp - MCP server management
├── memory/ # /memory - Memory management
├── resume/ # /resume - Resume session
├── review.ts # /review - Code review
├── share/ # /share - Share session
├── skills/ # /skills - Skill management
├── tasks/ # /tasks - Task management
├── vim/ # /vim - Vim mode toggle
└── ... (40+ more)
/components - React UI Components
140+ Ink (React for CLI) components.
components/
├── agents/ # Agent-related UI
├── mcp/ # MCP server UI
├── messages/ # Message rendering
├── permissions/ # Permission dialogs
├── PromptInput/ # Input handling
├── tasks/ # Task UI
├── teams/ # Team/swarm UI
├── App.tsx # Main app component
├── Message.tsx # Message renderer
├── Messages.tsx # Message list
├── REPL.tsx # REPL screen (moved to screens/)
└── ... (130+ more)
/constants - Constants & Prompts
System prompts, limits, and configuration constants.
constants/
├── prompts.ts # System prompt builder (CRITICAL)
├── system.ts # System constants
├── systemPromptSections.ts # Prompt sections
├── apiLimits.ts # API limits
├── tools.ts # Tool constants
├── files.ts # File type constants
├── oauth.ts # OAuth configuration
└── xml.ts # XML tag constants
prompts.ts is one of the most important files - it contains the complete system prompt assembly logic.
/context - React Contexts
React context providers for global state.
context/
├── modalContext.tsx # Modal management
├── notifications.tsx # Notification system
├── stats.tsx # Statistics tracking
└── voice.tsx # Voice mode context
/coordinator - Coordinator Mode
Multi-agent coordination (feature-gated).
coordinator/
└── coordinatorMode.ts # Coordinator implementation
/entrypoints - Entry Points
Different entry points for different modes.
entrypoints/
├── cli.tsx # CLI mode entry
├── init.ts # Initialization logic
├── mcp.ts # MCP server mode
├── sdk/ # SDK entry points
└── agentSdkTypes.ts # SDK type definitions
/hooks - React Hooks
80+ custom React hooks.
hooks/
├── useCanUseTool.tsx # Permission checking
├── useIDEIntegration.tsx # IDE connection
├── useMergedTools.ts # Tool merging
├── useReplBridge.tsx # Bridge management
├── useSettings.ts # Settings access
├── useVimInput.ts # Vim mode input
└── ... (70+ more)
/ink - Terminal Rendering
Custom Ink renderer with optimizations.
ink/
├── components/ # Ink components
├── events/ # Event handling
├── hooks/ # Ink hooks
├── layout/ # Layout engine
├── termio/ # Terminal I/O
├── reconciler.ts # React reconciler
├── renderer.ts # Rendering engine
└── terminal.ts # Terminal abstraction
/keybindings - Keybinding System
Configurable keybindings.
keybindings/
├── defaultBindings.ts # Default keybindings
├── loadUserBindings.ts # User customization
├── parser.ts # Keybinding parser
├── resolver.ts # Keybinding resolution
└── schema.ts # Validation schema
/memdir - Memory System
Persistent memory (MEMORY.md) management.
memdir/
├── memdir.ts # Core memory logic
├── paths.ts # Memory file paths
├── findRelevantMemories.ts # Memory search
├── memoryAge.ts # Freshness tracking
├── memoryTypes.ts # Memory type definitions
└── teamMemPaths.ts # Team memory (feature-gated)
/migrations - Config Migrations
Version migrations for config changes.
migrations/
├── migrateSonnet45ToSonnet46.ts
├── migrateOpusToOpus1m.ts
└── ... (10+ migrations)
/plugins - Plugin System
Plugin architecture and built-in plugins.
plugins/
├── bundled/ # Bundled plugins
└── builtinPlugins.ts # Built-in plugin registry
/query - Query Helpers
Query engine helper modules.
query/
├── config.ts # Query configuration
├── deps.ts # Dependency injection
├── stopHooks.ts # Stop hooks
└── tokenBudget.ts # Token budget tracking
/schemas - Zod Schemas
Validation schemas.
schemas/
└── hooks.ts # Hook schemas
/screens - Full-Screen UIs
Full-screen React components.
screens/
├── Doctor.tsx # Diagnostics screen
├── REPL.tsx # Main REPL screen
└── ResumeConversation.tsx # Resume picker
/server - Server Mode
Direct connect server for remote sessions.
server/
├── createDirectConnectSession.ts
├── directConnectManager.ts
└── types.ts
/services - External Services
Integration with external services and APIs.
services/
├── analytics/ # GrowthBook, telemetry
├── api/ # Anthropic API client
│ ├── claude.ts # Main API wrapper
│ ├── bootstrap.ts # Bootstrap data
│ └── filesApi.ts # File upload/download
├── compact/ # Context compression
├── lsp/ # Language Server Protocol
│ └── manager.ts # LSP server manager
├── mcp/ # Model Context Protocol
│ ├── client.ts # MCP client
│ ├── config.ts # MCP configuration
│ └── types.ts # MCP types
├── oauth/ # OAuth authentication
├── plugins/ # Plugin management
├── policyLimits/ # Organization policies
├── remoteManagedSettings/ # Remote settings
└── tools/ # Tool orchestration
└── toolOrchestration.ts
/skills - Skill System
Markdown-based workflow system.
skills/
├── bundled/ # Bundled skills
├── bundledSkills.ts # Bundled skill definitions
├── loadSkillsDir.ts # Skill loader
└── mcpSkillBuilders.ts # MCP skill builders
/state - State Management
React state management.
state/
├── AppState.tsx # Main app state component
├── AppStateStore.ts # State type definitions
├── store.ts # Store implementation
└── selectors.ts # State selectors
/tasks - Task System
Background task management.
tasks/
├── LocalAgentTask/ # Local agent tasks
├── RemoteAgentTask/ # Remote agent tasks
├── LocalShellTask/ # Shell tasks
├── DreamTask/ # Dream tasks (feature-gated)
└── types.ts # Task type definitions
40+ tool implementations.
tools/
├── AgentTool/ # Sub-agent spawning
├── BashTool/ # Shell execution
├── FileReadTool/ # File reading
├── FileWriteTool/ # File creation
├── FileEditTool/ # File editing
├── GlobTool/ # File search
├── GrepTool/ # Content search
├── WebFetchTool/ # URL fetching
├── WebSearchTool/ # Web search
├── MCPTool/ # MCP tool invocation
├── LSPTool/ # LSP features
├── REPLTool/ # REPL mode
├── TaskCreateTool/ # Task creation
├── TeamCreateTool/ # Team creation
├── EnterPlanModeTool/ # Plan mode
├── EnterWorktreeTool/ # Worktree isolation
└── ... (25+ more)
Each tool directory contains:
{Tool}.ts - Main implementation
prompt.ts - Tool description and schema
constants.ts - Tool constants
Additional helper files
/types - TypeScript Types
Shared type definitions.
types/
├── command.ts # Command types
├── hooks.ts # Hook types
├── ids.ts # ID types (SessionId, AgentId)
├── logs.ts # Log entry types
├── message.ts # Message types (CRITICAL)
├── permissions.ts # Permission types
├── plugin.ts # Plugin types
└── generated/ # Generated types
/utils - Utility Functions
300+ utility modules organized into subdirectories.
utils/
├── permissions/ # Permission system
│ ├── permissions.ts
│ ├── PermissionMode.ts
│ └── permissionSetup.ts
├── settings/ # Settings management
│ ├── settings.ts
│ ├── types.ts
│ └── validation.ts
├── model/ # Model utilities
│ ├── model.ts
│ ├── providers.ts
│ └── modelStrings.ts
├── git/ # Git operations
├── github/ # GitHub integration
├── hooks/ # Hook system
├── mcp/ # MCP utilities
├── messages/ # Message utilities
├── plugins/ # Plugin utilities
├── processUserInput/ # Input processing
├── secureStorage/ # Keychain/credential storage
├── shell/ # Shell utilities
├── skills/ # Skill utilities
├── swarm/ # Team/swarm utilities
├── telemetry/ # Telemetry
└── ... (200+ utility files)
Key utility files:
api.ts - API helpers
auth.ts - Authentication
config.ts - Configuration management
sessionStorage.ts - Session persistence
queryContext.ts - Context assembly
thinking.ts - Thinking mode
tokens.ts - Token counting
/vim - Vim Mode
Vim keybinding implementation.
vim/
├── motions.ts # Vim motions
├── operators.ts # Vim operators
├── textObjects.ts # Text objects
├── transitions.ts # State transitions
└── types.ts # Vim types
/voice - Voice Mode
Voice input feature (feature-gated).
voice/
└── voiceModeEnabled.ts # Voice mode check
File Naming Conventions
The codebase follows consistent naming patterns:
Pattern Purpose Example {Feature}.tsMain implementation BashTool.ts{feature}.tsxReact component Message.tsx{feature}Types.tsType definitions agentSdkTypes.ts{feature}Helpers.tsHelper functions queryHelpers.tsuse{Feature}.tsReact hook useCanUseTool.tsx{feature}Manager.tsManager class directConnectManager.ts{feature}Config.tsConfiguration bridgeConfig.tsconstants.tsConstants tools/BashTool/constants.tsprompt.tsTool prompts tools/BashTool/prompt.tstypes.tsType definitions bridge/types.tsindex.tsBarrel export commands/login/index.ts
Import Patterns
The codebase uses several import patterns:
Feature Gating
import { feature } from 'bun:bundle'
const module = feature ( 'FEATURE_NAME' )
? require ( './feature.js' )
: null
Dead code elimination removes unused features at build time.
Lazy Loading
const heavyModule = () =>
require ( './heavy.js' ) as typeof import ( './heavy.js' )
Defers loading until actually needed.
Circular Dependency Breaking
// Lazy require to break circular dependency
const getModule = () =>
require ( './module.js' ). exportedFunction
Key Files to Understand
If you want to understand Claude Code deeply, start with these files:
main.tsx - Entry point, see how everything initializes
QueryEngine.ts - Core agentic loop
query.ts - API communication
constants/prompts.ts - System prompt assembly
Tool.ts - Tool interface definition
tools.ts - Tool registry
commands.ts - Command registry
utils/sessionStorage.ts - Persistence
state/AppStateStore.ts - State management
services/api/claude.ts - Anthropic API wrapper
Build Artifacts
The source compiles to:
dist/
├── main.js # Bundled entry point
├── main.js.map # Source map (the leak!)
└── ... (other artifacts)
The source map pointed to a zip archive containing the full source.
Configuration Files
User configuration lives in:
~/.kiro/ # User-level config
├── settings/
│ ├── settings.json # User settings
│ └── mcp.json # MCP servers
├── skills/ # User skills
├── plugins/ # User plugins
└── sessions/ # Session transcripts
.kiro/ # Project-level config
├── settings/
│ ├── settings.json # Project settings
│ └── mcp.json # Project MCP servers
├── skills/ # Project skills
└── plugins/ # Project plugins
Architecture Overview High-level system architecture
Control Flow Flow from user input to output
Tools Overview Understanding the tool system
Commands Overview Understanding slash commands