← Back to PRs

#13441: Optimise: CLI startup time optimizations

by TymekTM open 2026-02-10 14:31 View on GitHub →
docs cli docker stale
## What & Why This PR significantly improves CLI startup time through several optimizations: 1. **Ultra-fast `--version` path**: Resolves version from `package.json` without loading the full CLI, avoiding respawn and command registration 2. **Lazy-load command registrations**: Defers loading of browser command modules until needed 3. **Lazy-load heavy dependencies**: Delays importing route deps, dotenv, and message/browser modules 4. **Skip respawn for help/version**: Avoids unnecessary process respawning for `--help` and `--version` flags 5. **Minimal help program**: Uses a lightweight help display that skips loading message/browser modules ## Testing - [x] Tested locally with OpenClaw instance - [x] Verified `--version` flag works correctly - [x] Verified `--help` flag works correctly - [x] Tested main CLI functionality still works - [x] CI checks passing ## AI-Assisted Development Developed with Github Copilot running Opus 4.6 <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR restructures CLI startup to reduce cold-start latency by adding fast paths for `--version`/help, deferring dotenv/env setup for help-only runs, and converting command registration to lazy `import()` so heavy modules (notably `message` and `browser`) are only loaded when needed. It also introduces a minimal help program that stubs out heavy subcommand trees for top-level `--help`. Key area to double-check is the new async/concurrent command registration approach, since it now registers many Commander commands via `Promise.all`, which can affect deterministic command setup and help output. <h3>Confidence Score: 3/5</h3> - This PR improves startup performance but has a deterministic-behavior risk due to concurrent Commander registration. - Most changes are straightforward lazy-import optimizations, but `Promise.all` registration mutates a shared Commander program concurrently, which can lead to nondeterministic command/help configuration and should be made sequential before merging. - src/cli/program/command-registry.ts <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> **Context used:** - Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8)) - Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13)) <!-- /greptile_comment -->

Most Similar PRs