Skip to content

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   # Restart

Source: 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 status

Source: 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 patch

Source: 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 plugin

Source: 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 skill

Source: src/commands/skills-cli.ts

Other Commands

CommandDescriptionSource File
cronCron job managementcron-cli.ts
nodesRemote node managementnodes-cli.ts
memoryMemory search and managementmemory-cli.ts
hooksHook debugging and listinghooks-cli.ts
updateVersion updatesupdate-cli.ts
doctorDiagnostics and repairdoctor-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

OpenClaw Source Code Tutorial