[BUG] Claude code chokes on bash commands with pipes
Resolved 💬 4 comments Opened Apr 12, 2025 by dasrfp Closed Apr 18, 2025
Environment
- Platform (select one):
- [ ] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [x] Other: Code
- Claude CLI version:
0.2.69 (Claude Code) - Operating System: Pop!_OS 22.04 LTS (Ubuntu derivative)
- Terminal: gnome-terminal
Bug Description
Claude Code chokes on bash command lines with pipes
Steps to Reproduce
- Have claude run any command with a pipeline (for example,
echo test|grep test) - Claude throws an error
Expected Behavior
For the example above, the output should be "test"
Actual Behavior
output is Error in red. Claude tries to cope by constructing a new command to run (usually with a pipe which fails again).
Additional Context
Screenshot:
!Image
Text of screenshot:
● Very interesting! It looks like:
1. Basic echo commands with escaped quotes or pipe characters work fine
2. Simple redirections like > and && work correctly
3. Actual pipes (|) in command execution fail
Let's test one more thing to confirm the issue is specifically with pipes:
● Bash(find docs -name "*.md" | grep -v "archive" | head -3)…
⎿
Shell cwd was reset to /var/www/casetrack
● It definitely appears that the issue is with pipes (|) in Bash commands. The tool seems to have trouble handling command pipelines. This helps narrow down the bug - it's specifically
related to how pipes are processed in the Bash tool implementation, not with escaping or quotes.
Based on this testing, we should focus on single commands or use command chaining with && when possible, rather than trying to use pipes.
> so for example `echo test|grep test` gives you no output?
● Let me try that specific example:
● Bash(echo test|grep test)…
⎿ Error
● Yes, exactly. The command echo test|grep test gives an error instead of the expected output "test". This confirms that the issue is with pipe operations in the Bash tool.
It seems that any command that uses the pipe operator (|) to connect commands is not working correctly, while other types of command chaining (like using &&) do work properly.
> can you escape the pipe maybe? I wonder if you run `echo test \|grep test` what you'd get
● Let me try escaping the pipe character to see if that works:
● Bash(echo test \|grep test)…
⎿ Error
● Bash(echo "test \|grep test")…
⎿ test \|grep test
⎿
Shell cwd was reset to /var/www/casetrack
● Interesting. Escaping the pipe character doesn't help with execution - it still gives an error. When I put the escaped pipe in quotes, it just echoes the literal text as expected.
It seems the issue is not with the parsing of the pipe character itself, but likely with how the Bash tool handles connecting multiple commands together through pipes.
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ > │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗