Welcome to the documentation for Claude Code (claude-code-main). This repository contains the documentation for an agentic coding assistant CLI developed by Anthropic, which brings the conversational abilities of Claude natively into your terminal environment.
Claude Code is a robust TypeScript project built for execution in the terminal using Node/Bun runtimes and Ink/React for UI rendering. Its primary purpose is to help users manage codebases by executing bash sequences, reading/writing files, orchestrating complex tools, and interfacing natively with the Model Context Protocol (MCP).
The codebase contains 1,884+ TypeScript/TSX files organized across 101 commands, 43 tools, 147 React components, 85+ hooks, 329+ utilities, and 38 service modules.
CLAUDE CODE ARCHITECTURE
===========================================================================================
USER INPUT CORE ENGINE EXTERNAL SERVICES
βββββββββ βββββββββββ βββββββββββββββββ
βββββββββββββββ ββββββββββββββββββββββββββ
β Terminal β β main.tsx β
β (stdin) ββββββββββββΊ β βββββββββββββββββββ β
β β β β Commander.js β β
β - Text β β β CLI Parser β β
β - Voice β β βββββββββ¬ββββββββββ β
β - Images β β β β
β - Files β β βΌ β
βββββββββββββββ β βββββββββββββββββββ β
β² β β setup.ts β β
β β β Bootstrap β β
β β β (12 steps) β β
β β βββββββββ¬ββββββββββ β
β ββββββββββββΌββββββββββββββ
β β
β βΌ
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β QueryEngine.ts β
β β βββββββββββββββββββββββββββββββββββββββββββββββ β
β β β MESSAGE LOOP β β
β β β β β
β β β 1. Build System Prompt β β
β β β ββ CLAUDE.md files β β
β β β ββ Memory (memdir/) β β
β β β ββ Git context β β
β β β ββ Environment info β β
β β β β β β
β β β 2. Call Anthropic API ββββββββββββββββββββββΌββΌβββΊ Anthropic API
β β β (streaming) β β β (claude.ts)
β β β βΌ β β
β β β 3. Parse Stream Response β β
β β β ββ Text chunks ββββββββββΊ stdout β β
β β β ββ Tool calls βββ β β
β β β β β β
β β β 4. Execute Tools β β β
β β β βββββββββββββ β β
β β β βΌ β β
β β β βββββββββββββββ βββββββββββββββββββββββ β β
β β β β Permission β β TOOL POOL (43) β β β
β β β β Check βββββΊβ β β β
β β β β β β BashTool β β β
β β β β βββββββββββ β β FileRead/Edit/Writeβ β β
β β β β β Rules β β β Grep / Glob β β β
β β β β β Classifrβ β β WebSearch/Fetch β β β
β β β β β Interactβ β β MCPTool / LSPTool β β β
β β β β βββββββββββ β β AgentTool β β β
β β β βββββββββββββββ β TaskCreate/Update β β β
β β β β β EnterPlanMode β β β
β β β β β EnterWorktree β β β
β β β β β SkillTool β β β
β β β β β NotebookEdit β β β
β β β β βββββββββββββββββββββββ β β
β β β β β β
β β β 5. Append Tool Results to Messages β β
β β β β β β
β β β ββββββββΊ Loop back to step 2 β β
β β β (until no more tool calls) β β
β β βββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β β Cost Tracker βββ Token counting + pricing β
β β Session Store ββ JSONL transcript persistence β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β βΌ
β ββββββββββββββββββββββββ
β β Ink / React UI β
β β β
β β βββββββββββββββββββ β
β β β App.tsx β β
ββββββββββββββββββββββββ€ β ββ StatusLine β β
β β ββ Messages β β
β β ββ ToolApprovalβ β
β β ββ Dialogs β β
β β ββ TextInput β β
β βββββββββββββββββββ β
ββββββββββββββββββββββββ
===========================================================================================
EXTENSION & INTEGRATION SYSTEMS
===========================================================================================
ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββββββββ
β PLUGINS β β SKILLS β β MCP β β BRIDGE / REMOTE β
β β β β β SERVERS β β β
β Marketplace β β Bundled β β β β ββββββββββ ββββββββββ β
β User plugins β β User skills β β Stdio/SSE/WS β β βclaude β β Local β β
β Built-in β β Plugin skillsβ β transports β β β .ai ββββ Bridge β β
β β β β β β β ββββββββββ βββββ¬βββββ β
β Hooks ββββββββ€ β Inline/Fork β β Tool/Resourceβ β β β
β Commands β β execution β β discovery β β Poll / SSE / WebSocket β
β MCP servers β β β β β β β β
β LSP servers β β β β β β βββββββββββββββββ β
ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β βΌ β
β Session Runner β
β (child CLI process) β
ββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β AGENT SWARMS & TEAMS β
β β
β βββββββββββββ SendMessage βββββββββββββ βββββββββββββ β
β β Leader βββββββββββββββββββββΊβ Worker 1 β β Worker 2 β β
β β (coord.) β Mailbox β (tmux) β β (in-proc) β β
β β β β β β β β
β β TeamFile β βββββββββββββ β Worktree β β AsyncLocalβ β
β β AppState β β Worker 3 β β isolated β β Storage β β
β βββββββββββββ β (iTerm2) β βββββββββββββ βββββββββββββ β
β βββββββββββββ β
β Backends: tmux | iTerm2 | in-process β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
===========================================================================================
PERSISTENCE & SECURITY
===========================================================================================
ββββββββββββββββββββββββ βββββββββββββββββββββββββ ββββββββββββββββββββββββββββ
β SESSION STORAGE β β CONFIGURATION β β SECURITY β
β β β β β β
β ~/.claude/projects/ β β ~/.claude/ β β OAuth 2.0 + PKCE β
β <project>/ β β settings.json β β Keychain (macOS) β
β <session>.jsonl β β keybindings.json β β Permission rules β
β β β β β Auto-mode classifier β
β ~/.claude/ β β .claude/ β β Trusted devices β
β history.jsonl β β settings.json β β Secret scanning β
β β β CLAUDE.md β β Sandbox (seatbelt) β
β Memory: β β settings.local.json β β β
β memory/MEMORY.md β β β β 7 permission modes: β
β memory/*.md β β Remote managed β β default, acceptEdits, β
β β β settings (API) β β plan, bypass, dontAsk, β
β Plans: β β β β auto, bubble β
β plans/*.md β β MDM / policy drops β β β
ββββββββββββββββββββββββ βββββββββββββββββββββββββ ββββββββββββββββββββββββββββ
===========================================================================================
IDE INTEGRATION
===========================================================================================
ββββββββββββββ MCP ββββββββββββββββ Native ββββββββββββββββ
β VS Code βββββββββΊβ β Messaging β Chrome β
β JetBrains β SSE/ β Claude Code βββββββββββββΊβ Extension β
β β WS β CLI β β β
ββββββββββββββ β β Handoff ββββββββββββββββ
β βββββββββββββΊβ Claude β
ββββββββββββββββ β Desktop App β
ββββββββββββββββ
-
Core Architecture & Orchestration The
QueryEnginemessage loop, API services, dynamic system prompts, cost tracking, state management, and FastMode. -
CLI & Terminal UI Command-line entry points, React/Ink terminal UI, interactive helpers, dialog system, and all 101+ slash commands.
-
Tools & Agent Ecosystem All 43 tools, the
ToolDefinterface, file system tools, web tools, protocol tools (MCP, LSP), and permission validation. -
Agent Swarms & Teams Multi-agent orchestration with tmux/iTerm2/in-process backends, team management, coordinator mode, inter-agent messaging, swarm architecture, and team memory sync.
-
Services & Integrations MCP backend, session analytics, cost tracking, voice I/O, rate limiting, compaction, LSP, and prompt suggestions.
-
Bridge & Remote Execution Remote session lifecycle, transport layers (v1 WebSocket, v2 SSE), bridge messaging protocol, trusted device management, and the REPL bridge.
-
Permission & Security System Permission modes, rule sources and matching, the multi-stage checking flow (rules -> classifier -> interactive), secure storage, auto mode, and permission persistence.
-
Authentication, State & Configuration OAuth 2.0 + PKCE authentication, API key management, AppState architecture, settings hierarchy, remote managed settings, user hooks system, and keybindings.
- Session, History & Memory JSONL session storage, resume/rewind, prompt history, context compaction strategies, the memory directory system, session memory, and background memory extraction.
- Plugins & Skills System Plugin types and discovery, marketplace integration, plugin lifecycle, the skills architecture (inline vs fork execution), bundled skills, and extension points.
- Planning, Tasks & IDE Integration Planning mode workflow, git worktree isolation, the task system (CRUD, dependencies, ownership), IDE integration (VS Code, JetBrains, Chrome extension), and context management.
- Unique & Novel Architectural Patterns The patterns that make this codebase different: async generator query loops, prompt cache-sharing forks, AI-powered permission classification, speculative execution with overlay filesystems, two-layer microcompaction, AsyncLocalStorage agent isolation, and more.