#13168: perf: short-circuit --version to skip process respawn and full module loading
stale
Cluster:
Completion Performance Improvements
## Summary
- Short-circuit `--version` (`-v`, `-V`) in `src/entry.ts` before the expensive `ensureExperimentalWarningSuppressed()` respawn and full Commander module loading
## Problem
Running `openclaw --version` takes ~5s on a single-core VPS (1-2s on modern machines) to print a hardcoded version string. The entire startup pipeline runs unnecessarily:
1. `entry.ts` respawns the process with `--disable-warning=ExperimentalWarning` (~1.6s)
2. `run-main.ts` loads `program.js` which triggers `buildProgram()` — loading 87+ imports, 348 files, ~28MB of dist code (~3.3s)
3. `help.ts` finally catches `--version` and prints the version
## Fix
Added a 6-line early exit in `src/entry.ts` that checks for version flags *before* the process respawn. Uses a dynamic `import("./version.js")` which is lightweight (just reads `package.json` via `createRequire`).
**Before:** `openclaw --version` takes ~5s
**After:** `openclaw --version` takes <100ms
## Files Changed
- `src/entry.ts` — Added early exit for version flags before `ensureExperimentalWarningSuppressed()`
## Test plan
- [x] TypeScript compiles cleanly (no new errors)
- [x] Lint passes
- [x] Existing tests pass — the version check in `help.ts` remains as a harmless fallback
- [x] Behavior is identical: both paths use the same `VERSION` constant from `src/version.ts`
Closes #13133
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adds an early `--version`/`-v`/`-V` check in `src/entry.ts` so the CLI can print the version and exit before triggering the expensive experimental-warning respawn logic and before importing the main Commander/program modules. The intention is to make `openclaw --version` fast by only dynamically importing `src/version` instead of running the full startup pipeline.
<h3>Confidence Score: 3/5</h3>
- This PR is mergeable after confirming module format/top-level await compatibility for the distributed entrypoint.
- Change is small and targeted, but introducing top-level await in the CLI entrypoint can hard-break execution if the built entrypoint is ever CommonJS (or otherwise not TLA-capable) in any supported runtime/distribution path. That compatibility should be verified or avoided by rewriting without TLA.
- src/entry.ts
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#16710: feat: fast-path --version, --help, and no-args to skip full module ...
by xin-wen · 2026-02-15
80.9%
#13441: Optimise: CLI startup time optimizations
by TymekTM · 2026-02-10
78.6%
#13840: perf(cli): skip plugin loading during completion generation
by lailoo · 2026-02-11
76.4%
#23522: feat(cli): add --quiet flag and OPENCLAW_NO_TAGLINE env var (#22635)
by dissaozw · 2026-02-22
75.7%
#17237: fix(update): guard post-install imports after npm global update
by tdjackey · 2026-02-15
75.4%
#17962: fix(cli): speed up completion plugin loading
by forketyfork · 2026-02-16
74.9%
#16016: fix: update systemd unit version on gateway restart
by jbold · 2026-02-14
74.2%
#12987: fix(cli): exit process after successful command completion
by omair445 · 2026-02-10
74.0%
#23113: fix: show actual runtime version after update/restart when service ...
by BryanTegomoh · 2026-02-22
73.9%
#17680: perf(cli): skip plugin loading during completion generation
by mcrolly · 2026-02-16
73.8%