#11165: fix(cli): filter empty flags in zsh and PowerShell nested completion
cli
stale
Cluster:
Zsh and PowerShell Completion Fixes
## Summary
- `generateZshArgs` uses `flags.split(/[ ,|]+/)` without filtering, so `flags[0]` (the fallback when no `--` flag exists) can be an empty string when `opt.flags` starts with a space or delimiter
- `generatePowerShellCompletion` (nested commands at line 521) uses `flags.split(/[ ,|]+/)[0]` directly, same empty-string risk
- Apply `.filter(Boolean)` after `.split()` to skip empty strings, consistent with the existing fixes in bash and PowerShell root completion
## Test plan
- [x] Verified `.filter(Boolean)` removes empty strings from split result
- [x] Consistent with existing bash completion fix and PowerShell root completion fix
- [x] Pre-commit formatting passes
Generated with [Claude Code](https://claude.com/claude-code)
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates shell completion generation to avoid producing empty option tokens when an option’s `flags` string begins with whitespace or delimiters.
In `src/cli/completion-cli.ts`, `generateZshArgs` now applies `.filter(Boolean)` after splitting `opt.flags`, and the PowerShell nested-completion path applies the same filtering to the computed option list. This aligns zsh + nested PowerShell behavior with the existing bash/root PowerShell completion logic that already avoids empty tokens, preventing empty-string completions and malformed completion entries.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk.
- Change is narrowly scoped to completion script generation and only removes empty tokens from flag-splitting; no behavior changes outside completion output, and it matches existing patterns already used elsewhere in this file.
- No files require special attention
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#10723: fix(cli): filter empty flags in PowerShell completion generation
by Yida-Dev · 2026-02-06
93.4%
#10710: fix(cli): filter empty flags in bash completion generation
by Yida-Dev · 2026-02-06
92.3%
#17437: fix(completion): avoid rc=1 for optionless zsh leaf commands
by ephelia-ai · 2026-02-15
81.5%
#12308: fix(cli): redirect log output to stderr during completion script ge...
by mcaxtr · 2026-02-09
78.6%
#9148: Fix: Speed up shell completion generation from ~4.6s to <200ms
by vishaltandale00 · 2026-02-04
78.1%
#6382: fix(cli): silence Powerlevel10k Zsh warning from completion script
by dungngo4520 · 2026-02-01
77.8%
#13840: perf(cli): skip plugin loading during completion generation
by lailoo · 2026-02-11
77.7%
#17680: perf(cli): skip plugin loading during completion generation
by mcrolly · 2026-02-16
76.9%
#17325: fix(completion): avoid zsh compdef error when compinit is not initi...
by ephelia-ai · 2026-02-15
76.6%
#22488: fix(cli): redirect plugin logs to stderr during completion
by pierreeurope · 2026-02-21
76.4%