#6694: fix: Cache completion install
cli
Cluster:
Completion Performance Improvements
## Summary
- cache generated completion scripts under ~/.openclaw/completions and source them
- migrate legacy process-substitution lines during install
- add install/migration/idempotency tests
## Why
Running `openclaw completion --shell zsh` on every shell startup costs ~1–2s; this makes completion load instant after the first install.
## Testing
- pnpm vitest src/cli/completion-cli.test.ts
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adds a completion install flow that caches generated completion scripts under `~/.openclaw/completions/<bin>.<shell>` and updates shell profile files to `source` the cached file, including migration from legacy process-substitution / pipe-to-source lines. It also adds Vitest coverage for install, legacy migration, binName handling, fish/bash variants, and idempotency.
The change fits into the CLI by extending the existing `completion` subcommand in `src/cli/completion-cli.ts` to optionally install completions and by introducing helpers for generating scripts, writing cached files, and updating profile contents.
<h3>Confidence Score: 3/5</h3>
- Mostly safe to merge, but install idempotency has an unintended side effect (rewriting cached scripts even when no profile changes are needed).
- The change is localized to the completion CLI and is covered by tests, but the current install flow writes the cached completion file before the early-return checks, which can cause unexpected overwrites/timestamps and contradicts the intended no-op behavior.
- src/cli/completion-cli.ts
<!-- greptile_other_comments_section -->
**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
#9158: perf(completion): add fast path for cached completions
by gavinbmoore · 2026-02-04
86.2%
#9148: Fix: Speed up shell completion generation from ~4.6s to <200ms
by vishaltandale00 · 2026-02-04
84.3%
#16908: fix(cli): clean stale shell completion profile entries on uninstall...
by lorstyang · 2026-02-15
81.6%
#17680: perf(cli): skip plugin loading during completion generation
by mcrolly · 2026-02-16
80.1%
#12308: fix(cli): redirect log output to stderr during completion script ge...
by mcaxtr · 2026-02-09
80.0%
#17962: fix(cli): speed up completion plugin loading
by forketyfork · 2026-02-16
79.8%
#13840: perf(cli): skip plugin loading during completion generation
by lailoo · 2026-02-11
79.8%
#6382: fix(cli): silence Powerlevel10k Zsh warning from completion script
by dungngo4520 · 2026-02-01
79.3%
#6888: feat: PowerShell completion install/uninstall + templates script + ...
by ThinkIbrokeIt · 2026-02-02
77.6%
#17325: fix(completion): avoid zsh compdef error when compinit is not initi...
by ephelia-ai · 2026-02-15
76.2%