Layer Diagram
The Four Main Layers
Entry Layer
cli.tsx parses CLI flags and version info, then delegates to main.tsx. From there, the app forks: interactive sessions render with React/Ink via REPL.tsx, while SDK/headless consumers go through QueryEngine.ts.Query Engine
The SDK-facing lifecycle engine.
submitMessage() returns an AsyncGenerator<SDKMessage> that drives the full agent loop — assembling prompts, handling slash commands, streaming tool execution, and compacting context.Three Pillars
Tool System — 40+ tools behind a uniform
Tool<Input, Output, Progress> interface. Service Layer — API client, compact engine, MCP manager, analytics. State Layer — AppStateStore providing React context for permissions, file history, and model settings.Task & Bridge Layer
Tasks represent long-running work:
local_bash, local_agent, remote_agent, in_process, dream, and workflow. The Bridge Layer (bridgeMain.ts) connects to Claude Desktop or remote containers via HTTP with JWT auth and backoff.