Skip to content

AppGambitStudio/Claude-Code-Docs

Repository files navigation

Claude Code Documentation

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.

Overview

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.

How Claude Code Works

                                    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  β”‚
                                                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Table of Contents

Core Architecture

  1. Core Architecture & Orchestration The QueryEngine message loop, API services, dynamic system prompts, cost tracking, state management, and FastMode.

  2. CLI & Terminal UI Command-line entry points, React/Ink terminal UI, interactive helpers, dialog system, and all 101+ slash commands.

Tool & Agent Ecosystem

  1. Tools & Agent Ecosystem All 43 tools, the ToolDef interface, file system tools, web tools, protocol tools (MCP, LSP), and permission validation.

  2. 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

  1. Services & Integrations MCP backend, session analytics, cost tracking, voice I/O, rate limiting, compaction, LSP, and prompt suggestions.

  2. Bridge & Remote Execution Remote session lifecycle, transport layers (v1 WebSocket, v2 SSE), bridge messaging protocol, trusted device management, and the REPL bridge.

Security & Permissions

  1. Permission & Security System Permission modes, rule sources and matching, the multi-stage checking flow (rules -> classifier -> interactive), secure storage, auto mode, and permission persistence.

  2. Authentication, State & Configuration OAuth 2.0 + PKCE authentication, API key management, AppState architecture, settings hierarchy, remote managed settings, user hooks system, and keybindings.

Session & Memory

  1. Session, History & Memory JSONL session storage, resume/rewind, prompt history, context compaction strategies, the memory directory system, session memory, and background memory extraction.

Extensibility

  1. 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

  1. 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.

Deep Dives

  1. 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.

Reference Links

About

Welcome to the documentation for Claude Code (1st Apr 2026)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors