[BUG] Shell initialization fails (exit 127) when .bashrc contains extglob pattern inside command substitution in function definition
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
- Add the following to
~/.bashrc:
shopt -s extglob
f() {
echo "$(cat +([[:xdigit:]]).json 2>/dev/null)"
}
- Start claude
- Try any Bash tool invocation (e.g.
echo hello) - 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:]]).jsonandcat "$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
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗