OpenClaw Architecture Explorer
Multi-channel AI gateway with extensible messaging integrations. An AI assistant that runs on your devices, in your channels, with your rules.
System Architecture
Click any component to see details. The system follows a layered architecture: user-facing surfaces connect through messaging channels to a central gateway that orchestrates AI agents.
Message Data Flow
How a user message travels through the system and returns as an AI response.
Inbound: User Message to AI
any channel
Discord, CLI, etc.
session key resolve
auth, rate-limit
system prompt, tools
Gemini, local, etc.
Tool Execution Loop
sandbox gating
execution
agent context
responds
Outbound: AI Response to User
block chunking
connected clients
(Markdown, etc.)
Core Module Reference
The main source directories under src/ and their responsibilities.
CLI
src/cli/program.ts as the root.Commands
Gateway
Agents
Channels
Memory
Plugins
Infra
Routing
Security
Media
Config
~/.openclaw/.Channel Implementations
Each channel lives in its own directory with platform-specific integration code.
Telegram
Discord
Slack
Signal
iMessage
Extensions (38 plugins)
Extensions are workspace packages under extensions/. They extend OpenClaw with additional channels, memory backends, AI tools, and integrations.
Messaging Channels
AI & Agent Tools
Memory & Auth
Technology Stack
TypeScript (ESM)
Primary language. Strict typing, no any. Node 22+ runtime. Bun supported for dev.
Swift / SwiftUI
macOS and iOS native apps. Uses Observation framework for state management.
Kotlin
Android app under apps/android/. Gradle build system.
tsdown
TypeScript bundler for building dist/. Fast, ESM-native.
pnpm (workspaces)
Package manager with workspace support. Monorepo with root + ui + packages + extensions.
Vitest
Testing framework. Multiple configs: unit, e2e, live, extensions, gateway. V8 coverage at 70% threshold.
Oxlint + Oxfmt
Rust-based linter and formatter. Fast, type-aware linting. SwiftLint/SwiftFormat for Swift.
Commander
CLI framework. Program built in src/cli/program.ts with extensive subcommand tree.
Express 5 + WebSockets
Gateway HTTP server with WebSocket support via ws. OpenAI-compatible API layer.
Lit + Vite
Web component framework. Lightweight, standards-based UI under ui/.
Baileys (WhatsApp)
WhatsApp Web protocol library for direct WhatsApp integration.
grammY (Telegram)
Telegram Bot API framework with runner and throttler plugins.
Carbon (Discord)
Discord bot framework. Voice support via @discordjs/voice.
Bolt (Slack)
Official Slack app framework for events, commands, and interactive messages.
Pi Agent (embedded)
AI agent runtime from @mariozechner/pi-*. Powers the core agent loop, coding tools, TUI.
Multi-Provider
Anthropic, OpenAI, Google, Bedrock, Ollama, vLLM, HuggingFace, Together, xAI, and more.
SQLite + sqlite-vec
Vector database for memory. Embeddings stored locally. Hybrid semantic + keyword search.
TypeBox + Zod
Runtime schema validation. TypeBox for tool schemas (JSON Schema), Zod for general validation.
Playwright
Browser automation for agent tools. Headless browsing, screenshots, interaction.
Docker + Fly.io
Containerized deployment. Multiple Dockerfiles: main, sandbox, sandbox-browser.
ACP (Agent Client Protocol)
Standardized protocol for agent communication. SDK at @agentclientprotocol/sdk.
New Contributor Quick Start
Follow these steps to get oriented and productive in the OpenClaw codebase.
Setup & Install
Node 22+ required. Install dependencies with pnpm install. The project uses pnpm workspaces with root + ui + packages + extensions. Bun is also supported for dev.
Read the Key Docs
Start with AGENTS.md (repo guidelines), VISION.md (project direction), CONTRIBUTING.md (PR rules), and SECURITY.md. These define coding style, naming, commit conventions, and what will/won't be merged.
Understand the Entry Points
src/entry.ts is the CLI bootstrap. It calls src/cli/run-main.ts which loads src/cli/program.ts (Commander). The gateway server lives at src/gateway/server.ts. src/index.ts is the library export.
Learn the Core Loop
A message arrives at a channel (src/telegram, src/discord, etc.) → gets routed (src/routing) → hits the gateway (src/gateway/server.ts) → runs through the agent (src/agents/pi-embedded-runner.ts) → calls an LLM provider → streams response back.
Build & Test
Build: pnpm build. Type-check: pnpm tsgo. Lint: pnpm check. Test: pnpm test (parallel vitest). Tests are colocated as *.test.ts files. Coverage target: 70%.
Run in Dev Mode
Run the CLI: pnpm openclaw ... or pnpm dev. Gateway dev mode: pnpm gateway:dev (skips channel startup for faster iteration). Web UI dev: pnpm ui:dev.
Explore a Feature Area
Adding a channel? Look at src/telegram/ or an extension like extensions/matrix/ as templates. Adding a tool? See src/agents/tools/. Adding a plugin? See docs/tools/plugin.md and src/plugins/.
Commit & PR Rules
Use scripts/committer "msg" file... for commits. One PR = one issue. Max ~5,000 changed lines. Format: pnpm format:fix before committing. Pre-commit hooks enforced.
Key Patterns to Know
DI: createDefaultDeps() pattern for dependency injection. Plugins: loaded via jiti, manifest-based. Config: stored at ~/.openclaw/. Sessions: JSONL files per agent. TypeBox: for tool schemas (no Union types). Oxlint: type-aware linting.
What NOT To Do
No @ts-nocheck. No any. No prototype mutation. No editing node_modules. No Carbon dependency updates. Keep files under ~500 LOC. Don't bundle unrelated changes. Don't add skills to core (use ClawHub). Don't add MCP to core (use mcporter).