> For the complete documentation index, see [llms.txt](https://www.openclawbook.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.openclawbook.xyz/en/ch43-engineering-panorama/43.2-scale-and-subsystem-map.md). Agents can also search and read this documentation through its [MCP server](https://www.openclawbook.xyz/~gitbook/mcp).

# 43.2 Scale and Subsystem Map

> **Generated by**: Claude Opus 5 (claude-opus-5\[1m]) **Token usage**: Input \~180,000 tokens, Output \~10,000 tokens (this section) **Source baseline**: `v2026.3.9` (`v2026.3.8-170-g665f67726`)

***

Before talking about architecture, talk about size — because **size is itself an architectural constraint**. A design that's elegant at 5,000 lines collapses at 500,000. Many of OpenClaw's apparently over-engineered decisions only make sense once you accept its scale.

## 43.2.1 Six Numbers

| Metric                                       |                                     Value |
| -------------------------------------------- | ----------------------------------------: |
| TypeScript in `src/` (excluding `*.test.ts`) |                         **507,227 lines** |
| Test files under `src/`                      |                                 **1,935** |
| Git commits                                  |                                **18,005** |
| `extensions/` packages                       |                                    **40** |
| Bundled `skills/`                            |                                    **52** |
| Native apps                                  | macOS / iOS / Android (`apps/`, \~1.7 GB) |

Versioning is **CalVer** (`vYYYY.M.D`, e.g. `v2026.3.9`), published on three npm dist-tags: stable / beta / dev.

> **Sidebar: CalVer (Calendar Versioning)** Numbering by date rather than major.minor.patch — `2026.3.9` means released March 9, 2026. It suits projects that are **continuously evolving with no stable API promise**: users care *how old is my version*, not *will this upgrade break me*. Libraries usually want SemVer because downstream needs the number to decide whether upgrading is safe. Choosing CalVer is effectively a declaration: **this is an application, not a library.**

The **1,935 test files** deserve their own note. They live alongside the source (`foo.ts` sits next to `foo.test.ts`), and their names are absurdly long. For example:

```
auth-profiles.resolve-auth-profile-order.does-not-prioritize-lastgood-round-robin-ordering.test.ts
```

That isn't sloppy naming — it's deliberate: **the filename is the behavioral spec.** When you hit a defensive branch in the source you don't understand, the fastest move isn't reading the implementation, it's `ls`-ing the sibling `.test.ts` files and reading the *reason that branch exists* straight out of a filename. §43.4 folds this into the recommended reading paths.

## 43.2.2 The Subsystem Map

Real sizes of each subsystem under `src/` (excluding tests), sorted by line count. Treat this table as a **reverse index for this book** — find the code you want to read, get the chapter:

| Subsystem         |  Lines | Responsibility                                             | Chapters       |
| ----------------- | -----: | ---------------------------------------------------------- | -------------- |
| `src/agents/`     | 87,781 | Embedded pi runtime, tools, sandbox, auth-profile rotation | 15–17, 22      |
| `src/gateway/`    | 43,673 | WS control plane: protocol, server, RPC methods            | 11–12          |
| `src/commands/`   | 42,119 | CLI subcommands + chat slash-command implementations       | 33             |
| `src/infra/`      | 39,455 | Infrastructure (process, locks, updates, diagnostics…)     | 34, 38         |
| `src/auto-reply/` | 34,520 | Inbound → reply pipeline (queueing, commands, heartbeat)   | 13–14          |
| `src/cli/`        | 27,311 | CLI skeleton and startup routing                           | 33             |
| `src/config/`     | 26,565 | Config loading, validation, hot reload, migration          | 31             |
| `src/discord/`    | 24,294 | Discord adaptation (largest single channel)                | 20             |
| `src/telegram/`   | 17,634 | Telegram adaptation                                        | 20             |
| `src/browser/`    | 15,505 | Built-in browser control (CDP + Playwright)                | 24             |
| `src/channels/`   | 13,590 | Channel abstraction and registries                         | 19             |
| `src/memory/`     | 10,987 | Memory and retrieval                                       | 28             |
| `src/slack/`      | 10,762 | Slack adaptation                                           | 20             |
| `src/secrets/`    |  9,261 | Secret references and redaction                            | 32             |
| `src/cron/`       |  8,972 | Scheduled jobs and webhooks                                | 26             |
| `src/plugins/`    |  8,449 | Plugin loader                                              | 21, 30         |
| `src/security/`   |  7,587 | Security audit and trust boundaries                        | 32             |
| `src/acp/`        |  7,101 | Agent Communication Protocol                               | 40             |
| `src/plugin-sdk/` |  6,344 | Plugin API surface                                         | 21             |
| `src/tui/`        |  5,580 | Terminal UI                                                | 41             |
| `src/daemon/`     |  4,377 | Cross-platform service installation                        | 37, Appendix F |
| `src/node-host/`  |  2,966 | Device node runtime                                        | 27, Appendix F |

(`src/` has 52 subdirectories total; this lists the major ones.)

Three things fall out of this table, and all three are counterintuitive:

**First, channel adaptation is the real cost center.** Discord + Telegram + Slack + Signal + iMessage + LINE + Web add up to roughly 75,000 lines — **more than the Gateway itself.** That isn't a design failure; it's the necessary price of fidelity-first. OpenClaw refuses to flatten every platform into one unified message model, and what it buys is the ability to actually use forum topics, native slash commands, and draft streaming. The bill arrives in §45.2.

**Second, inside `src/agents/`'s 87,781 lines, the agent loop is a small fraction.** As established, the core comes from pi. Those lines are mostly operations: auth-profile rotation, sandboxing, the tool policy pipeline, context-compaction safeguards, subagents.

**Third, infrastructure (`infra` + `config` + `cli` + `secrets`) exceeds 100,000 lines combined** — larger than the Gateway. Software that *runs on the user's machine* faces environmental variance far beyond server-side software: different OSes, different Node version managers, different proxy settings, different certificate chains. This code isn't glamorous, but it decides whether the software can actually be installed on someone else's computer.

## 43.2.3 Beyond `src/`: Three More Dimensions

**`extensions/` — 40 workspace packages**

```
acpx  bluebubbles  copilot-proxy  device-pair  diagnostics-otel  diffs
discord  feishu  google-gemini-cli-auth  googlechat  imessage  irc
line  llm-task  lobster  matrix  mattermost  memory-core  memory-lancedb
minimax-portal-auth  msteams  nextcloud-talk  nostr  open-prose
phone-control  qwen-portal-auth  shared  signal  slack  synology-chat
talk-voice  telegram  test-utils  thread-ownership  tlon  twitch
voice-call  whatsapp  zalo  zalouser
```

Four groups by type:

* **Channels**: matrix, msteams, feishu, googlechat, nostr, zalo, twitch, irc, tlon, voice-call…
* **Memory**: memory-core, memory-lancedb
* **Auth**: qwen-portal-auth, minimax-portal-auth, google-gemini-cli-auth, copilot-proxy
* **Tools**: llm-task, lobster, phone-control, diffs, open-prose…

Note that `discord` / `telegram` / `slack` / `whatsapp` / `signal` / `imessage` / `line` appear in **both** `src/` and `extensions/`. That's not duplication — it's the soft line between built-in and plugin that Chapter 21 covers: `src/` holds the implementation body, `extensions/` holds a thin shell wrapping it in the plugin contract.

**`skills/` — 52 bundled skills**

1password, apple-notes, bear-notes, camsnap, gh-issues, obsidian, peekaboo, spotify-player, things-mac, tmux, weather… all in Markdown knowledge-file form, not executable code. Chapter 29 details this.

**`apps/` — \~1.7 GB of native apps**

A macOS menu-bar app, iOS and Android node apps (Swift / Kotlin), plus a standalone Swift package `Swabble/` providing voice wake. This axis turns phone cameras, Mac screen recording, and device location into agent-callable capabilities. Chapter 36 details this.

## 43.2.4 Tech Stack at a Glance

| Dimension          | Choice                                                       |
| ------------------ | ------------------------------------------------------------ |
| Language / modules | TypeScript, all ESM                                          |
| Runtime            | Node 22+ and Bun (dual runtime)                              |
| Package manager    | pnpm workspace (monorepo)                                    |
| Testing            | Vitest, 70% coverage gate                                    |
| Lint / format      | Oxlint + Oxfmt (Rust-based toolchain)                        |
| Type schemas       | TypeBox (protocol) + Zod (config)                            |
| Build              | tsdown                                                       |
| Release            | CalVer + three npm channels; macOS ships via Sparkle appcast |

Picking Oxlint/Oxfmt over ESLint/Prettier is worth calling out: at 500,000 lines, a Rust-implemented linter compresses a full check from minutes to seconds. **Toolchain speed is a real architectural decision in a large repo** — a check so slow that nobody runs it may as well not exist.

There's also an unwritten discipline: **target under 700 lines per file** (a guideline, not a hard rule). That explains OpenClaw's enormous number of small files and deep directory nesting — it organizes complexity through **directory structure** rather than chapter-comments inside large files. The cost is frequent jumping on a first read; the benefit is that every file fits inside a single span of attention.

***

## Section Summary

1. OpenClaw is **507,227 lines of TypeScript + 1,935 test files + 18,005 commits**. Test filenames are deliberately written as behavioral specs and are the fastest way to answer "why does this branch exist?"
2. The subsystem map reveals three counterintuitive facts: **channel adaptation (\~75k lines) is larger than the Gateway itself**, the agent loop is a small slice of `src/agents/`, and **infrastructure exceeds 100k lines combined**.
3. Three more extension axes outside `src/`: **40 extension packages, 52 bundled skills, \~1.7 GB of native apps**.
4. In the tech stack, the Rust toolchain (Oxlint/Oxfmt) and the 700-line file discipline are both **engineering decisions in service of scale**, not style preferences.
