Tech Stack
Claude Code lร mแปt CLI app ฤฦฐแปฃc build bแบฑng stack rแบฅt thรบ vแป โ khรดng phแบฃi Node.js thรดng thฦฐแปng mร dรนng Bun runtime (custom fork cแปงa Anthropic) kแบฟt hแปฃp vแปi React + Ink ฤแป render terminal UI.
โก Bun Runtime (Custom Fork)
Anthropic fork Bun runtime riรชng, thรชm bun:bundle feature flags cho dead code elimination. Build-time defines nhฦฐ feature('KAIROS') cho phรฉp conditional compilation โ branches khรดng active sแบฝ bแป strip khแปi build output.
โ๏ธ React + Ink
Terminal UI ฤฦฐแปฃc render bแบฑng React components thรดng qua Ink library. REPL.tsx (879KB!) lร main screen component โ lแปn nhแบฅt codebase. Toร n bแป UI lร React components: Messages, PromptInput, Stats, VirtualMessageList...
๐ฆ TypeScript + Zod v4
Toร n bแป codebase dรนng TypeScript strict mode vแปi Zod cho schema validation. Tool inputs/outputs ฤแปu ฤฦฐแปฃc validate qua Zod schemas.
๐ง Commander.js CLI
CLI parsing dรนng Commander.js. Entry point main.tsx (789KB - monolithic bundle) setup Commander program vแปi 20+ subcommands.
Entry Point โ main.tsx (789KB)
File entry point khแปng lแป lร mแปt monolithic bundle. Nรณ khแปi tแบกo Commander program, ฤฤng kรฝ tแบฅt cแบฃ subcommands (claude chat, claude agent, etc.), parse CLI args, rแปi render React Ink app.
// Commander.js program setup
const program = new Command()
.name('claude')
.version(MACRO.VERSION)
.option('--model <model>', 'Model to use')
.option('--permission-mode <mode>', 'Permission mode')
.option('--tools <preset>', 'Tool preset')
.option('--add-dir <path>', 'Additional directories')
.option('--bare', 'Skip auto-discovery')
// ... 30+ more options
// Main interactive mode renders React Ink app
program.action(async () => {
await setup(/* ... */)
const { waitUntilExit } = render(
<App />, // React Ink component tree
{ exitOnCtrlC: false }
)
await waitUntilExit()
})
Architecture Diagram
879KB React Component] REPL --> QE[query.ts - Query Engine
Agentic Loop] QE --> API[claude.ts - API Layer
126KB] QE --> Tools[Tool System
40+ tools] QE --> Hooks[Hook System
Pre/Post Tool Use] Tools --> BashTool[BashTool
158KB] Tools --> FileEdit[FileEditTool] Tools --> AgentTool[AgentTool
230KB - Sub-agents] Tools --> MCPTools[MCP Tools
119KB client] REPL --> Messages[Message Components] REPL --> PromptInput[PromptInput
349KB] REPL --> Stats[Stats Panel] Setup --> Config[Config System] Setup --> Analytics[GrowthBook Analytics] Setup --> Memory[Memory System
autoDream + memdir] style CLI fill:#1a1e24,stroke:#58a6ff,color:#e6edf3 style REPL fill:#1a1e24,stroke:#bc8cff,color:#e6edf3 style QE fill:#1a1e24,stroke:#3fb950,color:#e6edf3 style AgentTool fill:#1a1e24,stroke:#f85149,color:#e6edf3 style Memory fill:#1a1e24,stroke:#d29922,color:#e6edf3
Build Pipeline
Bun bundler ฤฦฐแปฃc dรนng vแปi custom feature() flags tแปซ bun:bundle. Mแปi feature flag lร build-time constant โ cho phรฉp tree-shaking toร n bแป code paths khรดng active. Vรญ dแปฅ:
import { feature } from 'bun:bundle'
// External build: feature('KAIROS') = false โ entire block stripped
const SleepTool = feature('PROACTIVE') || feature('KAIROS')
? require('./tools/SleepTool/SleepTool.js').SleepTool
: null
// External build: feature('BUDDY') = false โ buddy code eliminated
const buddy = feature('BUDDY')
? require('./commands/buddy/index.js').default
: null
Directory Structure
| Directory | Files | Lines | Purpose |
|---|---|---|---|
utils/ | 564 | 165,026 | Utility functions โ lแปn nhแบฅt, chแปฉa permissions, messages, config, model, git, etc. |
components/ | 389 | 80,166 | React Ink UI components โ Messages, VirtualList, LogSelector, Stats |
services/ | 130 | 49,063 | API layer, MCP, analytics, compact, autoDream, memory extraction |
tools/ | 184 | 47,211 | All 40+ tool implementations |
commands/ | 189 | 24,973 | 70+ slash commands |
hooks/ | 104 | 17,931 | React hooks cho state management |
bridge/ | 31 | 11,761 | Bridge mode โ remote control via daemon |
skills/ | 20 | 3,538 | Skill system โ loadSkillsDir, bundledSkills |
memdir/ | 8 | 1,639 | Memory directory system โ paths, types, scanning |
vim/ | 5 | 1,358 | Full Vim mode โ motions, operators, text objects |
buddy/ | 6 | 1,253 | ๐ฅ Hidden Tamagotchi pet system! |
coordinator/ | 1 | 276 | Multi-agent coordinator mode |