Command completion in Zsh depends on the shell's completion system being initialized before the terminal can suggest subcommands, files, options, and command-specific arguments. Without that setup, pressing Tab may fall back to basic filename completion or show no command-aware choices.

The completion system is loaded with autoload -Uz compinit and initialized with compinit. During initialization, Zsh scans the completion function path and writes a dump file so later interactive shells can start faster. The -d option names that dump file explicitly.

Keep this setup in ~/.zshrc because completion is an interactive shell feature. A new interactive Zsh process should then register built-in command completions such as cd_completion=_cd and create the configured .zcompdump file. If Zsh reports insecure completion directories, inspect them with compaudit and correct ownership or permissions before bypassing the warning.

Steps to enable command completion in Zsh:

  1. Confirm that Zsh is available.
    $ zsh --version
    zsh 5.9 (aarch64-unknown-linux-gnu)
  2. Back up ~/.zshrc before editing completion setup.
    $ cp ~/.zshrc ~/.zshrc.bak

    If ~/.zshrc does not exist yet, create it with touch ~/.zshrc and skip the backup.

  3. Add the completion initialization lines to ~/.zshrc.
    ~/.zshrc
    autoload -Uz compinit
    compinit -d "${ZDOTDIR:-$HOME}/.zcompdump"

    The -d path keeps the completion dump under the active Zsh config directory when ZDOTDIR is set, and under the home directory otherwise.

  4. Check the edited file for syntax errors.
    $ zsh -n ~/.zshrc

    No output from zsh -n means Zsh parsed the startup file without finding a syntax error.

  5. Start a new interactive Zsh process and confirm that completion data loaded.
    $ zsh -ic 'print cd_completion=${_comps[cd]:-missing}'
    cd_completion=_cd

    The cd_completion=_cd output shows that Zsh registered the built-in completion function for cd.

  6. Confirm that the completion dump file exists after initialization.
    $ ls -l "${ZDOTDIR:-$HOME}/.zcompdump"
    -rw-r--r-- 1 operator operator 50559 Jun  5 08:19 /home/operator/.zcompdump
  7. Run compaudit if compinit reports insecure directories.
    $ zsh -ic 'compaudit'

    No output means compaudit did not list insecure completion paths.

    Do not silence insecure-directory warnings until the listed directories are owned by the expected user or by root and are not writable by other users.