# qwenlm/qwen-code architecture

> Architecture diagram of the GitHub repository qwenlm/qwen-code, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/qwenlm/qwen-code
- Repository: https://github.com/qwenlm/qwen-code

## Overview

Qwen Code is an AI coding agent whose main workflow begins with a developer request, enters a CLI or another supported surface, runs an agent session, invokes tools and model providers, and returns streamed results while maintaining session state. The repository also supports MCP, skills, memory, browser automation, channels, ACP daemon clients, web tasks, extensions, and live audio. Several subsystem links are inferred from documented capabilities and tree structure; sampled source most directly confirms model streaming, storage, history, task polling, OAuth persistence, compaction, and audio playback.

Main entry points: [`packages/cli/src/acp-integration/session/Session.ts`](https://github.com/qwenlm/qwen-code/blob/main/packages/cli/src/acp-integration/session/Session.ts) (Agent Session), [`packages/cli/src/cli.ts`](https://github.com/qwenlm/qwen-code/blob/main/packages/cli/src/cli.ts) (Terminal CLI), [`packages/core/src/core/baseLlmClient.ts`](https://github.com/qwenlm/qwen-code/blob/main/packages/core/src/core/baseLlmClient.ts) (LLM Client), [`packages/cli/src/commands/channel/runtime.ts`](https://github.com/qwenlm/qwen-code/blob/main/packages/cli/src/commands/channel/runtime.ts) (Channel Runtime)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User Interfaces"]
  node_terminal_cli["Terminal CLI<br/>[cli.ts]"]
  node_web_shell["Web Shell"]
  node_channel_runtime["Channel Runtime<br/>[runtime.ts]"]
end

subgraph group_agent["Agent Runtime"]
  node_agent_session["Agent Session<br/>[Session.ts]"]
  node_tool_runtime["Tool Runtime"]
  node_skills_memory["Skills Memory"]
  node_mcp_runtime["MCP Runtime<br/>[mcp.ts]"]
  node_history_manager["History Manager"]
end

subgraph group_models["Model Access"]
  node_base_llm["LLM Client<br/>[baseLlmClient.ts]"]
  node_openai_pipeline["OpenAI Pipeline<br/>[pipeline.ts]"]
  node_responses_pipeline["Responses Pipeline"]
end

subgraph group_state["State and Security"]
  node_session_records[("Session Records")]
  node_session_reader["Session Reader"]
  node_config_storage["Config Storage<br/>[storage.ts]"]
  node_oauth_storage[("OAuth Tokens")]
end

subgraph group_integrations["External Integrations"]
  node_acp_bridge["ACP Bridge<br/>[bridge.ts]"]
  node_browser_automation["Browser Automation<br/>[runtime.ts]"]
  node_extensions["Extensions Manager<br/>[extensions.tsx]"]
  node_live_audio["Live Audio<br/>[audio-engine.ts]"]
end

node_developer(("Developer"))
node_model_providers["Model Providers"]
node_chat_platforms["Chat Platforms"]
node_browser["Managed Browser"]
node_daemon_service["Daemon Service"]
node_audio_devices["Audio Devices"]

node_developer -->|"submits request"| node_terminal_cli
node_terminal_cli -->|"starts session"| node_agent_session
node_web_shell -->|"polls tasks"| node_daemon_service
node_daemon_service -->|"controls session"| node_agent_session
node_channel_runtime -.->|"connects channels"| node_chat_platforms
node_channel_runtime -->|"routes messages"| node_agent_session
node_acp_bridge -->|"bridges sessions"| node_agent_session
node_agent_session -->|"requests completion"| node_base_llm
node_agent_session -->|"invokes tools"| node_tool_runtime
node_agent_session -->|"loads capabilities"| node_skills_memory
node_agent_session -->|"dispatches MCP"| node_mcp_runtime
node_agent_session -->|"updates history"| node_history_manager
node_agent_session -->|"persists session"| node_session_records
node_history_manager -->|"loads history"| node_session_reader
node_base_llm -->|"routes requests"| node_openai_pipeline
node_base_llm -->|"routes requests"| node_responses_pipeline
node_openai_pipeline -->|"streams completions"| node_model_providers
node_responses_pipeline -->|"streams responses"| node_model_providers
node_mcp_runtime -->|"reads tokens"| node_oauth_storage
node_terminal_cli -->|"reads configuration"| node_config_storage
node_browser_automation -.->|"drives browser"| node_browser
node_live_audio -.->|"plays audio"| node_audio_devices
node_extensions -.->|"adds extensions"| node_agent_session

click node_terminal_cli "https://github.com/qwenlm/qwen-code/blob/main/packages/cli/src/cli.ts"
click node_web_shell "https://github.com/qwenlm/qwen-code/blob/main/packages/web-shell/client/hooks/useBackgroundTasks.ts"
click node_channel_runtime "https://github.com/qwenlm/qwen-code/blob/main/packages/cli/src/commands/channel/runtime.ts"
click node_agent_session "https://github.com/qwenlm/qwen-code/blob/main/packages/cli/src/acp-integration/session/Session.ts"
click node_tool_runtime "https://github.com/qwenlm/qwen-code/blob/main/packages/cli/src/acp-integration/session/tool-call-preparation-tracker.ts"
click node_skills_memory "https://github.com/qwenlm/qwen-code/blob/main/packages/cli/src/acp-integration/skill-management.ts"
click node_mcp_runtime "https://github.com/qwenlm/qwen-code/blob/main/packages/cli/src/commands/mcp.ts"
click node_history_manager "https://github.com/qwenlm/qwen-code/blob/main/packages/cli/src/ui/hooks/useHistoryManager.ts"
click node_base_llm "https://github.com/qwenlm/qwen-code/blob/main/packages/core/src/core/baseLlmClient.ts"
click node_openai_pipeline "https://github.com/qwenlm/qwen-code/blob/main/packages/core/src/core/openaiContentGenerator/pipeline.ts"
click node_responses_pipeline "https://github.com/qwenlm/qwen-code/blob/main/packages/core/src/core/openaiResponsesContentGenerator/responses-pipeline.ts"
click node_session_records "https://github.com/qwenlm/qwen-code/blob/main/packages/cli/src/acp-integration/session-model-persistence.ts"
click node_session_reader "https://github.com/qwenlm/qwen-code/blob/main/packages/core/src/utils/sessionStorageUtils.ts"
click node_config_storage "https://github.com/qwenlm/qwen-code/blob/main/packages/core/src/config/storage.ts"
click node_oauth_storage "https://github.com/qwenlm/qwen-code/blob/main/packages/core/src/mcp/oauth-token-storage.ts"
click node_acp_bridge "https://github.com/qwenlm/qwen-code/blob/main/packages/acp-bridge/src/bridge.ts"
click node_browser_automation "https://github.com/qwenlm/qwen-code/blob/main/packages/browser-use/src/runtime.ts"
click node_extensions "https://github.com/qwenlm/qwen-code/blob/main/packages/cli/src/commands/extensions.tsx"
click node_live_audio "https://github.com/qwenlm/qwen-code/blob/main/packages/live-host/src/preload/audio-engine.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_terminal_cli,node_web_shell,node_channel_runtime,node_browser toneBlue
class node_agent_session,node_tool_runtime,node_skills_memory,node_mcp_runtime,node_history_manager toneAmber
class node_base_llm,node_openai_pipeline,node_responses_pipeline toneMint
class node_session_records,node_session_reader,node_config_storage,node_oauth_storage toneRose
class node_acp_bridge,node_browser_automation,node_extensions,node_live_audio,node_developer,node_model_providers,node_chat_platforms,node_daemon_service,node_audio_devices toneIndigo
```

## Components

### User Interfaces

- [Terminal CLI](https://github.com/qwenlm/qwen-code/blob/main/packages/cli/src/cli.ts): `packages/cli/src/cli.ts`
- [Web Shell](https://github.com/qwenlm/qwen-code/blob/main/packages/web-shell/client/hooks/useBackgroundTasks.ts): `packages/web-shell/client/hooks/useBackgroundTasks.ts`
- [Channel Runtime](https://github.com/qwenlm/qwen-code/blob/main/packages/cli/src/commands/channel/runtime.ts): `packages/cli/src/commands/channel/runtime.ts`

### Agent Runtime

- [Agent Session](https://github.com/qwenlm/qwen-code/blob/main/packages/cli/src/acp-integration/session/Session.ts): `packages/cli/src/acp-integration/session/Session.ts`
- [Tool Runtime](https://github.com/qwenlm/qwen-code/blob/main/packages/cli/src/acp-integration/session/tool-call-preparation-tracker.ts): `packages/cli/src/acp-integration/session/tool-call-preparation-tracker.ts`
- [Skills Memory](https://github.com/qwenlm/qwen-code/blob/main/packages/cli/src/acp-integration/skill-management.ts): `packages/cli/src/acp-integration/skill-management.ts`
- [MCP Runtime](https://github.com/qwenlm/qwen-code/blob/main/packages/cli/src/commands/mcp.ts): `packages/cli/src/commands/mcp.ts`
- [History Manager](https://github.com/qwenlm/qwen-code/blob/main/packages/cli/src/ui/hooks/useHistoryManager.ts): `packages/cli/src/ui/hooks/useHistoryManager.ts`

### Model Access

- [LLM Client](https://github.com/qwenlm/qwen-code/blob/main/packages/core/src/core/baseLlmClient.ts): `packages/core/src/core/baseLlmClient.ts`
- [OpenAI Pipeline](https://github.com/qwenlm/qwen-code/blob/main/packages/core/src/core/openaiContentGenerator/pipeline.ts): `packages/core/src/core/openaiContentGenerator/pipeline.ts`
- [Responses Pipeline](https://github.com/qwenlm/qwen-code/blob/main/packages/core/src/core/openaiResponsesContentGenerator/responses-pipeline.ts): `packages/core/src/core/openaiResponsesContentGenerator/responses-pipeline.ts`

### State and Security

- [Session Records](https://github.com/qwenlm/qwen-code/blob/main/packages/cli/src/acp-integration/session-model-persistence.ts): `packages/cli/src/acp-integration/session-model-persistence.ts`
- [Session Reader](https://github.com/qwenlm/qwen-code/blob/main/packages/core/src/utils/sessionStorageUtils.ts): `packages/core/src/utils/sessionStorageUtils.ts`
- [Config Storage](https://github.com/qwenlm/qwen-code/blob/main/packages/core/src/config/storage.ts): `packages/core/src/config/storage.ts`
- [OAuth Tokens](https://github.com/qwenlm/qwen-code/blob/main/packages/core/src/mcp/oauth-token-storage.ts): `packages/core/src/mcp/oauth-token-storage.ts`

### External Integrations

- [ACP Bridge](https://github.com/qwenlm/qwen-code/blob/main/packages/acp-bridge/src/bridge.ts): `packages/acp-bridge/src/bridge.ts`
- [Browser Automation](https://github.com/qwenlm/qwen-code/blob/main/packages/browser-use/src/runtime.ts): `packages/browser-use/src/runtime.ts`
- [Extensions Manager](https://github.com/qwenlm/qwen-code/blob/main/packages/cli/src/commands/extensions.tsx): `packages/cli/src/commands/extensions.tsx`
- [Live Audio](https://github.com/qwenlm/qwen-code/blob/main/packages/live-host/src/preload/audio-engine.ts): `packages/live-host/src/preload/audio-engine.ts`

### Other components

- **Developer**
- **Model Providers**
- **Chat Platforms**
- **Managed Browser**
- **Daemon Service**
- **Audio Devices**

## Connections

- Developer → Terminal CLI: submits request
- Terminal CLI → Agent Session: starts session
- Web Shell → Daemon Service: polls tasks
- Daemon Service → Agent Session: controls session
- Channel Runtime → Chat Platforms: connects channels
- Channel Runtime → Agent Session: routes messages
- ACP Bridge → Agent Session: bridges sessions
- Agent Session → LLM Client: requests completion
- Agent Session → Tool Runtime: invokes tools
- Agent Session → Skills Memory: loads capabilities
- Agent Session → MCP Runtime: dispatches MCP
- Agent Session → History Manager: updates history
- Agent Session → Session Records: persists session
- History Manager → Session Reader: loads history
- LLM Client → OpenAI Pipeline: routes requests
- LLM Client → Responses Pipeline: routes requests
- OpenAI Pipeline → Model Providers: streams completions
- Responses Pipeline → Model Providers: streams responses
- MCP Runtime → OAuth Tokens: reads tokens
- Terminal CLI → Config Storage: reads configuration
- Browser Automation → Managed Browser: drives browser
- Live Audio → Audio Devices: plays audio
- Extensions Manager → Agent Session: adds extensions
