[BUG] Newlines stripped in for loops with pipes
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?
Multi-line for loops that contain pipe characters in the loop body fail with "unexpected end of file" syntax errors. The newlines are being incorrectly removed when Claude Code processes these commands, causing bash to see an incomplete loop structure.
What Should Happen?
Ideally, Claude should execute the command that it actually displays when it asks for permission to run it; or, failing that, it should replace newlines with semicolons to keep the syntax intact.
Error Messages/Logs
/opt/homebrew/bin/bash: eval: line 2: syntax error:
unexpected end of file from `for' command on line 1
Steps to Reproduce
for i in a b c; do
echo "test" | cat
done
Claude Model
Sonnet (default)
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.0.35 (Claude Code)
Platform
AWS Bedrock
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
When Claude Code transforms the command for execution via eval, it appears to be stripping newlines or improperly joining lines when a pipe character is present. This causes bash to interpret the multi-line loop as a single incomplete line. I have occasionally persuaded Claude to add semicolons where the newlines were to fix the syntax, but it seems impossible to get this fix to stick. (Perhaps note that while semicolon _generally_ is equivalent to newline, there should be no semicolon after do or then or possibly a few other keywords.)
This seems vaguely related to #7387, #10350, #10153 etc but I have not found a report of this specific error.
This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗