Orientation
Start with these files before exploring anything else. They form the spine of the entire system.| What | Where |
|---|---|
| CLI entrypoint | src/main.tsx |
| Core LLM engine | src/QueryEngine.ts (~46K lines) |
| Tool definitions | src/Tool.ts (~29K lines) |
| Command registry | src/commands.ts (~25K lines) |
| Tool registry | src/tools.ts |
| Context collection | src/context.ts |
| All tool implementations | src/tools/ (40 subdirectories) |
| All command implementations | src/commands/ (~85 subdirectories + 15 files) |
Finding things
How does tool X work?
Go to the tool directory
Every tool lives at
src/tools/{ToolName}/. For example, src/tools/BashTool/.Read the main implementation
The core logic is in
{ToolName}.ts or {ToolName}.tsx inside that directory.Check the UI component
UI.tsx contains the React component that renders the tool’s invocation and result in the terminal.How does command X work?
Checksrc/commands/{command-name}/ (directory) or src/commands/{command-name}.ts (file).
- PromptCommands — look for
getPromptForCommand(), which builds a formatted prompt sent to the LLM with injected tools. - LocalCommands — look for the direct implementation function that runs in-process and returns text or JSX.
How does feature X work?
Permissions
src/hooks/toolPermission/Checks permissions on every tool invocation before execution runs.IDE bridge
src/bridge/bridgeMain.tsBidirectional communication with VS Code and JetBrains extensions.MCP client
src/services/mcp/Model Context Protocol connection management and tool invocation.Plugin system
src/plugins/ + src/services/plugins/Plugin loading, built-in plugins, and bundled plugin code.Skills
src/skills/Reusable workflow definitions executed through SkillTool.Voice input
src/voice/ + src/services/voice.tsVoice capture and transcription pipeline.Multi-agent
src/coordinator/Sub-agent spawning and team-level orchestration.Memory
src/memdir/Persistent memory directory and memory extraction.Authentication
src/services/oauth/OAuth 2.0 flow, JWT handling, and macOS Keychain integration.Config schemas
src/schemas/Zod schemas (zod/v4 API) for all user, project, and org settings.State management
src/state/AppState store, selectors, and change observers.Context collection
src/context.tsAssembles OS, shell, git, and user context before each query.API call flow
Trace a full round-trip from user input to tool execution:The tool-call loop in
QueryEngine.ts can iterate many times in a single user turn — the LLM keeps requesting tools until it produces a final text response with no tool calls.Key files by size
The largest files contain the most logic and are worth studying first.| File | Lines | What’s inside |
|---|---|---|
src/QueryEngine.ts | ~46K | Streaming responses, tool-call loops, thinking mode, retry logic, token counting, context management |
src/Tool.ts | ~29K | Tool types, buildTool factory, permission models, progress state |
src/commands.ts | ~25K | Command registry, conditional loading per environment |
src/main.tsx | — | CLI parser, startup optimization, parallel prefetch side-effects |
src/context.ts | — | OS, shell, git, and user context assembly |