#6378: fix(cli): escape brackets in zsh completion option descriptions
cli
Cluster:
Zsh and PowerShell Completion Fixes
## Summary
Fixes zsh completion parser error when tab-completing commands with options that have quotes or special characters in their descriptions.
## Problem
When running `openclaw gateway res<TAB>`, zsh reports:
```
_arguments:comparguments:327: invalid option definition: --compact[Alias for --ws-log
```
**Root Cause:** The `generateZshArgs` function was not escaping special characters in option descriptions. Options like `--ws-log` with descriptions containing quotes like `("auto"|"full"|"compact")` broke zsh's `_arguments` parser when embedded in double-quoted strings.
Example of broken output:
```zsh
"--ws-log[WebSocket log style ("auto"|"full"|"compact")]"
↑ unescaped quotes break parsing
```
## Solution
Added proper escaping for all special characters in option descriptions:
```typescript
const desc = opt.description
.replace(/\\/g, "\\\\") // Backslashes (must be first!)
.replace(/"/g, "\\\"") // Double quotes (main issue)
.replace(/'/g, "'\\''") // Single quotes
.replace(/\[/g, "\\[") // Square brackets
.replace(/\]/g, "\\]");
```
**Key insight:** Escaping order matters - backslash must be escaped first to avoid double-escaping other characters.
Now generates correctly escaped output:
```zsh
"--ws-log[WebSocket log style (\"auto\"|\"full\"|\"compact\")]"
```
## Testing
1. ✅ Built and verified the generated completion script properly escapes all special chars
2. ✅ Manual test: `source <(openclaw completion --shell zsh)` loads without errors
3. ✅ Tab completion now works: `openclaw gateway res<TAB>` completes successfully
4. ✅ Existing tests pass
## Related
- Fixes completion errors for any option with special characters in descriptions
- Aligns with proper zsh `_arguments` escaping requirements
- Follows similar pattern to `generateZshSubcmdList` but adds quote escaping
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Most Similar PRs
#17437: fix(completion): avoid rc=1 for optionless zsh leaf commands
by ephelia-ai · 2026-02-15
71.6%
#9148: Fix: Speed up shell completion generation from ~4.6s to <200ms
by vishaltandale00 · 2026-02-04
71.1%
#18938: fix(completion): avoid compdef error in zsh by guarding completion ...
by gcsenyan · 2026-02-17
70.8%
#11165: fix(cli): filter empty flags in zsh and PowerShell nested completion
by Yida-Dev · 2026-02-07
70.3%
#20553: fix(completion): guard zsh compdef call for environments without co...
by mr-sk · 2026-02-19
70.1%
#22488: fix(cli): redirect plugin logs to stderr during completion
by pierreeurope · 2026-02-21
68.3%
#12308: fix(cli): redirect log output to stderr during completion script ge...
by mcaxtr · 2026-02-09
67.7%
#17680: perf(cli): skip plugin loading during completion generation
by mcrolly · 2026-02-16
67.0%
#17325: fix(completion): avoid zsh compdef error when compinit is not initi...
by ephelia-ai · 2026-02-15
66.7%
#13840: perf(cli): skip plugin loading during completion generation
by lailoo · 2026-02-11
66.6%