/root/architecture/lifecycle_map
System Lifecycle 01
From raw CLI entry to interactive REPL. How cli.tsx bootstraps through 12 fast-path exits, loads main.tsx, initializes services via init.ts, and mounts the React terminal UI.
01_ENTRYPOINT
terminal
cli.tsx:33
CLI Bootstrap
Process arguments parsed. 12 fast-path exits checked before loading any modules. Zero-import --version path.
> async function main(): Promise<void>
┌── FAST PATHS ──┐
--version
--dump-system-prompt
--claude-in-chrome-mcp
--daemon-worker
remote-control / bridge
daemon
ps / logs / attach / kill
new / list / reply
environment-runner
self-hosted-runner
│
▼
▼
02_COMMANDER
settings
main.tsx
Commander CLI definition. ~50 options parsed. preAction hook triggers init(). Subcommands: mcp, doctor, auth, plugin, update.
KEY OPTIONS:
-p "prompt"
--model
--resume
--worktree
--bare
--sdk-url
--verbose
--max-turns
│
▼
▼
schema
init.ts — Service Initialization
memoized (runs once)BLOCKING (must complete):
- 1. initSinks() — telemetry pipeline
- 2. runMigrations() — DB schema
- 3. loadRemoteManagedSettings()
- 4. enableConfigs() — settings cascade
FIRE-AND-FORGET (async):
- • GrowthBook feature flags
- • Policy limits fetch
- • Bootstrap API data
- • Session memory init
│
▼
▼
04_MODE_SELECT
Operating Mode
INTERACTIVE
REPL Mode
Default. Mounts
REPL.tsx (5,006 lines). Full Ink terminal UI with streaming, tools, permissions.HEADLESS
Print Mode (-p)
Single query, stdout output.
runHeadless() uses QueryEngine directly. No Ink rendering.SERVER
MCP / SDK Mode
Exposes tools via MCP protocol (stdio) or SDK transport (WebSocket/SSE). No terminal UI.
│
▼
▼
REPL
smart_display
REPL.tsx — The Terminal UI
5,006 LINES | REACT + INK (CUSTOM FORK)
chat
Message Stream
Streaming text, thinking, tool calls rendered in real-time
security
Permission Dialogs
Interactive approve/deny for tool execution
keyboard
Input System
Prompt input, vim mode, slash commands, key bindings
SDK TRANSPORTS
WebSocket
Bidirectional real-time. Full duplex reads and writes over a single WS connection.
Hybrid
WS for reads, HTTP POST for writes. Used when WS writes are unreliable.
SSE
Server-Sent Events for reads, HTTP POST for writes. Firewall-friendly fallback.
CCR Client
Claude Code Remote. Connects to cloud-hosted containers with auto-selection logic.