Skip to content

Claude Code - Module Inventory

Summary Statistics

  • Total source files: 1884 (.ts/.tsx)
  • Top-level modules: 35 subdirectories + 18 root-level files
  • Core modules: 15 (essential for understanding the system)
  • Supporting modules: 8 (important but not entry points)
  • Peripheral modules: 12 (feature-specific or auxiliary)

Module Classification

CORE Modules (Detailed Coverage Required)

ModulePathFilesComplexityResponsibility
Tool contractsrc/Tool.ts1 (793 lines)CriticalTool<Input,Output> interface, ToolUseContext (40+ fields), buildTool() factory
QueryEnginesrc/QueryEngine.ts1 (1296 lines)CriticalSDK/headless conversation engine, submitMessage() async generator
query loopsrc/query.ts + src/query/5CriticalCore agentic loop: API calls, streaming, tool execution, compaction
bootstrap/statesrc/bootstrap/1 (1759 lines)CriticalGlobal singleton: session ID, cost, model, telemetry, ~80 getters/setters
toolssrc/tools/184CriticalAll tool implementations (Bash, Agent, FileEdit, FileRead, Grep, etc.)
commandssrc/commands/ + src/commands.ts208High70+ slash commands registry, feature-flag conditional loading
screens/REPLsrc/screens/3CriticalInteractive terminal session, most complex UI component (~3000 lines)
inksrc/ink/85CriticalCustom React reconciler for terminal, Yoga WASM layout, ANSI rendering
componentssrc/components/389HighAll UI components: messages, permissions, prompt input, design system
hookssrc/hooks/~100HighReact hooks: permission handling, command processing, typeahead, etc.
statesrc/state/6HighAppState (150+ fields), Zustand-like store, React context provider
servicessrc/services/130HighAPI client, MCP, compaction, analytics, LSP, OAuth, tool orchestration
utilssrc/utils/564HighLargest module: bash parsing, permissions, plugins, settings, swarm, model, telemetry
entrypointssrc/entrypoints/8HighCLI bootstrap, MCP server mode, SDK type exports
typessrc/types/~10MediumShared types: Command, permissions, hooks, IDs, plugins

SUPPORTING Modules (Brief Coverage)

ModulePathFilesComplexityResponsibility
taskssrc/tasks/12HighBackground task runners: shell, agent, teammate, dream, workflow
skillssrc/skills/20MediumMarkdown skill loading from .claude/skills/, bundled skills
bridgesrc/bridge/33HighRemote control bridge: mobile/web -> local CLI session
clisrc/cli/15MediumCLI I/O, structured output, SSE/WebSocket transports
memdirsrc/memdir/8MediumMemory directory: .claude/memory/ file management
keybindingssrc/keybindings/14MediumCustomizable keyboard shortcuts
constantssrc/constants/20LowAPI limits, beta headers, product strings, prompts
contextsrc/context/9MediumReact contexts: notifications, mailbox, modal, voice

PERIPHERAL Modules (Mention Only)

ModulePathFilesComplexityResponsibility
coordinatorsrc/coordinator/1LowSwarm coordinator mode context injection
schemassrc/schemas/1LowZod schema for hooks config
buddysrc/buddy/6LowCompanion mascot feature (feature-flagged)
pluginssrc/plugins/2LowBuilt-in plugin registration
remotesrc/remote/4MediumRemote session management (--remote mode)
serversrc/server/3MediumDirect Connect server (Unix domain socket)
migrationssrc/migrations/11LowOne-time data migrations for settings
vimsrc/vim/5MediumVim mode for prompt input
voicesrc/voice/1LowVoice mode feature flag check
outputStylessrc/outputStyles/1LowCustom output style definitions
native-tssrc/native-ts/4Low (interface)TS ports of native libs (yoga-layout, color-diff)
morerightsrc/moreright/1LowContent overflow detection hook
assistantsrc/assistant/1LowRemote session history for Kairos feature
upstreamproxysrc/upstreamproxy/2LowHTTP proxy support for enterprise firewalls

Root-Level Files

FileResponsibilityComplexity
src/main.tsxMain CLI entry, all run modes, ToolUseContext assemblyCritical
src/Tool.tsTool interface & ToolUseContext definitionCritical
src/QueryEngine.tsSDK conversation engineCritical
src/query.tsCore agentic loopCritical
src/commands.tsCommand registry (70+ commands)High
src/setup.tsProcess-level initializationHigh
src/context.tsCLAUDE.md loading & system contextMedium
src/tools.tsTool assembly & registrationMedium
src/tasks.tsTask type handler registrationLow
src/Task.tsTask interface & types (7 task types)Medium
src/ink.tsRe-exports custom Ink libraryLow
src/cost-tracker.tsAPI cost tracking per sessionLow
src/history.tsSession history read/writeMedium
src/costHook.tsCost tracking hookLow
src/dialogLaunchers.tsxDialog launch helpersLow
src/interactiveHelpers.tsxInteractive mode helpersLow
src/replLauncher.tsxREPL launch orchestratorMedium
src/projectOnboardingState.tsProject onboarding state managementLow

Key Tool Implementations

ToolPathFilesComplexityNotes
AgentToolsrc/tools/AgentTool/22CriticalRecursive sub-agent, context forking, MCP connection
BashToolsrc/tools/BashTool/18CriticalShell execution, security validation, 2600-line permission file
FileEditToolsrc/tools/FileEditTool/~8HighString replacement, diff display, permission prompts
FileReadToolsrc/tools/FileReadTool/~6MediumFile reading, image processing, size limits
FileWriteToolsrc/tools/FileWriteTool/~6MediumFile creation/overwrite
GrepToolsrc/tools/GrepTool/~4MediumRipgrep-based content search
GlobToolsrc/tools/GlobTool/~4Low-MediumPattern-based file search
MCPToolsrc/tools/MCPTool/~6HighMCP server tool proxy
LSPToolsrc/tools/LSPTool/~4MediumLanguage server protocol
WebSearchToolsrc/tools/WebSearchTool/~4MediumWeb search
WebFetchToolsrc/tools/WebFetchTool/~4MediumWeb page fetching
SkillToolsrc/tools/SkillTool/~4MediumSkill command invocation
NotebookEditToolsrc/tools/NotebookEditTool/~4MediumJupyter notebook editing

Key Service Modules

ServicePathFilesComplexityNotes
apisrc/services/api/19HighAnthropic API client, retry, usage tracking, cost calculation
mcpsrc/services/mcp/22HighMCP connection management, OAuth, 4 transport types
compactsrc/services/compact/12HighContext window management: auto/micro/snip compaction
analyticssrc/services/analytics/9MediumGrowthBook, event logging, Datadog
toolssrc/services/tools/4HighStreamingToolExecutor, tool orchestration
lspsrc/services/lsp/6MediumLanguage server lifecycle
oauthsrc/services/oauth/5MediumOAuth2 authentication flow
pluginssrc/services/plugins/3MediumPlugin installation & operations
SessionMemorysrc/services/SessionMemory/3MediumSession memory extraction/injection
autoDreamsrc/services/autoDream/4MediumBackground dream consolidation

Essential Files for Understanding the Codebase (Top 15)

  1. src/Tool.ts — Tool type contract + ToolUseContext
  2. src/QueryEngine.ts — Headless conversation lifecycle
  3. src/query.ts — Inner agentic loop
  4. src/bootstrap/state.ts — Global singleton state
  5. src/commands.ts — Command registry
  6. src/state/store.ts — Minimal pub/sub store (35 lines, best starting point)
  7. src/state/AppStateStore.ts — AppState type definition
  8. src/screens/REPL.tsx — Interactive session orchestrator
  9. src/tools/AgentTool/runAgent.ts — Recursive sub-agent invocation
  10. src/tools/BashTool/BashTool.tsx — Most security-sensitive tool
  11. src/hooks/useCanUseTool.tsx — Central permission decision point
  12. src/services/api/claude.ts — Anthropic API streaming client
  13. src/services/compact/autoCompact.ts — Context window management
  14. src/types/permissions.ts — Permission type definitions (9-variant union)
  15. src/context.ts — CLAUDE.md loading & system context injection

Built for learners who want to read Claude Code like a real system.