Bash tool: environment variables and command substitution break when piping
Resolved 💬 3 comments Opened Feb 1, 2026 by Butanium Closed Feb 1, 2026
Description
Environment variables ($USER, $PWD, $HOME) and command substitution ($(whoami), backticks) become empty/fail when the bash command includes a pipe (|).
Reproduction
Works (no pipe):
echo "user is $USER"
# Output: user is myusername
echo "pwd is $(pwd)"
# Output: pwd is /home/myusername
Broken (with pipe):
echo "user is $USER" | head -1
# Output: user is
# (variable is empty!)
echo "user is $(whoami)" | head -1
# Output: (completely empty)
ls -la $(pwd) | head -5
# Output: (empty)
Workaround:
bash -c 'echo "user is $USER" | head -1'
# Output: user is myusername
# (works when wrapped in bash -c with single quotes)
Impact
This affects any piped command that uses variables or command substitution, e.g.:
squeue -u $USER | head -10ps aux | grep $(whoami)find $HOME -name "*.txt" | head
Environment
- Claude Code version: 2.1.29
- OS: Ubuntu 22.04 (Linux 6.8.0-60-generic x86_64)
- Bash version: 5.1.16(1)-release
🤖 Generated with Claude Code
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗