Shell completions for Codex speed up command entry, reduce typos, and make flags and subcommands easier to discover during interactive terminal work.

The codex completion command prints a completion script for a specific shell (bash, zsh, fish, PowerShell, or elvish). For zsh, the completion system loads functions from directories listed in fpath and initializes them with compinit, so placing the script in a directory on fpath enables tab-completion for the codex command.

Completion scripts are best stored in a user-owned directory so package upgrades do not overwrite custom settings. The completion directory must be added to fpath before compinit runs, and the shell session must be reloaded (or restarted) to activate the new completion function.

Steps to generate Codex shell completions:

  1. Create a completion directory for zsh in the home directory.
    $ mkdir -p ~/.zsh/completions
  2. Write the Codex completion script to the zsh completion directory.
    $ codex completion zsh > ~/.zsh/completions/_codex

    zsh completion functions use the _command naming convention, so _codex maps to codex.

  3. Load the completion script directly from the CLI when you prefer a lightweight setup.
    $ eval "$(codex completion zsh)"

    Add the eval line to ~/.zshrc if you want it applied automatically for new shells.

  4. Verify the completion script file exists and is not empty.
    $ ls -l ~/.zsh/completions/_codex
    -rw-r--r--  1 user  user  118091 Jan 19 11:50 /home/user/.zsh/completions/_codex
  5. Add the completion directory to the zsh fpath before compinit in ~/.zshrc.
    fpath=(~/.zsh/completions $fpath)
    autoload -Uz compinit
    compinit

    If ~/.zshrc already runs compinit, keep the existing compinit lines and add only the fpath=(...) line above them.

  6. Confirm the completion directory appears in fpath.
    $ print -l $fpath | head -n 3
    /home/user/.zsh/completions
    /usr/local/share/zsh/site-functions
    /usr/share/zsh/site-functions
  7. Reload the zsh configuration to activate the completion function.
    $ source ~/.zshrc

    Use exec zsh for a clean reload when source re-runs plugin managers or prompts.

  8. Confirm zsh can locate the _codex completion function via fpath.
    $ whence -v _codex
    _codex is an autoload shell function from /home/user/.zsh/completions/_codex