docs/developers/architecture.md
Qwen Code is a monorepo that supports an interactive terminal, headless and programmatic execution, the Agent Client Protocol (ACP), a long-running HTTP daemon, web and IDE clients, and messaging-channel adapters. This document maps those surfaces to the packages that implement them and explains the main runtime boundaries.
For detailed daemon internals, start with the
daemon documentation. For HTTP request and event
shapes, see the qwen serve protocol reference.
Qwen Code has two agent execution models:
qwen --acp hosts the agent behind an ACP transport. It
can be driven by an ACP client directly or by qwen serve through the shared
ACP bridge.qwen serve adds an HTTP + Server-Sent Events (SSE) control plane around ACP
execution so multiple clients can use long-lived, workspace-scoped runtimes.
flowchart TB
subgraph surfaces["User and integration surfaces"]
TUI["Interactive TUI / headless CLI"]
PQ["TypeScript SDK process client"]
WEB["Web Shell / shared Web UI"]
IDE["IDE integrations"]
CHANNEL["Messaging channels"]
CUSTOM["Custom daemon clients"]
end
subgraph hosts["Process and transport hosts"]
CLI["CLI host
packages/cli"]
SDK["Daemon client
packages/sdk-typescript"]
SERVE["qwen serve
packages/cli/src/serve"]
BRIDGE["ACP bridge
packages/acp-bridge"]
ACP["qwen --acp child"]
end
subgraph runtime["Agent runtime"]
CORE["Agent orchestration and tools
packages/core"]
end
subgraph external["External systems"]
MODEL["Model providers"]
MCP["MCP servers"]
HOST["Workspace filesystem and processes"]
end
TUI --> CLI
PQ --> CLI
CLI --> CORE
WEB --> SDK
IDE --> SDK
CHANNEL --> SDK
CUSTOM --> SDK
SDK --> SERVE
SERVE --> BRIDGE
BRIDGE --> ACP
ACP --> CORE
CORE --> MODEL
CORE --> MCP
CORE --> HOST
The diagram shows the main production paths. Some adapters also have standalone
modes: for example, qwen channel start uses the ACP bridge without requiring
an HTTP daemon. See the
channel plugin guide for those variants.
| Path | Responsibility |
|---|---|
packages/cli | The qwen executable, argument parsing, configuration assembly, Ink TUI, headless output, ACP entry point, qwen serve, and command-specific adapters. |
packages/core | UI-independent agent orchestration, model-provider integration, prompt and context construction, tool registration and execution, permissions, sessions, memory, telemetry, and shared services. |
packages/acp-bridge | ACP channel lifecycle, session multiplexing, event delivery, permission mediation, process spawning, and the filesystem seam shared by daemon and adapter hosts. |
packages/sdk-typescript | Programmatic process execution through query() plus HTTP/SSE clients and transcript projection for qwen serve. |
packages/webui | Shared React components and the daemon React adapter built on the TypeScript SDK. |
packages/web-shell | The terminal-style browser UI built on packages/webui and the daemon SDK. |
packages/web-templates | Web templates packaged as embeddable JavaScript and CSS strings. |
packages/audio-capture | Native microphone capture for voice input. |
packages/channels | The shared channel runtime and platform adapters for messaging services. |
packages/desktop, packages/vscode-ide-companion, packages/chrome-extension, packages/zed-extension | Product and editor surfaces that adapt Qwen Code to their host environments. |
packages/sdk-java, packages/sdk-python | Language-specific programmatic clients. |
packages/cua-driver, packages/mobile-mcp | Computer-use and mobile-device integrations exposed through MCP-compatible boundaries. |
integration-tests | End-to-end coverage for CLI, interactive, SDK, sandbox, hook, and terminal behavior. |
docs and docs-site | User, developer, protocol, and design documentation plus the documentation site. |
scripts | Build, packaging, release, validation, and repository-maintenance automation. |
Most code lives in npm workspaces under packages/. A package should depend on
another package through its declared public exports rather than through a
relative path into that package's source tree.
packages/cli owns the executable and chooses the runtime mode from command-line
arguments. It loads user and workspace settings, constructs the core
configuration, enters the requested sandbox when necessary, and then starts one
of the interactive, headless, ACP, daemon, channel, or maintenance flows.
Presentation remains outside the core runtime:
packages/webui adapts daemon state to React providers and hooks;packages/web-shell provides the browser terminal experience;packages/core owns the agent loop. It constructs model requests, maintains
conversation context, dispatches tool calls, applies permission policy, and
returns structured events and results to the active host. Built-in tools cover
file operations, shell execution, search, planning, web access, memory, skills,
and subagents. MCP extends the tool and resource surface without coupling the
runtime to a specific integration.
The core package does not decide how results are displayed or how a remote client transports them. Those decisions belong to the CLI, bridge, SDK, and UI layers.
packages/acp-bridge connects a host process to an ACP agent runtime. Its main
responsibilities are:
The bridge can use a real qwen --acp child process in production or an
in-memory channel in tests. See the
@qwen-code/acp-bridge README for its
public entry points.
The TypeScript SDK exposes two client styles:
query() starts and controls a Qwen Code process for programmatic local use;qwen serve over HTTP and SSE.packages/webui builds a React state layer on the daemon client, and
packages/web-shell builds the browser UI on that state layer. Other clients,
including IDE integrations and daemon-managed channels, reuse the same SDK and
event contracts instead of importing server implementation code.
qwen serve.qwen --acp child.With multi-workspace sessions enabled, each live workspace runtime owns its own bridge and ACP child. Filesystem access, environment overlays, MCP transports, sessions, and failure handling remain scoped to that resolved runtime. The daemon architecture documents the process topology, trust boundaries, event replay, and lifecycle in detail.
Qwen Code can be extended at several layers:
Keep platform-specific concerns in adapters. Shared agent behavior belongs in the core runtime, while transport and wire behavior belongs in the ACP bridge, SDK, or daemon host.
The CLI assembles effective configuration from command-line arguments, environment variables, user settings, workspace settings, and defaults before constructing the runtime. The core receives the resolved configuration rather than reading presentation-specific input. See Settings for the supported settings and their scopes.
Direct sessions persist their history and metadata through shared core services. In daemon mode, the daemon resolves the owning workspace and exposes workspace- and session-scoped operations to clients; the ACP child remains the owner of live agent execution.