Shell snapshot generation fails on extglob-dependent functions (e.g. bash-completion realpath)

Open 💬 0 comments Opened Aug 2, 2026 by DnaMes

Description

Codex CLI's shell snapshot bootstrap (used to give the sandboxed shell your interactive functions/aliases) crashes when the login shell has functions that rely on extglob patterns, because the snapshot generator dumps declare -f output without first running shopt -s extglob in the context that re-sources it.

Repro

Any system with bash-completion installed defines a realpath-style helper using extglob patterns like:

case $REPLY in
    */./*) ... ;;
    */.) ... ;;
    /..?(/*))
        REPLY=${REPLY#/..}
    ;;
    */+([^/])/../*) ... ;;
esac

This is valid bash only when extglob is enabled at parse time (interactive bash-completion enables it). When Codex captures the shell state via declare -f and replays it into a snapshot script without enabling extglob first, parsing the snapshot fails:

codex_core::shell_snapshot: Shell snapshot validation failed: Snapshot command exited with status exit status: 2: /home/<user>/.codex/shell_snapshots/<uuid>.tmp-<pid>: line 900: syntax error near unexpected token `('

Minimal local reproduction of the underlying parse failure:

bash -n <(bash -lc 'declare -f')
# /dev/fd/63: line 897: syntax error near unexpected token `('
# /dev/fd/63: line 897: `            /..?(/*))'

Impact

Any tool that shells out to codex exec (e.g. custom delegate/routing wrappers) fails outright with the above error whenever the invoking shell has bash-completion (or any other extglob-dependent function) loaded — which is the Linux distro default in many environments (confirmed on Fedora).

Expected

The shell snapshot generator should either:

  • shopt -s extglob (and any other relevant shell option) before re-parsing captured function definitions, or
  • Skip/guard functions it can't safely re-parse instead of failing the whole snapshot, or
  • Capture/replay shopt -p state alongside declare -f so parsing context matches the original shell.

Environment

  • codex-cli 0.146.0
  • OS: Fedora Linux (bash-completion package installed)
  • Shell: bash

Repro snippet to confirm root cause

shopt -s extglob
bash -n <(bash -lc 'declare -f')   # succeeds

View original on GitHub ↗