Bash tool: Environment variables stripped when command contains pipes
Resolved 💬 3 comments Opened Dec 17, 2025 by hjtran Closed Dec 21, 2025
Bug Description
When using the Bash tool with a command that contains a pipe (|), environment variables (e.g., $HOME, $PATH, $USER) are replaced with empty strings before execution.
Steps to Reproduce
Copy and paste this prompt into any Claude Code session:
I need you to help me test a potential bug in Claude Code's Bash tool. Please run these commands exactly as written and report the results.
Test 1: Without pipe
echo "HOME=$HOME"
Test 2: With pipe
echo "HOME=$HOME" | cat
Test 3: Workaround
bash -c 'echo "HOME=$HOME"' | cat
The bug hypothesis is: When a Bash command contains a pipe (|), environment variables like $HOME are replaced with empty strings before execution.
Expected results if the bug exists:
- Test 1: Shows the full path (e.g., HOME=/Users/yourname)
- Test 2: Shows just HOME= with no value
- Test 3: Shows the full path again (workaround works)
Please run all three tests and tell me what you observe.
Expected Behavior
All three tests should output the full path:
HOME=/Users/username
Actual Behavior
- Test 1:
HOME=/Users/jtran✓ (works correctly) - Test 2:
HOME=✗ (variable stripped to empty string) - Test 3:
HOME=/Users/jtran✓ (workaround succeeds)
Impact
This bug affects any command that needs to:
- Use environment variables (like
$HOME,$PATH,$USER) - Pipe output to another command
Common examples that would fail:
echo $PATH | tr ':' '\n'
ls $HOME/Documents | grep pattern
cat $HOME/.bashrc | head -10
Workaround
Wrap the command in bash -c '...' with single quotes:
bash -c 'echo $PATH | tr ":" "\n"'
bash -c 'ls $HOME/Documents | grep pattern'
Environment
- OS: macOS (Darwin 24.6.0)
- Claude Code version: Latest (as of 2025-12-17)
- Model: Claude Sonnet 4.5
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗