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.

Steps to generate shell completions for Codex:

  1. 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.

  2. 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 codex

    Replace zsh with bash, elvish, fish, or powershell when needed. If you omit the shell name, Codex currently generates Bash completions by default.

  3. 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.

  4. 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 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.