claude-code - 💡(How to fix) Fix [BUG] Bash tool fails with exit 127 when shell snapshot replays extglob syntax in non-interactive bash 5

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

Error Messages/Logs

The 2>/dev/null swallows the parse error. The function (e.g. get_modules from bash-completion v1's cvs module) is

Root Cause

Two pieces both miss the fix:

  1. Snapshot capture should shopt -s extglob before emitting function definitions.
  2. The source-wrapper command should shopt -s extglob before the source, not unset it after.

Workaround

brew uninstall bash-completion && brew install bash-completion@2 — v2 is the supported package on bash 4+/5 and doesn't use the problematic syntax. Or add shopt -s extglob to the user's shell rc.

Fix Action

Fix / Workaround

Workaround

Code Example

The wrapper command is constructed like:
  source SNAPSHOT 2>/dev/null || true && { shopt -u extglob ...; } && eval '<actual command>'
  The 2>/dev/null swallows the parse error. The function (e.g. get_modules from bash-completion v1's cvs module) is
  never defined, so the actual command fails with exit 127.

  bash -x trace narrows the parse failure to the !(CVSROOT) extglob syntax in bash-completion v1's cvs module — fails
  to parse because extglob defaults off in non-interactive bash 5.
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

The shell snapshot replayer fails to parse extglob syntax in captured function bodies when run in non-interactive bash 5, causing the bash tool to exit with code 127.

What Should Happen?

The bash tool should execute commands successfully. The snapshot replayer should handle bash functions that use extglob syntax — common in bash-completion modules and other shell environments where extglob is on by default in interactive bash.

Error Messages/Logs

The wrapper command is constructed like:
  source SNAPSHOT 2>/dev/null || true && { shopt -u extglob ...; } && eval '<actual command>'
  The 2>/dev/null swallows the parse error. The function (e.g. get_modules from bash-completion v1's cvs module) is
  never defined, so the actual command fails with exit 127.

  bash -x trace narrows the parse failure to the !(CVSROOT) extglob syntax in bash-completion v1's cvs module — fails
  to parse because extglob defaults off in non-interactive bash 5.

Steps to Reproduce

  1. macOS, bash 5
  2. brew install bash-completion (v1 — note: v2 doesn't have this issue)
  3. Start Claude Code
  4. Any bash tool call fails with exit 127

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.136 - @anthropic-ai/claude-code

Platform

Other

Operating System

macOS

Terminal/Shell

iTerm2

Additional Information

Root cause

Two pieces both miss the fix:

  1. Snapshot capture should shopt -s extglob before emitting function definitions.
  2. The source-wrapper command should shopt -s extglob before the source, not unset it after.

Workaround

brew uninstall bash-completion && brew install bash-completion@2 — v2 is the supported package on bash 4+/5 and doesn't use the problematic syntax. Or add shopt -s extglob to the user's shell rc.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING