OpenClaw Architecture Deep Dive

Not just a chatbot — a multi-agent operating system with hub-and-spoke messaging, self-evolving markdown skills, file-based layered memory, and a separable PI agent runtime. 247K+ stars, 35K+ forks, 13.7K+ community skills.

Core Architecture: Two Layers

OpenClaw is actually two systems:

  1. PI (Personal Intelligence): The lower-level agent runtime — the actual agent framework that handles LLM interaction, tool execution, and the agent loop
  2. OpenClaw: The orchestration and integration layer on top — channel adapters, Gateway, skills, memory, cron

This separation is architecturally significant: PI can be extracted and used independently to build other agent products.

The Agent Loop

Lives in src/agents/pi-embedded-runner/run.ts. Standard while-loop with two notable resilience patterns:

Message arrives from channel adapter
  → PI createAgentSession()
  → while (true):
      1. Call LLM with messages + tools
      2. Execute returned tool calls
      3. Feed results back
      4. Repeat until completion or error
  → Two resilience mechanisms:
      - Context overflow → automatic session compaction
      - Auth error → API key rotation across providers

Event-driven, not polling. The loop only spins up when a message arrives. For autonomous/proactive behavior, a separate cron daemon (src/cron/) handles scheduled tasks — this is what enables the “heartbeat” where OpenClaw acts without user prompting.

Multi-Platform Messaging: Hub-and-Spoke

Gateway (Single Control Plane)

All clients connect via one WebSocket endpoint (ws://127.0.0.1:18789). CLI, web UI, macOS app, iOS/Android, headless nodes — all share the same protocol and declare their role at handshake.

Channel Adapters (src/channels/)

One adapter per platform, each normalizing platform-specific APIs into a standard internal message format:

WhatsApp API  ─→ ┐
Telegram API  ─→ ├─→ [Normalized Message] ─→ Gateway ─→ Agent Runtime
Slack API     ─→ ┤                                         ↓
Discord API   ─→ ┘                                    [Response]
                                                         ↓
                                              Gateway routes to origin

Commercial pattern: Adding a new platform = writing one adapter that conforms to the message contract. Agent core never changes. O(1) agent changes for O(n) platforms.

Self-Evolving Skills

The most architecturally interesting feature. Deceptively simple:

Skills are Directories with Markdown

skills/
├── skill-creator/
│   └── SKILL.md          # Meta-skill: teaches agent how to create new skills
├── web-search/
│   └── SKILL.md          # YAML frontmatter + markdown instructions
├── custom-automation/
│   ├── SKILL.md          # Instructions
│   └── handler.ts        # Optional: code-backed execution

Each SKILL.md has YAML frontmatter (name, description, triggers) + markdown instructions. No compiled code required at minimum — the simplest skill is pure natural language instructions.

How It Works at Runtime

  1. formatSkillsForPrompt scans all installed SKILL.md files
  2. Builds a compact XML skill index
  3. Injects into system prompt
  4. LLM selects skills based on task semantics

The Skill-Creator is a Skill

skills/skill-creator/SKILL.md teaches the agent how to write new SKILL.md files. Nothing mechanically special — same format as every other skill. The agent writes new skills to disk, and they’re available on the next invocation.

For code-backed skills: The LLM generates TypeScript/shell scripts, writes to disk via file operations, then executes them.

Security boundary: Skills don’t grant permissions. If your tool policy blocks exec, a skill requiring shell commands will load but fail at execution time. Skills are instructions, not executable plugins.

Ecosystem Scale

  • 13,700+ skills on ClawHub
  • 35,000+ forks
  • Skill-creator enables non-developers to extend the system via natural language

Memory System (Local-First, File-Based)

Layered Architecture

LayerFileLoaded WhenPurpose
Long-termMEMORY.mdEvery DM session startDurable facts, preferences, decisions
Daily contextmemory/YYYY-MM-DD.mdToday + yesterday auto-loadedRecent context and daily notes
Vector searchSQLite + sqlite-vecOn retrieval querySemantic search over all content

Vector Search (Zero External Dependencies)

Uses SQLite with sqlite-vec extension — no Pinecone, no Qdrant, no external service:

  • Content chunked into ~400-token segments with 80-token overlap
  • Supports BM25 (keyword), vector similarity, and hybrid search
  • QMD (Query-Memory-Document): Runs BM25 + vector channels simultaneously with re-ranking fusion

Compaction Safeguard

Before summarizing a conversation to free context, OpenClaw runs a silent turn reminding the agent to save important unsaved context to memory files first. Prevents information loss during context window management.

Cron-Based Autonomy

The proactive behavior differentiator. A separate cron daemon handles scheduled tasks:

  • Morning briefing aggregation
  • Cross-posting content on schedule
  • Periodic monitoring and alerting
  • Any user-defined recurring task

This makes OpenClaw a proactive assistant, not just a reactive one — a significant UX differentiator.

OpenClaw vs Claude Code

DimensionOpenClawClaude Code
PhilosophyAutonomous general assistantDeveloper augmentation tool
Agent modelMulti-agent native (PI runtime)Single-agent + external orchestration
Model supportAny LLM (BYOK), including local OllamaAnthropic models only
MemoryPersistent across sessions (file-based)Session-scoped (CLAUDE.md for soft persistence)
Extension modelSKILL.md (markdown-first, non-dev friendly)MCP servers (code-first, developer-focused)
Multi-platform50+ channels via adaptersIDE-focused (VS Code, JetBrains, CLI)
AutonomyProactive (cron daemon)Reactive (user-initiated)
StrengthBreadth of integrations, accessibilityDepth of codebase understanding, precision

Key insight: OpenClaw optimizes for breadth and autonomy (many platforms, proactive behavior, non-developer users). Claude Code optimizes for depth and precision (deep repo understanding, multi-file refactoring, developer workflows). They solve fundamentally different problems.

Commercial Patterns to Extract

PatternImplementationApplicable To
Hub-and-spoke GatewaySingle WS endpoint, adapters per platformAny multi-channel AI product
Markdown-first skillsSKILL.md = YAML frontmatter + instructionsLow-code automation platforms
Separable agent runtimePI runtime extracted from orchestrationLicensing the core as SDK
File-based memoryMEMORY.md + daily files + SQLite vectorPortable, inspectable, no DB dependency
Cron autonomyBackground daemon for proactive behaviorDifferentiator vs reactive-only products
Adapter normalizationOne message contract, many platformsScale platform support without touching core

Notable Forks

  • NanoClaw: Security-first fork with mandatory Docker/Apple container isolation (enterprise target)
  • ZeroClaw: Rust rewrite achieving 99% RAM reduction
  • openclaw-mission-control: Multi-agent orchestration dashboard

Sources