← Back to PRs

#13840: perf(cli): skip plugin loading during completion generation

by lailoo open 2026-02-11 03:01 View on GitHub →
cli stale size: S trusted-contributor
## Summary Fixes #13810 ## Problem `openclaw completion --shell bash` (and zsh) takes ~24 seconds because it eagerly registers all subcommands, including `pairing` and `plugins` which call `registerPluginCliCommands()`. This triggers the full plugin loader via `jiti`, which Babel-transpiles ~423 files at runtime. This makes `source <(openclaw completion --shell bash)` in `.bashrc`/`.zshrc` add ~24s to every new shell session. **Root cause** in `src/cli/program/register.subclis.ts`: ```typescript // pairing entry (line 178-179) const { registerPluginCliCommands } = await import("../../plugins/cli.js"); registerPluginCliCommands(program, await loadConfig()); // ~24s jiti hit // plugins entry (line 190-191) const { registerPluginCliCommands } = await import("../../plugins/cli.js"); registerPluginCliCommands(program, await loadConfig()); // ~24s jiti hit ``` ## Fix Set `OPENCLAW_COMPLETION_MODE=1` during completion generation and check it in the `pairing` and `plugins` registration entries to skip plugin loading. The core CLI structure (`pairing-cli`, `plugins-cli`) is still registered so completion includes those commands. **completion-cli.ts:** ```typescript process.env.OPENCLAW_COMPLETION_MODE = "1"; // ... register all subcommands ... delete process.env.OPENCLAW_COMPLETION_MODE; ``` **register.subclis.ts (pairing & plugins entries):** ```typescript if (!isTruthyEnvValue(process.env.OPENCLAW_COMPLETION_MODE)) { const { registerPluginCliCommands } = await import("../../plugins/cli.js"); registerPluginCliCommands(program, await loadConfig()); } ``` ## Effect on User Experience **Before fix:** ```bash time openclaw completion --shell bash > /dev/null # real 0m23.991s ``` **After fix:** ```bash time openclaw completion --shell bash > /dev/null # real ~2s (no jiti transpilation) ``` - `openclaw pairing` and `openclaw plugins` commands work normally (plugins load as before) - Shell startup with `source <(openclaw completion --shell bash)` drops from ~24s to ~2s ## Testing - ✅ 6 tests pass (pnpm vitest run src/cli/program/register.subclis.test.ts) - ✅ Lint passes - ✅ New tests verify plugin loading is skipped in completion mode - ✅ New tests verify plugin loading works normally outside completion mode <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> Performance optimization that reduces shell completion generation time from ~24s to ~2s by skipping plugin loading during `openclaw completion` execution. Uses `OPENCLAW_COMPLETION_MODE` environment variable to conditionally bypass `registerPluginCliCommands()` calls in `pairing` and `plugins` subcommand registration. The command structure is still registered for completion purposes, but the expensive jiti transpilation of ~423 plugin files is avoided. Normal command execution outside completion mode remains unchanged with full plugin loading. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - Well-scoped performance fix with comprehensive test coverage, clear problem/solution description, and no logical errors. The environment variable approach is thread-safe within the synchronous registration flow, and the optimization only affects completion generation without impacting normal command execution. - No files require special attention <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs