Command Structure
The OpenClaw CLI uses Commander.js to organize its commands, with approximately 183 files implementing the full command tree.
Program Construction
Source: src/cli/program/build-program.ts
typescript
// src/cli/program/build-program.ts (simplified)
function buildProgram(): Command {
const program = new Command("openclaw");
// 1. Create program context
createProgramContext(program);
// 2. Register all commands
registerProgramCommands(program);
// 3. Configure help output
configureProgramHelp(program);
// 4. Register pre-action hooks
registerPreActionHooks(program);
return program;
}Command Tree
Main Command Groups
gateway -- Gateway Management
openclaw gateway start # Start the Gateway
openclaw gateway stop # Stop the Gateway
openclaw gateway status # View status
openclaw gateway restart # RestartSource: src/commands/gateway-cli.ts
send -- Message Sending
openclaw send -t telegram -c <chatId> "Hello"Source: src/commands/send-cli.ts
channels -- Channel Management
openclaw channels login telegram # Login to Telegram
openclaw channels logout discord # Logout from Discord
openclaw channels list # List all channels
openclaw channels status # View channel statusSource: src/commands/channels-cli.ts
config -- Configuration Management
openclaw config get # View full config
openclaw config set key value # Set a config value
openclaw config patch '{"key":"val"}' # JSON patchSource: src/commands/config-cli.ts
plugins -- Plugin Management
openclaw plugins install <name> # Install a plugin
openclaw plugins list # List installed plugins
openclaw plugins enable <name> # Enable a plugin
openclaw plugins disable <name> # Disable a pluginSource: src/commands/plugins-cli.ts
skills -- Skill Management
openclaw skills install <name> # Install a skill
openclaw skills list # List skills
openclaw skills remove <name> # Remove a skillSource: src/commands/skills-cli.ts
Other Commands
| Command | Description | Source File |
|---|---|---|
cron | Cron job management | cron-cli.ts |
nodes | Remote node management | nodes-cli.ts |
memory | Memory search and management | memory-cli.ts |
hooks | Hook debugging and listing | hooks-cli.ts |
update | Version updates | update-cli.ts |
doctor | Diagnostics and repair | doctor-cli.ts |
Pre-Action Hooks
Commander.js pre-action hooks run before command execution:
typescript
// Pre-action hooks (simplified)
function registerPreActionHooks(program: Command): void {
program.hook("preAction", async () => {
// Load config
// Initialize dependencies
// Check prerequisites
});
}Summary
- Commander.js-based command tree with approximately 183 files
buildProgram()creates context, registers commands, and configures help in one place- Main command groups: gateway, send, channels, config, plugins, skills, nodes
- Pre-action hooks initialize dependencies and config before command execution
Next: Dependency Injection