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.
Related: How to check Codex CLI version
Related: How to run Codex exec with a prompt
Steps to generate Codex shell completions:
- Create a completion directory for zsh in the home directory.
$ mkdir -p ~/.zsh/completions
- 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.
- 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.
- 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
- 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.
- 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
- 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.
- 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
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
