[BUG] Shell initialization fails (exit 127) when .bashrc contains extglob pattern inside command substitution in function definition

Resolved 💬 3 comments Opened Mar 5, 2026 by douglaswth Closed May 4, 2026

Preflight Checklist

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

What's Wrong?

When ~/.bashrc contains a bash extglob pattern inside a command substitution ($(...)) inside a function definition, Claude Code's shell initialization fails completely.
All Bash tool invocations return exit code 127 ("command not found") for every command, including basic ones like echo and ls.

What Should Happen?

Claude Code should initialize its shell successfully regardless of extglob patterns used in .bashrc function definitions. Standard bash -c 'source ~/.bashrc' handles this fine.

Error Messages/Logs

Steps to Reproduce

  1. Add the following to ~/.bashrc:
shopt -s extglob

f() {
    echo "$(cat +([[:xdigit:]]).json 2>/dev/null)"
}
  1. Start claude
  2. Try any Bash tool invocation (e.g. echo hello)
  3. Observe exit code 127

Note: the function does not need to be called — merely being defined triggers the bug. Replacing +([[:xdigit:]]) with a simple glob like *.json avoids the issue.

Claude Model

Opus

Is this a regression?

Yes, this worked in a previous version

Last Working Version

2.1.50

Claude Code Version

2.1.69

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

Windows Terminal

Additional Information

  • The real-world trigger was compgen -G "$dir"/+([[:xdigit:]]).json and cat "$dir"/+([[:xdigit:]]).json | jq ... inside prompt functions in .bashrc
  • Workaround: replace extglob patterns with simple globs (e.g. [[:xdigit:]]*.json)
  • bash -c 'source ~/.bashrc' works fine, suggesting Claude Code's shell initialization parses the file differently than standard bash

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗