Generating shell completions for Codex lets your shell suggest subcommands, flags, and argument values as you type. That reduces typing mistakes and makes the current CLI surface easier to discover from the terminal.
The current Codex CLI exposes this through codex completion [SHELL]. It can print completion scripts for bash, elvish, fish, powershell, and zsh, and it writes the generated script to stdout so you can inspect it or redirect it into a file.
The generated script only reflects the version of Codex that produced it, so regenerate it after upgrades if commands or flags change. Generating the script does not edit your shell configuration or install the file automatically, which keeps this workflow safe to run in any terminal session.
Related: How to install Codex CLI with Homebrew
Related: How to upgrade Codex CLI with Homebrew
$ codex completion --help
Generate shell completion scripts
Usage: codex completion [OPTIONS] [SHELL]
Arguments:
[SHELL]
Shell to generate completions for
[default: bash]
[possible values: bash, elvish, fish, powershell, zsh]
Options:
##### snipped #####
The current CLI uses codex completion for this job, and the help output shows the valid shell names for your installed version.
$ codex completion zsh
#compdef codex
autoload -U is-at-least
_codex() {
typeset -A opt_args
typeset -a _arguments_options
local ret=1
##### snipped #####
compdef _codex codex
Replace zsh with bash, elvish, fish, or powershell when needed. If you omit the shell name, Codex currently generates Bash completions by default.
$ codex completion zsh > _codex
This step only writes the completion script to disk. Place that file in your shell's normal completion path or source it manually in a separate install step.
$ cat _codex
#compdef codex
autoload -U is-at-least
_codex() {
##### snipped #####
compdef _codex codex
The final compdef _codex codex line is the zsh binding that tells the shell to use the generated _codex function for the codex command.