[BUG] Bash tool corrupts commands with multi-line + pipe, and $() in pipes

Resolved 💬 5 comments Opened Dec 28, 2025 by janbam Closed Feb 14, 2026

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?

The Bash tool has two command parsing bugs that corrupt commands:

Bug 1: Multi-line + Pipe
When bash input contains both newlines and a pipe (anywhere), commands get corrupted. The echo keyword becomes literal text, or subsequent commands are passed as arguments to previous commands.

Bug 2: $() in Pipes
Command substitution $(...) gets mangled into \$ ( ... ) with spaces and escaping when the command contains a pipe, causing syntax errors.

What Should Happen?

Multi-line bash commands with pipes should execute correctly, with each line running as a separate command. Command substitution $() should work in piped commands without being mangled.

Error Messages/Logs

# Bug 1: Multi-line + Pipe (NO $ involved)

## Test A: Pipe on second line
Input:
  echo "a"
  echo "b" | cat

Expected: a then b (on separate lines)
Actual output: a echo b
(The "echo" keyword becomes literal text!)

## Test B: Pipe on first line
Input:
  echo "a" | cat
  echo "b"

Actual error:
  cat: echo: No such file or directory
  cat: b: No such file or directory
(Subsequent commands passed as filenames to cat!)

## Test C: Pipes on both lines
Input:
  echo "a" | cat
  echo "b" | cat

Actual error:
  cat: echo: No such file or directory

---

# Bug 2: $() Mangling in Pipes

## Test: echo $(whoami) | head -1
/usr/bin/bash: eval: line 1: syntax error near unexpected token `('
/usr/bin/bash: eval: line 1: `echo \$ ( whoami ) < /dev/null | head -1'

## Test: size=$(du -sh /tmp | cut -f1)
/usr/bin/bash: eval: line 1: syntax error near unexpected token `('
/usr/bin/bash: eval: line 1: `size=\$ ( du -sh /tmp < /dev/null | cut -f1 )'

Steps to Reproduce

Bug 1: Multi-line + Pipe

  1. Start Claude Code
  2. Ask Claude to run a multi-line bash command containing a pipe, e.g.:

``
echo "a"
echo "b" | cat
``

  1. Observe corrupted output: a echo b instead of a then b

Bug 2: $() Mangling in Pipes

  1. Start Claude Code
  2. Ask Claude to run: echo $(whoami) | head -1
  3. Observe syntax error revealing the mangled command:

echo \$ ( whoami ) < /dev/null | head -1

Controls that work:

  • Single-line with pipe: echo "hello" | head -1
  • Multi-line without pipe: multiple echo commands ✓
  • $() without pipe: echo $(whoami)

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.0.76 (Claude Code)

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

Other

Additional Information

Terminal: Kitty (selected "Other" above)

Feedback ID: b2b45a09-6166-4572-bd59-c84425c414e6
(Also submitted via Claude Code's built-in /feedback command)

Note: This bug appears to be in the Bash tool's command parsing logic, specifically how it handles newlines and pipes. The error messages reveal an eval wrapper that mangles the commands.

View original on GitHub ↗

This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗