#17437: fix(completion): avoid rc=1 for optionless zsh leaf commands
cli
stale
size: XS
Cluster:
Zsh and PowerShell Completion Fixes
## Summary
- fix zsh completion generation for leaf commands that have no options
- avoid emitting an empty `_arguments -C` block for those leaves
- emit a no-op leaf function (`return 0`) instead
- add a regression test in `src/wizard/onboarding.completion.test.ts`
## Why
Some generated zsh leaf functions ended up with an empty `_arguments -C` body, which returned non-zero (rc=1) when invoked. This makes completion behavior brittle for optionless leaf commands.
## Verification
- `npx pnpm vitest src/wizard/onboarding.completion.test.ts` ✅
- `npx pnpm exec oxfmt --check src/cli/completion-cli.ts src/wizard/onboarding.completion.test.ts` ✅
- `npx pnpm exec oxlint --type-aware src/cli/completion-cli.ts src/wizard/onboarding.completion.test.ts` ✅
- manual repro with generated mini zsh completion: `_openclaw_config_unset` returns `rc:0` ✅
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Fixed zsh completion generation for leaf commands without options by emitting a no-op function (`return 0`) instead of an empty `_arguments -C` block that would fail with rc=1.
- Refactored `generateZshSubcommands` to handle three cases: commands with subcommands, leaf commands with options, and leaf commands without options
- Added regression test to verify no-op function generation for optionless commands
- Optimized argument line generation to avoid trailing backslash when no args exist
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The fix is surgical and well-targeted: it addresses a specific bug in zsh completion generation for optionless leaf commands, includes a regression test, and follows the existing code patterns. The logic flow is correct across all three cases (commands with subcommands, leaf with options, leaf without options).
- No files require special attention
<sub>Last reviewed commit: e949bf7</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#11165: fix(cli): filter empty flags in zsh and PowerShell nested completion
by Yida-Dev · 2026-02-07
81.5%
#17325: fix(completion): avoid zsh compdef error when compinit is not initi...
by ephelia-ai · 2026-02-15
80.6%
#18938: fix(completion): avoid compdef error in zsh by guarding completion ...
by gcsenyan · 2026-02-17
79.9%
#20553: fix(completion): guard zsh compdef call for environments without co...
by mr-sk · 2026-02-19
79.8%
#6382: fix(cli): silence Powerlevel10k Zsh warning from completion script
by dungngo4520 · 2026-02-01
79.0%
#9148: Fix: Speed up shell completion generation from ~4.6s to <200ms
by vishaltandale00 · 2026-02-04
78.6%
#12308: fix(cli): redirect log output to stderr during completion script ge...
by mcaxtr · 2026-02-09
78.6%
#13840: perf(cli): skip plugin loading during completion generation
by lailoo · 2026-02-11
77.1%
#17680: perf(cli): skip plugin loading during completion generation
by mcrolly · 2026-02-16
77.0%
#10710: fix(cli): filter empty flags in bash completion generation
by Yida-Dev · 2026-02-06
76.9%