Skip to content

[Bug]: zsh completion fails with command not found: compdef unless compinit is initialized first #14289

Description

@imaddar
### Summary

Using the zsh completion snippet:

```zsh
source <(openclaw completion --shell zsh)

causes this error on shell startup:

command not found: compdef

Environment

  • OpenClaw: 2026.1.30
  • Shell: zsh
  • OS: macOS

Reproduction

  1. In .zshrc, add:
    source <(openclaw completion --shell zsh)
  2. Do not run compinit before this line.
  3. Start a new zsh session.
  4. Observe: command not found: compdef.

Expected behavior

Completion should load cleanly, or docs/setup should clearly state that compinit must be initialized first.

Actual behavior

The generated completion uses compdef, which is unavailable unless zsh completion is initialized.

Workaround

This fixes it:

autoload -Uz compinit
compinit
source <(openclaw completion --shell zsh)

(optional guard)

if command -v openclaw >/dev/null 2>&1; then
  source <(openclaw completion --shell zsh)
fi

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstaleMarked as stale due to inactivity

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions