The codebase is organized by function: tools, services, components, utilities. The system boots in ~200ms by overlapping I/O with module loading. The conversation loop is an async generator. Tools execute while the API response is still streaming.
The src/ directory organized by function. Every top-level directory with file counts from the actual source.
| Directory | Files | What's Inside |
|---|---|---|
utils/ | 564 | Permissions (24 files), bash AST parser, sandbox adapter, model routing, settings, git ops, swarm backends (tmux/iTerm/in-process), computer use, deep links, memory, telemetry, suggestions |
components/ | 389 | Ink terminal UI — messages, permission dialogs, settings panels, diff viewer, task list, team management, design system, prompt input |
commands/ | 207 | 84 slash commands each in own dir — /help, /plan, /review, /buddy, /voice. 24+ internal-only stripped from external builds |
tools/ | 184 | 43 tool implementations — Bash, FileEdit, FileRead, FileWrite, Glob, Grep, Agent, MCP, WebFetch, Skill, Task*, Team*, Cron*, Plan, Worktree, LSP |
services/ | 130 | API client (multi-provider), MCP protocol (24 files), StreamingToolExecutor, compaction, analytics, OAuth, plugins, policy limits, prompt suggestion, memory extraction, autoDream, team memory sync |
hooks/ | 104 | React hooks — useStream, useTools, tool permissions, notifications. 20 hook events (Setup → Stop) |
ink/ | 96 | Custom Ink fork — React reconciler, Yoga WASM flexbox, ANSI parser/optimizer, DOM, frame rendering, double-buffering, terminal I/O, events, hit testing, selection |
bridge/ | 31 | IDE/remote — OAuth, JWT refresh, trusted devices, WebSocket, SSE, session management, keepalive |
constants/ | 21 | Prompts, system prompt sections, API limits, spinner verbs, cyber risk instructions, OAuth scopes |
skills/ | 20 | 19 bundled skills — /schedule, /loop, /claude-api, /simplify, /ship, /investigate. Plus loading infra |
cli/ | 19 | CLI entry (cli.tsx 39KB), headless/print mode (212KB), transport handlers |
keybindings/ | 14 | Custom keyboard shortcuts — schema, parser, resolver, validator, chord bindings, defaults |
tasks/ | 12 | Task runners — RemoteAgent, InProcessTeammate, LocalAgent, LocalShell, DreamTask |
migrations/ | 11 | Model renames (Fennec→Opus, Sonnet 4.5→4.6), settings migrations, consent tracking |
types/ | 11 | Permission types, hook types, command types, plugin types, generated protobuf |
context/ | 9 | React contexts — prompt overlay, FPS metrics, mailbox, notifications, stats, modal, voice |
memdir/ | 8 | Memory system — MEMORY.md loader, 4 memory types, scan, relevance scoring, team memory prompts |
entrypoints/ | 8 | CLI bootstrap, SDK entry, MCP server entry, init sequence, sandbox types |
buddy/ | 6 | Companion sprite — 18 species, procedural generation, animation, sprites |
state/ | 6 | Zustand store, AppState types, store factory, snapshots |
vim/ | 5 | Full vim mode — motions, operators, 11 text objects, state machine, dot-repeat |
query/ | 4 | Core loop — token budget, stop hooks, config, dependencies |
native-ts/ | 4 | Native bindings — color-diff, file-index, yoga-layout (WASM) |
remote/ | 4 | Remote session management, WebSocket, SDK adapter, permission bridge |
screens/ | 3 | REPL.tsx (896KB), ResumeConversation.tsx (60KB), Doctor.tsx (73KB) |
server/ | 3 | Direct connect sessions, connection manager |
plugins/ | 2 | Plugin loading, built-in plugin registry |
upstreamproxy/ | 2 | Upstream proxy + relay for CCR mTLS |
coordinator/ | 1 | Coordinator mode — worker orchestration with shared scratchpad |
voice/ | 1 | Voice mode enablement (SoX + mic + OAuth + kill-switch) |
What happens when you type claude — a 3-phase pipeline that overlaps I/O with module loading. Side effects fire before 187 imports resolve.
--version exits immediately. --daemon-worker, --chrome-native-host, --computer-use-mcp route to handlers. Zero module evaluation.feature() eliminates code at build time. 26 flags — external builds strip all ANT-only code. Binary is measurably smaller.startMdmRawRead() spawns plutil/reg query (~135ms). startKeychainPrefetch() fires two keychain reads (~65ms). Both overlap with 187 imports resolving.~/.claude/auth.json or ANTHROPIC_API_KEY. Provider detection: Bedrock/Vertex/Foundry env vars.tengu_* gates fetched async (disk-cached).The conversation loop (query.ts, 1,729 lines) is an async generator. The REPL consumes events via for await.
The src/ink/ directory (96 files) is a heavily modified Ink fork — not a thin wrapper.
Two-layer system: a global singleton for process-lifetime data, and a Zustand store for React-integrated UI state.
150+ fields surviving the entire process:
originalCwd, projectRoottotalCostUSD, totalAPIDuration, totalToolDurationmodelUsage — per-model token accountingsessionId, agentColorMaplastAPIRequest — debugging (sans messages)cachedClaudeMdContent — for auto-mode classifierImmutable (DeepImmutable):
Mutable:
Bun's feature() enables compile-time dead code elimination. Not runtime checks — code is physically absent from the binary.
if (feature('COORDINATOR_MODE')) { ... } — the entire block is removed from the external binary at build time. 26 flags total, almost all ANT-only. External builds are measurably smaller.
The source you're reading includes ~26 features that don't exist in the binary you download. Coordinator mode, ML classifier, voice, computer use, buddy. Internal and external are architecturally different products.