VS Code Extension Architecture

The VS Code extension (packages/kilo-vscode/) is a client of Kilo CLI runtime. It bundles platform CLI binary, starts one shared editor-owned kilo serve server on demand, and drives that server through generated SDK HTTP calls plus global SSE.

ℹ️Scope

This page covers extension-host ownership, webview routing, Agent Manager, local terminal paths, recovery, bundled resources, and build outputs. It is not full extension feature inventory.

Shared server ownership

CLI Runtime defines shared local-server authentication, directory routing, provider routing, persistence, and SSE contracts. This page starts at VS Code client boundary.

Activation creates one KiloConnectionService. It owns one ServerManager, one active SDK client, and one SSE adapter. ServerManager owns child process lifecycle. This editor-owned child is separate from detached local daemon managed by kilo daemon.

flowchart LR
  subgraph host ["VS Code extension host"]
    consumers["Sidebar, tabs, panels, services"]
    service["KiloConnectionService"]
    manager["ServerManager"]
    sdk["Generated SDK client"]
    sse["SdkSSEAdapter"]
  end

  server["bin/kilo serve --port 0"]
  runtime["Kilo CLI runtime"]

  consumers --> service
  service --> manager --> server
  service --> sdk --> server
  service --> sse -->|/global/event| server
  server --> runtime
AreaBehavior
StartupLazy on client demand; autocomplete prewarm can start server during activation
BinaryUses extension bin/kilo, or bin/kilo.exe on Windows
PortStarts kilo serve --port 0; CLI server prefers 4096, then asks OS for free port
AuthenticationGenerates random 32-byte hex password per spawn and passes it as KILO_SERVER_PASSWORD; username defaults to kilo
ReuseSidebar, editor tabs, panels, Agent Manager, and host services share active server
ExitServerManager clears dead child; connection service clears SDK/SSE state and enters error state
ReplacementLater retry or connection attempt starts replacement server

Shared consumers

Shared service has more consumers than chat tabs:

FamilyConsumers
ChatSidebar provider and editor-tab providers
PanelsSettings, profile and marketplace surfaces, sub-agent viewers, Agent Manager, KiloClaw
DiffDiff Viewer, Diff Virtual, and diff source catalog
Editor assistanceAutocomplete and commit-message generation
IntegrationsBrowser automation MCP registration and KiloClaw bootstrap

New mutable state must account for concurrent consumers and multiple directory contexts on one process.

Webview bridge

Main chat webviews use host-mediated message bridge:

webview vscode.postMessage()
  -> KiloProvider host handler
  -> generated SDK HTTP request
  -> CLI runtime
  -> /global/event SSE
  -> SdkSSEAdapter
  -> KiloConnectionService subscribers
  -> KiloProvider directory/session filtering and stream coalescing
  -> webview postMessage()

Global SSE carries wrapped events for multiple directories. Connection service broadcasts incoming payload plus directory to subscribers. Providers resolve session scope, maintain message-to-session lookup where events omit direct session ID, filter for relevant views, and coalesce high-frequency stream updates before posting UI messages.

Agent Manager

Agent Manager is extension feature, not separate product. It opens as editor tab and manages parallel sessions, optional worktrees, terminals, diffs, setup scripts, and extra editor windows.

AspectSidebarAgent Manager
Primary useOne active chat viewMulti-session orchestration
Git isolationWorkspace root by defaultOptional worktree per session
BackendShared kilo serve processSame shared process
Request routingWorkspace directorySession worktree path passed as SDK directory
CLI instance keyNormalized workspace rootNormalized worktree directory

Agent Manager request path is:

session worktree path -> SDK directory -> CLI directory-routing middleware -> InstanceStore directory key

Agent Manager persists state in .kilo/agent-manager.json and worktrees under .kilo/worktrees/. Startup migration moves Agent Manager-owned data from legacy .kilocode/ paths when target items do not already exist and repairs git worktree refs.

State boundaries

Directory-keyed CLI state is isolated by worktree path. Process-owned state remains shared because all Agent Manager sessions use one CLI process. Snapshot implementation state is directory-keyed, but slow-snapshot prompt guard belongs to shared Snapshot.Service scope. Managed Agent Manager prompts pass snapshotInitialization: "wait" so slow baseline setup waits without interrupting concurrently started sessions.

Terminal surfaces

VS Code extension has two terminal paths:

SurfaceOwnerUse
VS Code integrated terminalVS Code hostShell terminals and setup-script execution surfaced through editor
CLI PTY WebSocket tabAgent Manager and kilo serve serverServer-created PTY session streamed over loopback WebSocket

Agent Manager PTY WebSocket URL uses auth_token=<base64 kilo:password> query mode because browser WebSocket API cannot attach Basic header. Webview CSP permits loopback HTTP and WebSocket origins for active server port. CLI also exposes scope-bound short-lived PTY ticket API as alternate browser WebSocket auth mode.

Config split

Config ownerExamples
VS Code settingskilo-code.new.* extension UI, proxy, autocomplete, and integration settings
CLI configGlobal and project kilo.jsonc, kilo.json, compatible OpenCode files, provider auth, tools, permissions, modes

Extension-specific behavior belongs in VS Code settings. Agent runtime behavior belongs in CLI config so TUI, Console, VS Code, and JetBrains can share it.

Bundled resources

ResourceBehavior
CLI executablePlatform binary under extension bin/; Windows uses kilo.exe
CLI Tree-sitter WASMCopied under bin/tree-sitter; backend spawn sets KILO_TREE_SITTER_WASM_DIR
FFmpeg helperBundled for supported targets for speech capture; capture code also checks system fallback paths
Empty-window cwdUses extension global storage directory when no VS Code workspace folder exists
Empty-window indexingSets KILO_DISABLE_CODEBASE_INDEXING=vscode-no-workspace so CLI reports indexing disabled

Speech-to-text captures audio locally, then sends completed recording through shared editor-owned kilo serve server to authenticated Kilo Gateway transcription path. It is batch transcription, not direct provider streaming.

Recovery

Failure signalResponse
Missing SSE events for 15 secondsSSE adapter aborts attempt and reconnects
SSE reconnectStarts at 250 ms delay and backs off to 5 seconds until stream opens
Health pollEvery 10 seconds, checks /global/health with 3 second timeout; failure forces SSE reconnect
Server exitClears connection state, reports error, and lets later retry or connection attempt spawn replacement
Extension disposalStops polls, disposes SSE, and sends server process group termination with kill fallback

Builds

BuildSourceOutput
Extension hostsrc/extension.tsdist/extension.js
Sidebar and editor chat webviewwebview-ui/src/index.tsxdist/webview.js
Agent Manager webviewwebview-ui/agent-manager/index.tsxdist/agent-manager.js
KiloClaw webviewwebview-ui/kiloclaw/index.tsxdist/kiloclaw.js
Diff Viewer webviewwebview-ui/diff-viewer/index.tsxdist/diff-viewer.js
Diff Virtual webviewwebview-ui/diff-virtual/index.tsxdist/diff-virtual.js
Shared Shiki workersynthetic worker entrydist/shiki-worker.js

Extension host bundle targets Node/CommonJS. Browser webviews and shared worker use esbuild browser bundles. Run bun run typecheck, bun run lint, and targeted unit tests from packages/kilo-vscode/ after changing this area.

Source map

Paths below are relative to Kilo-Org/kilocode.

ConcernSource path
Activationpackages/kilo-vscode/src/extension.ts
Editor-owned server child processpackages/kilo-vscode/src/services/cli-backend/server-manager.ts
Shared SDK and SSE ownershippackages/kilo-vscode/src/services/cli-backend/connection-service.ts
SSE reconnect adapterpackages/kilo-vscode/src/services/cli-backend/sdk-sse-adapter.ts
Agent Managerpackages/kilo-vscode/src/agent-manager/
Build entriespackages/kilo-vscode/esbuild.js