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
Steps to generate shell completions for Codex:
- Check the current Codex completion syntax and supported shell names.
$ 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.
- Generate the completion script for the shell you want Codex to complete.
$ 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 codexReplace zsh with bash, elvish, fish, or powershell when needed. If you omit the shell name, Codex currently generates Bash completions by default.
- Save the generated script to a file when you want to reuse or install it later.
$ 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.
- Open the saved file and confirm it contains the Codex completion binding.
$ cat _codex #compdef codex autoload -U is-at-least _codex() { ##### snipped ##### compdef _codex codexThe final compdef _codex codex line is the zsh binding that tells the shell to use the generated _codex function for the codex command.
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.
