> 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/ch01-understanding-openclaw/1.4-project-directory-structure.md). Agents can also search and read this documentation through its [MCP server](https://www.openclawbook.xyz/~gitbook/mcp).

# 1.4 Project Directory Structure in Detail

> **Generated by**: Claude Opus 4.6 (initial draft) / Claude Opus 5 (`v2026.3.9` revision) **Token usage**: Input \~130,000 tokens, Output \~12,000 tokens (total for this chapter) **Source baseline**: `v2026.3.9` (`v2026.3.8-170-g665f67726`)

***

Before diving into the source code, we need to have a comprehensive understanding of OpenClaw's project directory structure. A good directory structure is like a book's table of contents—it reflects the project's architectural decisions and module divisions.

The top-level structure of the OpenClaw repository root directory is as follows:

```
openclaw/
├── src/                    # Core source code (TypeScript)
├── apps/                   # Native client applications
│   ├── macos/             # macOS menu bar application (Swift)
│   ├── ios/               # iOS node application (Swift)
│   ├── android/           # Android node application (Kotlin)
│   └── shared/            # Cross-platform shared code (Swift)
├── ui/                     # Web console UI (Lit + Vite)
├── extensions/             # Optional channel extensions (31)
├── packages/               # Internal shared packages
├── skills/                 # Built-in skills (52)
├── docs/                   # Official documentation source
├── scripts/                # Build and tool scripts
├── test/                   # Global test configuration
├── vendor/                 # Third-party code
├── patches/                # pnpm patch patches
├── git-hooks/              # Git hooks
├── package.json            # Main package configuration
├── pnpm-workspace.yaml     # Monorepo workspace definition
├── tsconfig.json           # TypeScript configuration
├── tsdown.config.ts        # Bundler configuration
├── vitest.config.ts        # Test configuration
├── docker-compose.yml      # Docker orchestration
├── Dockerfile              # Main container image
├── Dockerfile.sandbox      # Sandbox container image
├── Dockerfile.sandbox-browser # Sandbox image with browser
└── openclaw.mjs            # CLI entry point for npm global install
```

Let's dive into each core directory.

## 1.4.1 `src/` — Core Source Code (69 Subdirectories)

`src/` is OpenClaw's core, containing TypeScript source code for all core functionality including Gateway, Agent, channels, tools, and more. It has 69 subdirectories—the largest part of the entire project.

Divided by functional domain, these subdirectories can be grouped as follows:

### Gateway Core (Control Plane)

| Directory       | Files | Description                                                                |
| --------------- | ----- | -------------------------------------------------------------------------- |
| `src/gateway/`  | 128   | Gateway WebSocket server, HTTP server, session management, method handling |
| `src/routing/`  | 5     | Message routing logic: route resolution, session key generation            |
| `src/sessions/` | 7     | Session helpers: level overrides, model overrides, send policies           |

### Agent Runtime

| Directory        | Files | Description                                                                       |
| ---------------- | ----- | --------------------------------------------------------------------------------- |
| `src/agents/`    | 308   | **Largest directory**. Agent loop, tool system, model management, skills, sandbox |
| `src/providers/` | 8     | Model provider-specific logic (GitHub Copilot, Google, Qwen)                      |

`src/agents/` is the directory with the most files in the entire project. It's further subdivided into:

```
src/agents/
├── pi-embedded-*.ts        # Pi Agent embedded runtime (core Agent loop)
├── pi-tools*.ts            # Tool registration, policies, Schema
├── bash-tools*.ts          # Bash execution engine
├── model-*.ts              # Model selection, fallback, catalog, compatibility
├── auth-profiles*.ts       # Auth Profile authentication management
├── skills*.ts              # Skill loading, installation, status
├── sandbox*.ts             # Docker sandbox
├── system-prompt*.ts       # System prompt construction
├── compaction*.ts          # Context compaction
├── identity*.ts            # AI identity management
├── workspace*.ts           # Workspace management
├── subagent-*.ts           # Sub-agent management
├── session-*.ts            # Session file operations
├── tools/                  # Concrete tool implementations (Discord actions, Slack actions, etc.)
├── schema/                 # Configuration Schema
├── cli-runner/             # CLI Agent runner
├── pi-embedded-runner/     # Pi embedded runner submodule
├── pi-embedded-helpers/    # Pi embedded helper functions
├── pi-extensions/          # Pi extension points
├── sandbox/                # Sandbox submodule
├── skills/                 # Skills submodule
└── test-helpers/           # Test helpers
```

### Channel Implementation

| Directory       | Files | Description                                                                     |
| --------------- | ----- | ------------------------------------------------------------------------------- |
| `src/channels/` | 31    | Channel abstraction layer: registry, whitelists, mention gating, command gating |
| `src/whatsapp/` | —     | WhatsApp-specific logic                                                         |
| `src/web/`      | 46    | WhatsApp Web implementation (Baileys): login, inbound, outbound, auto-reply     |
| `src/telegram/` | —     | Telegram Bot (grammY) implementation                                            |
| `src/discord/`  | —     | Discord Bot implementation                                                      |
| `src/slack/`    | —     | Slack Bot (Bolt) implementation                                                 |
| `src/signal/`   | —     | Signal (signal-cli) implementation                                              |
| `src/imessage/` | —     | iMessage Legacy implementation                                                  |
| `src/line/`     | —     | LINE channel helpers                                                            |

### Tools and Automation

| Directory          | Files | Description                                                      |
| ------------------ | ----- | ---------------------------------------------------------------- |
| `src/browser/`     | 68    | Browser control: CDP, Playwright, Chrome management, screenshots |
| `src/canvas-host/` | 4     | Canvas/A2UI server                                               |
| `src/cron/`        | 33    | Cron scheduling: scheduling, storage, delivery                   |
| `src/node-host/`   | 3     | Device node Host                                                 |
| `src/commands/`    | —     | Chat slash command handling                                      |
| `src/hooks/`       | 28    | Hook system: loaders, installation, Gmail hooks                  |

### Infrastructure

| Directory       | Files | Description                                                            |
| --------------- | ----- | ---------------------------------------------------------------------- |
| `src/config/`   | 124   | Configuration system: loading, Schema, types, migration, validation    |
| `src/security/` | 13    | Security: audit, external content check, skill scanning                |
| `src/infra/`    | —     | Infrastructure tools: port management, binaries, environment variables |
| `src/media/`    | 19    | Media pipeline: fetch, parse, store, image processing                  |
| `src/memory/`   | 43    | Memory system: embeddings, vector search, SQLite, hybrid search        |
| `src/logging/`  | —     | Logging subsystem                                                      |
| `src/tts/`      | —     | Text-to-speech                                                         |

### CLI and User Interface

| Directory       | Files | Description                                                             |
| --------------- | ----- | ----------------------------------------------------------------------- |
| `src/cli/`      | 105   | CLI command implementations: gateway, agent, send, models, skills, etc. |
| `src/wizard/`   | 10    | Onboarding Wizard                                                       |
| `src/tui/`      | —     | Terminal user interface                                                 |
| `src/terminal/` | —     | Terminal rendering tools                                                |
| `src/daemon/`   | —     | Daemon process management                                               |

### Other

| Directory/File             | Description                                 |
| -------------------------- | ------------------------------------------- |
| `src/plugin-sdk/`          | Plugin SDK (for extension developers)       |
| `src/plugins/`             | Plugin loader                               |
| `src/extensionAPI.ts`      | Extension API entry point                   |
| `src/acp/`                 | Agent Communication Protocol implementation |
| `src/auto-reply/`          | Auto-reply logic                            |
| `src/link-understanding/`  | Link content understanding                  |
| `src/media-understanding/` | Media content understanding                 |
| `src/pairing/`             | DM pairing system                           |
| `src/process/`             | Process management                          |
| `src/shared/`              | Shared utility functions                    |
| `src/types/`               | Third-party library type declarations       |
| `src/utils.ts`             | General utility functions                   |
| `src/markdown/`            | Markdown processing                         |
| `src/macos/`               | macOS-specific functionality                |
| `src/entry.ts`             | CLI entry point                             |
| `src/index.ts`             | Library entry point (exports public API)    |
| `src/globals.ts`           | Global constants                            |
| `src/runtime.ts`           | Runtime configuration                       |
| `src/logger.ts`            | Logger instance                             |
| `src/logging.ts`           | Logging configuration                       |

## 1.4.2 `apps/` — Native Client Applications

```
apps/
├── macos/                 # macOS menu bar application
│   ├── Sources/           # Swift source code
│   │   ├── OpenClawApp/   # Main application
│   │   ├── OpenClawProtocol/ # Gateway protocol implementation (auto-generated)
│   │   ├── Views/         # SwiftUI views
│   │   ├── VoiceWake/     # Voice wake module
│   │   └── ...
│   ├── project.yml        # XcodeGen project description
│   └── .swiftlint.yml     # Swift Lint configuration
├── ios/                   # iOS node application
│   ├── Sources/           # Swift source code
│   ├── project.yml        # XcodeGen project description
│   └── ...
├── android/               # Android node application
│   ├── app/
│   │   └── src/main/
│   │       ├── java/ai/openclaw/android/  # Kotlin source code
│   │       ├── res/       # Android resources
│   │       └── AndroidManifest.xml
│   ├── build.gradle.kts   # Gradle build configuration
│   └── gradlew            # Gradle Wrapper
└── shared/                # Cross-platform shared code
    └── OpenClawKit/
        └── Sources/       # Shared Swift Package
```

The macOS and iOS applications use **XcodeGen** to generate Xcode project files (rather than directly committing `.xcodeproj`), which avoids merge conflict issues with Xcode project files.

## 1.4.3 `ui/` — Web Console UI

```
ui/
├── index.html             # SPA entry point
├── package.json           # UI package configuration (Lit + Vite)
├── vite.config.ts         # Vite build configuration
├── vitest.config.ts       # UI test configuration
├── public/                # Static assets
└── src/                   # Lit Web Components source code
```

The UI is an independent pnpm workspace package (`openclaw-control-ui`) built with Vite. The build artifacts are embedded in Gateway and served directly, requiring no separate deployment. Gateway automatically provides UI service on startup (`src/gateway/control-ui.ts`).

## 1.4.4 `extensions/` — Optional Channel Extensions (31 Extensions)

```
extensions/
├── bluebubbles/           # BlueBubbles iMessage integration
├── msteams/               # Microsoft Teams
├── matrix/                # Matrix protocol
├── googlechat/            # Google Chat
├── nostr/                 # Nostr decentralized protocol
├── twitch/                # Twitch streaming platform
├── feishu/                # Feishu / Lark
├── line/                  # LINE
├── mattermost/            # Mattermost
├── zalo/                  # Zalo (Vietnamese messaging platform)
├── zalouser/              # Zalo Personal
├── memory-core/           # Core memory plugin
├── memory-lancedb/        # LanceDB memory backend
├── copilot-proxy/         # Copilot proxy
├── diagnostics-otel/      # OpenTelemetry diagnostics
├── llm-task/              # LLM task extension
├── voice-call/            # Voice call
├── open-prose/            # Open prose processing
├── lobster/               # Lobster extension
├── tlon/                  # Tlon platform
├── nextcloud-talk/        # Nextcloud Talk
├── discord/               # Discord extension version
├── slack/                 # Slack extension version
├── telegram/              # Telegram extension version
├── signal/                # Signal extension version
├── whatsapp/              # WhatsApp extension version
├── imessage/              # iMessage extension version
├── google-antigravity-auth/  # Google authentication helper
├── google-gemini-cli-auth/   # Gemini CLI authentication
├── minimax-portal-auth/      # MiniMax authentication
└── qwen-portal-auth/         # Qwen authentication
```

Each extension is an independent pnpm package with its own `package.json` and entry file. Extensions interact with Gateway through the Plugin SDK.

## 1.4.5 `packages/` — Internal Shared Packages

```
packages/
├── clawdbot/              # Internal shared package
└── moltbot/               # Compatibility alias package
```

These two packages provide some basic functionality shared across modules. `moltbot` is a legacy name from OpenClaw's predecessor project.

## 1.4.6 `skills/` — Built-in Skills (52 Skills)

```
skills/
├── 1password/             # 1Password integration
├── apple-notes/           # Apple Notes operations
├── apple-reminders/       # Apple Reminders operations
├── bear-notes/            # Bear Notes integration
├── blogwatcher/           # Blog monitoring
├── canvas/                # Canvas operations skill
├── clawhub/               # ClawHub skill search
├── coding-agent/          # Coding Agent skill
├── discord/               # Discord operations
├── github/                # GitHub integration
├── gmail/                 # Gmail integration (missing but implemented in hooks)
├── healthcheck/           # Health check
├── notion/                # Notion integration
├── obsidian/              # Obsidian note integration
├── oracle/                # Oracle consultation skill
├── peekaboo/              # Peekaboo screenshot
├── skill-creator/         # Skill creation helper
├── slack/                 # Slack operations
├── spotify-player/        # Spotify playback control
├── things-mac/            # Things 3 task management
├── tmux/                  # Tmux terminal operations
├── trello/                # Trello integration
├── weather/               # Weather query
├── video-frames/          # Video frame extraction
├── voice-call/            # Voice call
└── ...                    # More skills
```

Each skill directory typically contains a `SKILL.md` file, which is a Markdown-formatted documentation that the Agent reads at runtime to understand how to use the skill. Some skills also include additional scripts or configuration files.

## 1.4.7 `docs/` — Official Documentation Source

```
docs/
├── index.md               # Documentation home page
├── docs.json              # Mintlify documentation configuration
├── concepts/              # Concept documentation (31)
│   ├── architecture.md    # Architecture overview
│   ├── agent-loop.md      # Agent loop
│   ├── session.md         # Session management
│   ├── streaming.md       # Streaming
│   ├── models.md          # Model management
│   ├── memory.md          # Memory system
│   └── ...
├── channels/              # Channel configuration guides
├── gateway/               # Gateway operations guides
├── tools/                 # Tool usage documentation
├── platforms/             # Platform guides (macOS/iOS/Android/Windows/Linux)
├── automation/            # Automation (Cron/Webhook/Gmail)
├── install/               # Installation guides
├── start/                 # Getting started guides
├── web/                   # Web UI documentation
├── reference/             # Reference documentation
├── providers/             # Model providers
├── plugins/               # Plugin development
├── security/              # Security guides
├── zh-CN/                 # Chinese translation
└── assets/                # Documentation assets
```

The documentation is built with [Mintlify](https://mintlify.com/) and hosted at `docs.openclaw.ai`. The 31 concept documents in the `docs/concepts/` directory are excellent references for understanding OpenClaw's design decisions—this book also references these documents in many places.

***

By now, you should have a clear understanding of OpenClaw's project structure. Let's end this section with a quick reference table:

| Feature You Want to Understand | Directory to Look At First                              |
| ------------------------------ | ------------------------------------------------------- |
| Gateway server implementation  | `src/gateway/`                                          |
| AI Agent loop                  | `src/agents/pi-embedded-*.ts`                           |
| Tool system                    | `src/agents/pi-tools*.ts` + `src/agents/bash-tools*.ts` |
| WhatsApp channel               | `src/web/`                                              |
| Telegram channel               | `src/telegram/`                                         |
| Configuration system           | `src/config/`                                           |
| Security model                 | `src/security/` + `src/agents/sandbox*.ts`              |
| Memory system                  | `src/memory/`                                           |
| Browser automation             | `src/browser/`                                          |
| CLI commands                   | `src/cli/`                                              |
| Skill system                   | `src/agents/skills*.ts` + `skills/`                     |
| Extension development          | `src/plugin-sdk/` + `extensions/`                       |
| macOS application              | `apps/macos/Sources/`                                   |
| Web UI                         | `ui/src/`                                               |

In the next chapter, we'll set up the development environment and run OpenClaw.
