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
| Concept | Description | Source File |
|---|---|---|
| Program | Commander.js program instance | cli/program/build-program.ts |
| CliDeps | Dependency injection container | cli/deps.ts |
| Profile | CLI configuration profile | cli/profile.ts |
| Command Module | Command implementation module | commands/*.ts |
Chapter Navigation
- Command Structure -- Commander.js command registration and module organization
- Dependency Injection -- CliDeps pattern, bridging layer