Back to Kilocode

Architecture Overview

packages/kilo-docs/pages/contributing/architecture/index.md

7.3.4014.7 KB
Original Source

Architecture Overview

This page maps Kilo Code's repository-defined architecture. It introduces the local runtime, editor clients, cloud service boundaries, and hosted execution products before the subsystem pages add implementation detail.

{% callout type="info" title="Scope" %} Use these pages for stable system boundaries and contributor-wide contracts. Source code remains the reference for feature-level implementation details. Static source shows code paths and deployable surfaces, not production enablement, traffic, retention, or vendor configuration. {% /callout %}

How to read these pages

Choose the path closest to the change you are making:

Contributor pathSuggested order
Local CLI or editor clientArchitecture Overview -> CLI Runtime -> VS Code Extension or JetBrains Plugin
Hosted platform or automationArchitecture Overview -> Cloud Platform -> Automation Services
Security reviewArchitecture Overview -> Cloud Platform -> Cloud Security
Architecture-facing implementationRelevant architecture page -> Development Patterns
CLI config ownership or key changeCLI Runtime -> CLI Config Schema -> Development Patterns

Repository boundaries

Architecture pages cross two repositories:

RepositoryContents
Kilo‑Org/kilocodeKilo CLI runtime, local daemon, Kilo Console, VS Code extension, JetBrains plugin, JavaScript SDK, codebase indexing, Kilo Gateway client, telemetry, docs, and shared UI packages
Kilo‑Org/cloudWeb control plane, Kilo Gateway routes, Cloud Agent session runtime, automation, generated-application preview and deployment services, KiloClaw, Gas Town, billing, and supporting Workers

Three architecture layers

LayerResponsibilityTypical boundaries
Local runtime and clientsRuns local coding sessions and connects editor surfaces to one local agent engineKilo CLI runtime, kilo serve server, local daemon, Kilo Console, VS Code extension, JetBrains plugin
Kilo Cloud shared servicesHandles hosted identity, authorization, model routing, billing, orchestration, and shared product servicesWeb control plane, Kilo Gateway, Workers, queues, Durable Objects, persistence
Hosted product runtimes and automationRuns scoped cloud work for coding, app generation, assistants, security analysis, and multi-agent orchestrationCloud Agent, Automation Services, App Builder, Security Agent, KiloClaw, Gas Town, Wasteland

Local execution and hosted execution are separate boundaries. Editor clients use a local kilo serve server. Hosted automation can launch Cloud Agent execution sessions when cloud coding work is required.

Terms used throughout

TermMeaning
Kilo CodeUmbrella product across local clients, Kilo CLI runtime, and Kilo Cloud services
Kilo CLI runtimeLocal agent engine in packages/opencode/; owns tools, sessions, config, persistence, and provider routing
kilo serve serverLocal HTTP and SSE process used by editor clients and Kilo Console; selected browser-oriented paths also use WebSocket
Local daemonDetached reusable kilo serve server managed by kilo daemon commands
Directory contextNormalized local filesystem directory used to select local runtime state
Local runtime instanceDirectory-keyed runtime context inside one Kilo CLI process
Local routing workspaceOptional routing context that can resolve to a local directory or remote target
Worktree directoryAlternate git worktree path used as a directory context for isolated concurrent work
Web control planeHosted Kilo Cloud application layer for identity, organization authorization, billing, product configuration, and API orchestration
Kilo GatewayFirst-party hosted model-routing boundary
Cloud AgentHosted coding-session capability. A Cloud Agent execution session is one hosted run; current session runtime implementation lives in services/cloud-agent-next/.

Core execution spine

The three layers appear in two primary execution shapes: local client requests and hosted cloud work.

mermaid
flowchart LR
  subgraph clients ["Local clients"]
    tui["Kilo CLI TUI"]
    run["kilo run"]
    console["Kilo Console"]
    editors["VS Code and JetBrains"]
  end

  subgraph local ["Local Kilo CLI boundary"]
    daemon["Local daemon manager"]
    server["kilo serve server"]
    runtime["Kilo CLI runtime"]
    router["Provider router"]
  end

  subgraph cloud ["Kilo Cloud shared services"]
    web["Web control plane"]
    workers["Automation Workers, queues, and Durable Objects"]
    gateway["Kilo Gateway"]
    agent["Cloud Agent"]
  end

  trigger["Hosted product or automation trigger"]
  repos["Repositories"]
  models["Model providers and external gateways"]

  tui -->|"daemon attach when available"| server
  tui -->|"worker-backed fallback"| runtime
  run -->|"attach when available"| server
  run -->|"embedded fallback"| runtime
  console -->|"starts or reuses"| daemon
  daemon -->|"owns detached child"| server
  editors -->|"start editor-owned child over HTTP + SSE"| server
  server --> runtime --> router
  router -->|"direct provider"| models
  router --> gateway --> models

  trigger --> web
  trigger --> workers
  web --> workers --> agent
  web --> agent
  agent --> repos
  agent --> models

Two execution paths

PathStarts fromRuns inWhat to remember
Local codingKilo CLI, Kilo Console, VS Code, or JetBrainsKilo CLI runtime on developer machineEditor clients talk to local kilo serve server. Local runtime owns coding session and sends model requests directly or through Kilo Gateway.
Hosted workWebhook, source-control event, command, schedule, or hosted productKilo Cloud services; Cloud Agent when coding is requiredCloud services coordinate work. Only flows that need repository changes launch Cloud Agent execution session.

This distinction is central: using editor does not move coding session into Cloud Agent. Cloud services also route model requests, deliver chat events, dispatch notifications, serve generated applications, and coordinate adjacent hosted boundaries without launching Cloud Agent.

Adjacent hosted boundaries

The core execution spine is not the full cloud product catalog. These service families and hosted runtimes attach to it for specific product flows:

mermaid
flowchart LR
  web["Web control plane"]
  workers["Automation Services"]
  agent["Cloud Agent"]
  builder["App Builder"]
  preview["Generated-application preview"]
  deploy["Generated-application deployment"]
  security["Security Agent"]
  chat["Kilo Chat, events, and notifications"]
  claw["KiloClaw"]
  town["Gas Town"]
  wasteland["Wasteland"]

  web --> workers --> agent
  web --> builder --> agent
  builder --> preview
  builder --> deploy
  web --> security
  security -->|"optional deep analysis"| agent
  web --> claw
  chat --> claw
  web --> town --> wasteland
BoundaryRoleTopology or workflowSecurity review
Automation ServicesTurns commands, source-control events, labels, webhooks, and schedules into scoped workAutomation ServicesTrust boundaries
App BuilderCoordinates generated-application coding, preview, build, and deployment boundariesCloud PlatformPreview and deployment
Security AgentSyncs findings and analyzes risk; selected deep analysis can launch Cloud AgentCloud PlatformSync and cleanup
KiloClawCoordinates owner-scoped hosted assistant runtimesCloud PlatformKiloClaw ingress
Gas Town and WastelandCoordinate multi-agent repository work and collaborative commons pathsCloud PlatformTrust boundaries

Local entry points and clients

These local surfaces live in Kilo-Org/kilocode. Package paths below are relative to that repository root.

SurfacePackage in Kilo-Org/kilocodeRuntime model
Kilo CLI TUIpackages/opencode/Interactive local client with daemon attach and worker-backed fallback paths
kilo runpackages/opencode/Headless prompt execution through explicit attach, daemon attach, or embedded fallback
kilo servepackages/opencode/Local HTTP + SSE server for local clients
Kilo Consolepackages/kilo-console/{% linebreak /%}packages/opencode/Browser UI served at /console by a started or reused local daemon
VS Code extensionpackages/kilo-vscode/Extension host starts one shared editor-owned kilo serve server and routes webviews through HTTP + global SSE; SDK directory selects local runtime instance
JetBrains pluginpackages/kilo-jetbrains/Split-mode Swing plugin; backend module starts one editor-owned kilo serve server and caches workspace clients by directory

Cloud service families

Hosted service families live in Kilo-Org/cloud. Paths below are relative to that repository root unless another repository is named.

BoundaryPrimary source pathsRole
Kilo Cloudapps/web/{% linebreak /%}services/Hosted platform repository for identity, billing, routing, product configuration, automation, and scoped execution services
Web control planeapps/web/Hosted application layer for authorization, configuration, and API orchestration
Kilo Gatewayapps/web/src/app/api/gateway/{% linebreak /%}apps/web/src/lib/ai-gateway/{% linebreak /%}Local integration: Kilo-Org/kilocode/packages/kilo-gateway/First-party model-routing boundary and local client integration
Cloud Agentservices/cloud-agent-next/Hosted coding-session capability with policy-selected sandbox allocation
Automation Servicesservices/code-review-infra/{% linebreak /%}services/auto-triage-infra/{% linebreak /%}services/auto-fix-infra/{% linebreak /%}services/security-auto-analysis/{% linebreak /%}services/security-sync/{% linebreak /%}services/webhook-agent-ingest/Trigger-driven review, triage, fix, security, and configured webhook flows
Adjacent hosted boundariesservices/app-builder/{% linebreak /%}services/kiloclaw/{% linebreak /%}services/gastown/{% linebreak /%}services/wasteland/{% linebreak /%}Supporting servicesApp Builder, KiloClaw, Gas Town, Wasteland, chat, notifications, and supporting services

Supporting packages

These supporting packages also live in Kilo-Org/kilocode. Package paths below are relative to that repository root.

Package in Kilo-Org/kilocodeRole
packages/kilo-indexing/Per-directory asynchronous codebase indexing engine behind Kilo CLI bridge
packages/sdk/js/Generated JavaScript client and handwritten wrapper for local server APIs
packages/kilo-gateway/Local Kilo Gateway client integration used by Kilo CLI runtime
packages/kilo-console/Browser UI served by local daemon at /console

Architecture pages

PageWhat it covers
CLI RuntimeLocal execution modes, daemon, server authentication, routing, persistence, snapshots, SDK, config, SSE, Kilo Console, and indexing
VS Code ExtensionShared local kilo serve ownership, webview bridge, Agent Manager, PTYs, recovery, bundled resources, and build outputs
JetBrains PluginSplit-mode modules, RPC, bundled local kilo serve lifecycle, Kotlin SDK, recovery, and remote-development constraints
Cloud PlatformHosted service inventory, Cloud Agent topology, shared cloud boundaries, and adjacent hosted runtimes
Automation ServicesTrigger-driven Workers, queues, callbacks, ownership, and scoped execution paths
Cloud SecurityCloud trust boundaries, data flows, persistence, isolation, controls, and third-party categories

Development pages

After system-boundary pages, continue with Development Patterns for implementation rules. Use CLI Config Schema when changing config keys or editor-facing schema publication.

PageWhat it covers
Development PatternsCode-ownership decisions, shared-file seams, SDK generation, validation guards, and fork maintenance
CLI Config SchemaSeparate runtime-loading and editor-validation paths for cross-repository config contract