> 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/ch02-getting-started/2.4-development-workflow.md). Agents can also search and read this documentation through its [MCP server](https://www.openclawbook.xyz/~gitbook/mcp).

# 2.4 Development Workflow

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

***

An efficient development workflow is the foundation for contributing to open source projects. OpenClaw provides multiple tools to accelerate the "modify → verify" feedback loop.

## 2.4.1 `pnpm gateway:watch` — File Watching and Hot Reload

For Gateway development, the most commonly used command is:

```bash
pnpm gateway:watch
```

This command is implemented in `scripts/watch-node.mjs` and does two things:

```javascript
// scripts/watch-node.mjs (simplified)

// 1. First perform a complete build
const initialBuild = spawnSync("pnpm", ["exec", "tsdown"], { stdio: "inherit" });

// 2. Start two processes simultaneously:
// (a) tsdown --watch: Monitor TypeScript source changes, incremental recompilation
const compilerProcess = spawn("pnpm", ["exec", "tsdown", "--watch"], { stdio: "inherit" });

// (b) node --watch: Monitor JS changes in dist/, automatically restart Gateway
const nodeProcess = spawn(
  process.execPath,
  ["--watch", "openclaw.mjs", ...args],
  { stdio: "inherit" }
);
```

The workflow is as follows:

```
You modify src/gateway/server.ts
        │
        ▼
tsdown --watch detects the change
        │
        ▼
Incremental compilation → Update dist/gateway/server.js
        │
        ▼
node --watch detects dist/ change
        │
        ▼
Automatically restart Gateway process
```

Note that `--watch` is a built-in file monitoring restart feature in Node.js 22, no additional tools like `nodemon` are needed.

There's also a development mode that skips channel connections, suitable for when you're only developing Gateway core logic:

```bash
# Development mode skipping channel connections (faster startup)
pnpm gateway:dev

# Development mode with reset (clear sessions)
pnpm gateway:dev:reset
```

These two commands set the environment variable `OPENCLAW_SKIP_CHANNELS=1`, which makes the Gateway skip connecting to any channels (WhatsApp, Telegram, etc.) on startup, significantly reducing startup time.

### Smart Incremental Build

`scripts/run-node.mjs` implements a smart incremental build mechanism:

```javascript
// scripts/run-node.mjs (simplified)
const distEntry = path.join(distRoot, "/entry.js");
const buildStampPath = path.join(distRoot, ".buildstamp");

// Check if dist/ exists and is newer than src/
const buildStamp = statMtime(buildStampPath);
const latestSource = findLatestMtime(srcRoot, isExcludedSource);

if (!buildStamp || !latestSource || latestSource > buildStamp) {
  // Source code is newer than build artifacts → need to rebuild
  console.log("[run-node] Rebuilding...");
  spawnSync("pnpm", ["exec", "tsdown", "--no-clean"], { stdio: "inherit" });
}
```

It determines whether a rebuild is needed by comparing the modification time of the `.buildstamp` file with the latest file in the `src/` directory. This way, when running `pnpm openclaw gateway`, if you haven't modified any source files, it will skip the build and start directly — saving a few seconds of startup time.

## 2.4.2 Test System

OpenClaw has a comprehensive layered test system:

### Unit Tests

```bash
# Run all unit tests
pnpm test

# Watch mode (automatically rerun after changes)
pnpm test:watch

# With coverage report
pnpm test:coverage
```

Unit tests use **vitest**, configured in `vitest.config.ts`. Test files are placed in the same directory as source code with a `.test.ts` suffix:

```
src/gateway/
├── auth.ts              # Source code
├── auth.test.ts         # Corresponding test
├── origin-check.ts
├── origin-check.test.ts
└── ...
```

Key vitest configuration:

```typescript
{
  test: {
    testTimeout: 120_000,        // 2 minute timeout
    pool: "forks",               // Process isolation (not threads)
    include: ["src/**/*.test.ts", "extensions/**/*.test.ts"],
    exclude: ["**/*.live.test.ts", "**/*.e2e.test.ts"],
  }
}
```

* **Process isolation** (`pool: "forks"`): Each test file runs in an isolated process. This is important for OpenClaw because Gateway tests may involve global state (port binding, file locks, etc.).
* **Exclude live and e2e tests**: These require real API Keys or complete environments and are run separately.

### End-to-End Tests (E2E)

```bash
pnpm test:e2e
```

E2E tests (`*.e2e.test.ts`) verify complete user workflows — starting the Gateway, sending messages, verifying replies. They use the `vitest.e2e.config.ts` configuration.

### Live Tests

```bash
pnpm test:live
```

Live tests (`*.live.test.ts`) require real API Keys (such as Anthropic API Key, OpenAI API Key) and test interactions with real models. Enabled via the `OPENCLAW_LIVE_TEST=1` environment variable.

### Docker Tests

```bash
# Run all Docker tests
pnpm test:docker:all
```

Docker tests run in containers, verifying packaging, installation, networking, and other scenarios:

| Test                          | Description                         |
| ----------------------------- | ----------------------------------- |
| `test:docker:live-models`     | Test model calls in container       |
| `test:docker:live-gateway`    | Test Gateway in container           |
| `test:docker:onboard`         | Test onboarding wizard in container |
| `test:docker:gateway-network` | Container network test              |
| `test:docker:qr`              | QR code import test                 |
| `test:docker:doctor-switch`   | doctor command test                 |
| `test:docker:plugins`         | Plugin test                         |

### Parallel Test Runner

OpenClaw has a custom parallel test runner `scripts/test-parallel.mjs`, called by `pnpm test`. It divides test files into multiple batches and runs them in parallel, fully utilizing multi-core CPUs.

### UI Tests

```bash
pnpm test:ui
```

The Web UI has its own test configuration (`ui/vitest.config.ts`), using `@vitest/browser-playwright` to run in a real browser.

## 2.4.3 Code Quality: oxlint Type-Aware Lint + oxfmt Formatting

### Lint Checking

```bash
# Lint check
pnpm lint

# Auto-fix
pnpm lint:fix
```

OpenClaw uses **oxlint** (a Linter written in Rust) instead of ESLint. The advantage of oxlint is speed — for OpenClaw's codebase of hundreds of thousands of lines, oxlint's lint time is only a fraction of ESLint's.

The `--type-aware` flag enables type-aware rules, which means oxlint reads TypeScript's type information to perform more precise checks (for example, detecting unused type imports, type-unsafe comparisons, etc.).

### Formatting

```bash
# Format check
pnpm format

# Auto-format
pnpm format:fix
```

**oxfmt** handles code formatting. Configuration is in `.oxfmtrc.jsonc`.

### Swift Code Quality

Native application Swift code has independent Lint and formatting tools:

```bash
# Swift Lint
pnpm lint:swift      # swiftlint

# Swift formatting
pnpm format:swift    # swiftformat
```

Configuration files `.swiftlint.yml` and `.swiftformat` define the rules respectively.

### Documentation Quality

```bash
# Documentation Lint + formatting
pnpm check:docs

# Lines of code check (single file not exceeding 500 lines)
pnpm check:loc
```

`check:loc` ensures via `scripts/check-ts-max-loc.ts` that no single TypeScript file exceeds 500 lines — this is a hard constraint on code organization. If a file grows close to 500 lines, it should be considered for splitting.

### One-Command Quality Check

```bash
# Complete quality check pipeline
pnpm check  # = tsgo + lint + format

# Complete test pipeline
pnpm test:all  # lint + build + test + e2e + live + docker
```

### Git Hooks

OpenClaw configures Git hooks through the `git-hooks/` directory, set up in the `prepare` script:

```json
{
  "scripts": {
    "prepare": "command -v git >/dev/null 2>&1 && git config core.hooksPath git-hooks || exit 0"
  }
}
```

This ensures that lint and formatting checks are automatically run before each commit.

***

To summarize OpenClaw's development workflow:

```
Code modification
    │
    ├──→ pnpm gateway:watch     # Real-time development (auto-restart)
    ├──→ pnpm test:watch        # Real-time testing (auto-rerun)
    │
    ├──→ pnpm lint:fix          # Auto-fix lint issues
    ├──→ pnpm format:fix        # Auto-format
    │
    ├──→ pnpm test              # Run unit tests
    ├──→ pnpm test:e2e          # Run E2E tests
    │
    └──→ pnpm check && pnpm test # Complete check before commit
```

By now, you have all the environmental knowledge needed to participate in OpenClaw development. Starting from the next chapter, we'll dive into the source code implementation of the Gateway control plane.
