#19109: fix(completion): initialize compinit before compdef
cli
size: XS
trusted-contributor
Cluster:
Zsh and PowerShell Completion Fixes
If compdef is not loaded, the zsh completion script fails silently.
Fix: Check for compdef and initialize compinit if needed.
Recreated from #17922 with only the relevant file.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Adds initialization guard for zsh completion system to prevent silent failures. The PR adds a check for `compdef` availability and initializes `compinit` if needed before defining completions, ensuring the completion script works even when run before the shell's completion system is loaded. Also includes a minor import reordering (commander imports moved to top).
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The change is well-scoped, fixes a real issue with zsh completion initialization, follows standard zsh completion patterns, and only modifies the generated completion script. The implementation is defensive (checks for compdef before calling compinit) and will not break existing working setups.
- No files require special attention
<sub>Last reviewed commit: 4b8f457</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#17325: fix(completion): avoid zsh compdef error when compinit is not initi...
by ephelia-ai · 2026-02-15
90.7%
#20553: fix(completion): guard zsh compdef call for environments without co...
by mr-sk · 2026-02-19
88.1%
#18938: fix(completion): avoid compdef error in zsh by guarding completion ...
by gcsenyan · 2026-02-17
87.7%
#6382: fix(cli): silence Powerlevel10k Zsh warning from completion script
by dungngo4520 · 2026-02-01
77.6%
#17437: fix(completion): avoid rc=1 for optionless zsh leaf commands
by ephelia-ai · 2026-02-15
76.0%
#12308: fix(cli): redirect log output to stderr during completion script ge...
by mcaxtr · 2026-02-09
74.5%
#22488: fix(cli): redirect plugin logs to stderr during completion
by pierreeurope · 2026-02-21
74.3%
#9148: Fix: Speed up shell completion generation from ~4.6s to <200ms
by vishaltandale00 · 2026-02-04
74.1%
#6694: fix: Cache completion install
by s0up4200 · 2026-02-01
73.1%
#11165: fix(cli): filter empty flags in zsh and PowerShell nested completion
by Yida-Dev · 2026-02-07
72.8%