Skip to main content

Architecture & Module Map

Layered Architecture

Claude Code uses a clear layered architecture, forming a complete data pipeline from user input to LLM interaction:

src/ Top-Level Directory Classification

Entry Layer

Directory/FileFilesResponsibility
entrypoints/8Process entry: cli.tsx (CLI bootstrap), init.ts (one-time init), mcp.ts (MCP server mode), SDK types
main.tsx1Commander CLI setup, GrowthBook init, tool registration, REPL launch
bootstrap/1state.ts: global bootstrap state (telemetry, channels, settings cache)

Core Layer

FileResponsibility
query.tsCore agent loop: query() / queryLoop() state machine driving LLM calls -> tool execution -> result injection
QueryEngine.tsSDK / headless mode wrapper managing per-session message lists, abort, file cache
Tool.tsTool interface definitions: Tool<Input, Output>, ToolUseContext, ToolPermissionContext, buildTool()
tools.tsTool registry: getAllBaseTools() returns all built-in tools, getTools() filters by permissions
commands.tsCommand registry: merges bundled/plugin/skill/built-in commands, sorted by priority

Service Layer (services/, 130 files)

SubdirectoryResponsibility
api/Anthropic API client construction, streaming calls, retries, file API
mcp/MCP client connection management, tool discovery, config merging
compact/Context compaction (full/micro/auto)
analytics/GrowthBook feature flags, analytics events
oauth/OAuth 2.0 authentication flow
tools/Tool orchestration (toolOrchestration.ts), execution (toolExecution.ts), streaming executor
lsp/Language Server Protocol integration
policyLimits/Organization policy limits
remoteManagedSettings/Remote managed settings (enterprise)
SessionMemory/Session memory extraction
teamMemorySync/Team memory synchronization

UI Layer

DirectoryFilesResponsibility
ink/96Custom Ink rendering engine: React reconciler + Yoga layout + terminal cell buffer
screens/3Full-screen UIs: REPL.tsx (main interaction), Doctor.tsx (diagnostics), ResumeConversation.tsx
components/389Ink UI components: message display, permission dialogs, input, design system, task panels, etc.
hooks/104React hooks: tool permissions, notifications, settings changes, etc.
keybindings/14Keybinding definitions and handling (chord support)
vim/5Vim mode implementation (motions, operators, text objects)

Infrastructure Layer (utils/, 564 files)

SubdirectoryResponsibility
permissions/Core permission decision logic, rule parsing, setup
settings/Layered config loading and merging (user/project/local/flag/policy)
model/Model selection, provider branching, capability checks
swarm/Multi-agent coordination: in-process teammates, tmux/iTerm backends
bash/Bash command parsing and security classification
plugins/Plugin loader
hooks/Lifecycle hooks
telemetry/Telemetry reporting

Extension Layer

DirectoryFilesResponsibility
plugins/2Plugin system (built-in plugin registration)
skills/20Skill system (bundled skills, disk skill loading)
bridge/31IDE bridge (VS Code, JetBrains)
tasks/12Task framework: local/remote agent tasks, teammate tasks

Core Data Flow

A complete user interaction flows through:

Next

Go to 02-startup-flow.md to understand the complete startup process from command line to interactive loop.