Skip to main content
This is a read-only reference codebase. There is no build system or test suite to run — the goal is to understand how a production AI coding assistant is built. The source is pure TypeScript running on the Bun runtime with a React + Ink terminal UI.

Orientation

Start with these files before exploring anything else. They form the spine of the entire system.
WhatWhere
CLI entrypointsrc/main.tsx
Core LLM enginesrc/QueryEngine.ts (~46K lines)
Tool definitionssrc/Tool.ts (~29K lines)
Command registrysrc/commands.ts (~25K lines)
Tool registrysrc/tools.ts
Context collectionsrc/context.ts
All tool implementationssrc/tools/ (40 subdirectories)
All command implementationssrc/commands/ (~85 subdirectories + 15 files)

Finding things

How does tool X work?

1

Go to the tool directory

Every tool lives at src/tools/{ToolName}/. For example, src/tools/BashTool/.
2

Read the main implementation

The core logic is in {ToolName}.ts or {ToolName}.tsx inside that directory.
3

Check the UI component

UI.tsx contains the React component that renders the tool’s invocation and result in the terminal.
4

Read the system prompt contribution

prompt.ts defines what this tool adds to the system prompt sent to the LLM.
Example — BashTool:
src/tools/BashTool/
├── BashTool.ts      ← Core execution logic
├── UI.tsx           ← How bash output renders in terminal
├── prompt.ts        ← What the system prompt says about bash
└── index.ts         ← Re-exports BashTool

How does command X work?

Check src/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:
src/main.tsx                    ← CLI parsing, startup optimization
  → src/replLauncher.tsx        ← REPL session start
    → src/QueryEngine.ts        ← Core engine: streaming, tool loops, retries
      → src/services/api/       ← Anthropic SDK client
        → (Anthropic API)       ← HTTP / streaming SSE
      ← Tool use response
      → src/tools/{ToolName}/   ← Tool execution
      ← Tool result
      → (feed back to API)      ← Continue the tool-call loop
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.
FileLinesWhat’s inside
src/QueryEngine.ts~46KStreaming responses, tool-call loops, thinking mode, retry logic, token counting, context management
src/Tool.ts~29KTool types, buildTool factory, permission models, progress state
src/commands.ts~25KCommand registry, conditional loading per environment
src/main.tsxCLI parser, startup optimization, parallel prefetch side-effects
src/context.tsOS, shell, git, and user context assembly

Useful search patterns

Use these ripgrep patterns to find things quickly across the source.
# Find all tool definitions
rg "buildTool\(" src/tools/

# Find all command definitions
rg "satisfies Command" src/commands/

# Find feature flag usage
rg "feature\(" src/

# Find Anthropic-internal gates
rg "USER_TYPE.*ant" src/

# Find all React hooks
rg "^export function use" src/hooks/

# Find all Zod schemas
rg "z\.object\(" src/schemas/

# Find all system prompt contributions
rg "prompt\(" src/tools/*/prompt.ts

# Find permission rule patterns
rg "checkPermissions" src/tools/
Use rg --files-with-matches instead of rg when you only want file paths, not line content. This is useful when you know what you’re looking for but want to scope your reading list first.

Build docs developers (and LLMs) love