> 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.4-source-reading-paths.md). Agents can also search and read this documentation through its [MCP server](https://www.openclawbook.xyz/~gitbook/mcp).

# 43.4 Source Reading Paths

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

***

You cannot read 500,000 lines end to end, and you shouldn't try. This section gives four proven entry paths. Pick one based on what you're after.

## 43.4.1 Path One: Build a Map (half a day)

Goal: understand what problem this project solves and where its boundaries are. Documentation only, no code:

| Order | File                            | Read it to answer                                                                          |
| ----- | ------------------------------- | ------------------------------------------------------------------------------------------ |
| 1     | `VISION.md`                     | What the project wants — and explicitly doesn't                                            |
| 2     | `docs/concepts/architecture.md` | Gateway star topology; control plane vs. data plane                                        |
| 3     | `docs/concepts/agent.md`        | Personality files, sessions, workspace model                                               |
| 4     | `SECURITY.md`                   | **Required.** The trust model dictates why all the code that follows looks the way it does |
| 5     | `AGENTS.md`                     | How this repository actually gets developed (§43.3)                                        |

`SECURITY.md` sits at position four rather than last because it has the highest information density in the repo. It writes down *what is not protected* as executable case law — single-machine single-operator, plugins as trusted computing base, prompt-injection-only isn't a vulnerability. Skip it and you'll spend the rest of your reading confused about why there's no isolation *here*.

In this book: Chapter 1, §11.1, Chapter 32.

## 43.4.2 Path Two: Follow One Message's Life (one day)

This is **the recommended first code path**. Pick a channel you know (Telegram is simplest) and follow a message from arrival to reply:

```
① Channel monitor        src/telegram/
   Platform SDK events → normalized to internal message
        ↓
② Routing                src/routing/
   Which agent and which session does this belong to?
        ↓
③ Dispatch & queueing    src/auto-reply/dispatch.ts + queue
   Debounce, mention gating, command detection, two-tier lane queueing
        ↓
④ Agent run              src/agents/pi-embedded-runner/
   System prompt assembly → pi loop → tool execution → stream events
        ↓
⑤ Reply delivery         Chunk, shape, adapt per channel, send
```

Walk this once and OpenClaw's skeleton stands up. The five stages map to Chapter 20, Chapter 13, Chapter 14, Chapter 15, and Chapter 18 respectively — when the code stalls you, go read the matching chapter.

One practical tip: **turn on debug logging against a real instance while you read** (Chapter 38 covers how) and follow the logs alongside the code. This path has a lot of conditional branches, and reading alone makes it hard to tell which one is the main road.

## 43.4.3 Path Three: Read by Problem

If you arrive with a specific question, jump straight to the module:

| The problem you want solved                          | Read                                                                   | Chapters       |
| ---------------------------------------------------- | ---------------------------------------------------------------------- | -------------- |
| How to design a multi-device / multi-client protocol | `src/gateway/protocol/` + `docs/gateway/protocol.md`                   | 12, Appendix G |
| How to degrade gracefully when API keys run out      | `src/agents/auth-profiles*`                                            | 16             |
| How to define a plugin contract                      | `src/plugin-sdk/` + any small extension (e.g. `extensions/mattermost`) | 21             |
| What to do when users send bursts of messages        | `docs/concepts/queue.md` + `src/auto-reply/`                           | 13, 14         |
| How to compact an overflowing context                | `src/agents/pi-embedded-runner/compact.ts`                             | §17.4          |
| How to lend out shell capability safely              | `src/node-host/exec-policy.ts`                                         | 27, Appendix F |
| How to install a cross-platform daemon               | `src/daemon/`                                                          | 37, Appendix F |
| How to do config hot reload and write-back           | `src/config/`                                                          | 31             |

Reading a small extension is high-leverage: a package like `extensions/mattermost` is only a few hundred lines yet exercises the entire plugin contract — manifest declaration, capability registration, message send/receive, config schema. Understand one small extension and you understand every interface in the plugin system.

## 43.4.4 Path Four: Use the Tests as the Spec

As §43.2 noted, `src/` contains 1,935 test files whose names are deliberately written as behavior descriptions. That creates a reading path unique to this project.

When code confuses you, the standard move is:

```bash
# find the sibling test
ls src/agents/ | grep "auth-profiles.*test"
```

You'll find filenames like:

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

Parse it: in the `auth-profiles` module, the `resolveAuthProfileOrder` function **does not** prioritize the last successful profile — it preserves round-robin order.

That one filename explains a counterintuitive design decision: why not prefer the account that just worked? (Answer in Chapter 16: to spread load, instead of pinning all traffic on one key until it gets rate-limited.)

**This is a source of reading efficiency unique to OpenClaw.** In most projects tests are a verification mechanism; here test filenames are full-text-searchable behavioral documentation. Build the habit of *grep the test names first, read the implementation second* and your comprehension speed noticeably improves.

## 43.4.5 One Important Warning: Don't Start with `attempt.ts`

A closing anti-recommendation.

Under `src/agents/pi-embedded-runner/` sits a \~2,100-line assembly file (dissected in §15.2 and §15.5). It's the staging ground for an agent run — wiring together config, tools, auth, the streaming wrapper chain, and extension hooks.

It is the **destination** for understanding agent execution, not the entry point. The wrapper chain is order-sensitive and the conditional branches are dense; many of them only make sense after you've read Chapters 16, 17, and 22. Newcomers who charge in usually conclude *this code is a mess* and give up.

The right order: walk Path Two to build the skeleton, read Chapters 15–17 to understand the parts, then come back to the assembly. By then you'll find it's messy **for reasons** — every quirk corresponds to a behavioral difference in the upstream pi engine or a production incident.

***

## Section Summary

1. **Path One (half a day)**: documentation only — `VISION.md` → `architecture.md` → `agent.md` → **`SECURITY.md` (required)** → `AGENTS.md`.
2. **Path Two (one day)**: follow one message's life — monitor → routing → dispatch/queue → agent run → delivery. The recommended first code path.
3. **Path Three**: jump to the module for a specific question; **reading a small extension is the fastest way to understand the plugin contract**.
4. **Path Four**: **use the 1,935 test filenames as the spec** — "grep test names first, read implementation second" is an efficiency source unique to this project.
5. Anti-recommendation: **don't start with the \~2,100-line assembly file** — it's the destination, not the entry point.
