Skip to content

CLI Overview

The OpenClaw CLI is the primary interface for users to interact with the system. It is built on Commander.js and uses a dependency injection pattern to organize commands.

Source Location

src/cli/
├── program/
│   └── build-program.ts    # Commander program builder
├── deps.ts                 # Dependency injection
├── run-main.ts             # CLI main run function
├── profile.ts              # Profile management
├── prompt.ts               # Interactive prompts
├── wait.ts                 # Wait utilities
├── progress.ts             # Progress bars
└── ...

src/commands/                # ~183 files, CLI subcommands
├── gateway-cli.ts          # gateway command group
├── channels-cli.ts         # channels command group
├── config-cli.ts           # config command group
├── plugins-cli.ts          # plugins command group
├── send-cli.ts             # send command
├── cron-cli.ts             # cron command group
├── skills-cli.ts           # skills command group
├── nodes-cli.ts            # nodes command group
├── memory-cli.ts           # memory command group
├── hooks-cli.ts            # hooks command group
├── update-cli.ts           # update command
└── ...

CLI Startup Flow

Respawn Mechanism

Source: src/entry.ts

The entry file checks whether a respawn is needed. To suppress Node.js ExperimentalWarning messages, the process may need to restart with the --disable-warning=ExperimentalWarning flag:

typescript
// src/entry.ts (simplified)
function ensureExperimentalWarningSuppressed(): boolean {
  if (hasExperimentalWarningSuppressed()) return false;

  // Respawn with the flag
  const child = spawn(
    process.execPath,
    [EXPERIMENTAL_WARNING_FLAG, ...process.execArgv, ...process.argv.slice(1)],
    { stdio: "inherit", env: process.env }
  );

  attachChildProcessBridge(child);
  return true; // Parent stops here
}

Core Concepts

ConceptDescriptionSource File
ProgramCommander.js program instancecli/program/build-program.ts
CliDepsDependency injection containercli/deps.ts
ProfileCLI configuration profilecli/profile.ts
Command ModuleCommand implementation modulecommands/*.ts

Chapter Navigation

  1. Command Structure -- Commander.js command registration and module organization
  2. Dependency Injection -- CliDeps pattern, bridging layer

OpenClaw Source Code Tutorial