#13441: Optimise: CLI startup time optimizations
docs
cli
docker
stale
Cluster:
Completion Performance Improvements
## 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
#13168: perf: short-circuit --version to skip process respawn and full modu...
by RamiNoodle733 · 2026-02-10
78.6%
#16710: feat: fast-path --version, --help, and no-args to skip full module ...
by xin-wen · 2026-02-15
77.8%
#9148: Fix: Speed up shell completion generation from ~4.6s to <200ms
by vishaltandale00 · 2026-02-04
76.7%
#17962: fix(cli): speed up completion plugin loading
by forketyfork · 2026-02-16
76.6%
#22050: Speed up docker cold start time by 6.3x.
by mm-zacharydavison · 2026-02-20
75.0%
#13840: perf(cli): skip plugin loading during completion generation
by lailoo · 2026-02-11
74.7%
#15306: fix: explicit exit after onboarding command completes
by jeroenbaas · 2026-02-13
74.2%
#17770: refactor(cli): reuse shared option builders
by iyoda · 2026-02-16
73.6%
#10367: CLI/Ops: resilient browser fill + failover hardening + operations t...
by cluster2600 · 2026-02-06
73.5%
#17680: perf(cli): skip plugin loading during completion generation
by mcrolly · 2026-02-16
73.0%