[BUG] Environment variables expand to empty strings when used as command arguments in Bash tool
Resolved 💬 3 comments Opened Oct 2, 2025 by garfazadeh Closed Oct 6, 2025
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?
Environment variables are successfully loaded into Claude Code's Bash tool environment (confirmed via env | grep), but they expand to empty strings when used as command arguments.
What Should Happen?
Variables should expand to their values when used as command arguments, just as they do in direct echo statements, subshells, and new bash processes.
Error Messages/Logs
Steps to Reproduce
- Set environment variables in shell snapshot (e.g., via
.zshenv) - Verify variable is loaded:
env | grep MY_API_KEY(shows correct value) - Try using in command:
some-cli --api-key "$MY_API_KEY" --action list - Observe with debugging:
set -x; some-cli --api-key "$MY_API_KEY" - See output shows:
+(eval):1> some-cli --api-key '' --action list
Claude Model
Sonnet (default)
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.0.2 (Claude Code)
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Other
Additional Information
Variables work correctly in:
- echo "$MY_VAR"
- $(echo $MY_VAR)
- bash -c 'echo "$MY_VAR"'
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗