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)
| Module | Path | Files | Complexity | Responsibility |
|---|---|---|---|---|
| Tool contract | src/Tool.ts | 1 (793 lines) | Critical | Tool<Input,Output> interface, ToolUseContext (40+ fields), buildTool() factory |
| QueryEngine | src/QueryEngine.ts | 1 (1296 lines) | Critical | SDK/headless conversation engine, submitMessage() async generator |
| query loop | src/query.ts + src/query/ | 5 | Critical | Core agentic loop: API calls, streaming, tool execution, compaction |
| bootstrap/state | src/bootstrap/ | 1 (1759 lines) | Critical | Global singleton: session ID, cost, model, telemetry, ~80 getters/setters |
| tools | src/tools/ | 184 | Critical | All tool implementations (Bash, Agent, FileEdit, FileRead, Grep, etc.) |
| commands | src/commands/ + src/commands.ts | 208 | High | 70+ slash commands registry, feature-flag conditional loading |
| screens/REPL | src/screens/ | 3 | Critical | Interactive terminal session, most complex UI component (~3000 lines) |
| ink | src/ink/ | 85 | Critical | Custom React reconciler for terminal, Yoga WASM layout, ANSI rendering |
| components | src/components/ | 389 | High | All UI components: messages, permissions, prompt input, design system |
| hooks | src/hooks/ | ~100 | High | React hooks: permission handling, command processing, typeahead, etc. |
| state | src/state/ | 6 | High | AppState (150+ fields), Zustand-like store, React context provider |
| services | src/services/ | 130 | High | API client, MCP, compaction, analytics, LSP, OAuth, tool orchestration |
| utils | src/utils/ | 564 | High | Largest module: bash parsing, permissions, plugins, settings, swarm, model, telemetry |
| entrypoints | src/entrypoints/ | 8 | High | CLI bootstrap, MCP server mode, SDK type exports |
| types | src/types/ | ~10 | Medium | Shared types: Command, permissions, hooks, IDs, plugins |
SUPPORTING Modules (Brief Coverage)
| Module | Path | Files | Complexity | Responsibility |
|---|---|---|---|---|
| tasks | src/tasks/ | 12 | High | Background task runners: shell, agent, teammate, dream, workflow |
| skills | src/skills/ | 20 | Medium | Markdown skill loading from .claude/skills/, bundled skills |
| bridge | src/bridge/ | 33 | High | Remote control bridge: mobile/web -> local CLI session |
| cli | src/cli/ | 15 | Medium | CLI I/O, structured output, SSE/WebSocket transports |
| memdir | src/memdir/ | 8 | Medium | Memory directory: .claude/memory/ file management |
| keybindings | src/keybindings/ | 14 | Medium | Customizable keyboard shortcuts |
| constants | src/constants/ | 20 | Low | API limits, beta headers, product strings, prompts |
| context | src/context/ | 9 | Medium | React contexts: notifications, mailbox, modal, voice |
PERIPHERAL Modules (Mention Only)
| Module | Path | Files | Complexity | Responsibility |
|---|---|---|---|---|
| coordinator | src/coordinator/ | 1 | Low | Swarm coordinator mode context injection |
| schemas | src/schemas/ | 1 | Low | Zod schema for hooks config |
| buddy | src/buddy/ | 6 | Low | Companion mascot feature (feature-flagged) |
| plugins | src/plugins/ | 2 | Low | Built-in plugin registration |
| remote | src/remote/ | 4 | Medium | Remote session management (--remote mode) |
| server | src/server/ | 3 | Medium | Direct Connect server (Unix domain socket) |
| migrations | src/migrations/ | 11 | Low | One-time data migrations for settings |
| vim | src/vim/ | 5 | Medium | Vim mode for prompt input |
| voice | src/voice/ | 1 | Low | Voice mode feature flag check |
| outputStyles | src/outputStyles/ | 1 | Low | Custom output style definitions |
| native-ts | src/native-ts/ | 4 | Low (interface) | TS ports of native libs (yoga-layout, color-diff) |
| moreright | src/moreright/ | 1 | Low | Content overflow detection hook |
| assistant | src/assistant/ | 1 | Low | Remote session history for Kairos feature |
| upstreamproxy | src/upstreamproxy/ | 2 | Low | HTTP proxy support for enterprise firewalls |
Root-Level Files
| File | Responsibility | Complexity |
|---|---|---|
src/main.tsx | Main CLI entry, all run modes, ToolUseContext assembly | Critical |
src/Tool.ts | Tool interface & ToolUseContext definition | Critical |
src/QueryEngine.ts | SDK conversation engine | Critical |
src/query.ts | Core agentic loop | Critical |
src/commands.ts | Command registry (70+ commands) | High |
src/setup.ts | Process-level initialization | High |
src/context.ts | CLAUDE.md loading & system context | Medium |
src/tools.ts | Tool assembly & registration | Medium |
src/tasks.ts | Task type handler registration | Low |
src/Task.ts | Task interface & types (7 task types) | Medium |
src/ink.ts | Re-exports custom Ink library | Low |
src/cost-tracker.ts | API cost tracking per session | Low |
src/history.ts | Session history read/write | Medium |
src/costHook.ts | Cost tracking hook | Low |
src/dialogLaunchers.tsx | Dialog launch helpers | Low |
src/interactiveHelpers.tsx | Interactive mode helpers | Low |
src/replLauncher.tsx | REPL launch orchestrator | Medium |
src/projectOnboardingState.ts | Project onboarding state management | Low |
Key Tool Implementations
| Tool | Path | Files | Complexity | Notes |
|---|---|---|---|---|
| AgentTool | src/tools/AgentTool/ | 22 | Critical | Recursive sub-agent, context forking, MCP connection |
| BashTool | src/tools/BashTool/ | 18 | Critical | Shell execution, security validation, 2600-line permission file |
| FileEditTool | src/tools/FileEditTool/ | ~8 | High | String replacement, diff display, permission prompts |
| FileReadTool | src/tools/FileReadTool/ | ~6 | Medium | File reading, image processing, size limits |
| FileWriteTool | src/tools/FileWriteTool/ | ~6 | Medium | File creation/overwrite |
| GrepTool | src/tools/GrepTool/ | ~4 | Medium | Ripgrep-based content search |
| GlobTool | src/tools/GlobTool/ | ~4 | Low-Medium | Pattern-based file search |
| MCPTool | src/tools/MCPTool/ | ~6 | High | MCP server tool proxy |
| LSPTool | src/tools/LSPTool/ | ~4 | Medium | Language server protocol |
| WebSearchTool | src/tools/WebSearchTool/ | ~4 | Medium | Web search |
| WebFetchTool | src/tools/WebFetchTool/ | ~4 | Medium | Web page fetching |
| SkillTool | src/tools/SkillTool/ | ~4 | Medium | Skill command invocation |
| NotebookEditTool | src/tools/NotebookEditTool/ | ~4 | Medium | Jupyter notebook editing |
Key Service Modules
| Service | Path | Files | Complexity | Notes |
|---|---|---|---|---|
| api | src/services/api/ | 19 | High | Anthropic API client, retry, usage tracking, cost calculation |
| mcp | src/services/mcp/ | 22 | High | MCP connection management, OAuth, 4 transport types |
| compact | src/services/compact/ | 12 | High | Context window management: auto/micro/snip compaction |
| analytics | src/services/analytics/ | 9 | Medium | GrowthBook, event logging, Datadog |
| tools | src/services/tools/ | 4 | High | StreamingToolExecutor, tool orchestration |
| lsp | src/services/lsp/ | 6 | Medium | Language server lifecycle |
| oauth | src/services/oauth/ | 5 | Medium | OAuth2 authentication flow |
| plugins | src/services/plugins/ | 3 | Medium | Plugin installation & operations |
| SessionMemory | src/services/SessionMemory/ | 3 | Medium | Session memory extraction/injection |
| autoDream | src/services/autoDream/ | 4 | Medium | Background dream consolidation |
Essential Files for Understanding the Codebase (Top 15)
src/Tool.ts— Tool type contract + ToolUseContextsrc/QueryEngine.ts— Headless conversation lifecyclesrc/query.ts— Inner agentic loopsrc/bootstrap/state.ts— Global singleton statesrc/commands.ts— Command registrysrc/state/store.ts— Minimal pub/sub store (35 lines, best starting point)src/state/AppStateStore.ts— AppState type definitionsrc/screens/REPL.tsx— Interactive session orchestratorsrc/tools/AgentTool/runAgent.ts— Recursive sub-agent invocationsrc/tools/BashTool/BashTool.tsx— Most security-sensitive toolsrc/hooks/useCanUseTool.tsx— Central permission decision pointsrc/services/api/claude.ts— Anthropic API streaming clientsrc/services/compact/autoCompact.ts— Context window managementsrc/types/permissions.ts— Permission type definitions (9-variant union)src/context.ts— CLAUDE.md loading & system context injection