[BUG] Bash tool mangles heredoc syntax at command level

Resolved 💬 3 comments Opened Jul 24, 2025 by thomastthai Closed Jan 4, 2026

Environment

  • Platform (select one):
  • [ ] Anthropic API
  • [ ] AWS Bedrock
  • [ ] Google Vertex AI
  • [X] Other: Max 200 Plan
  • Claude CLI version: v1.0.59
  • Operating System: macOS 15.5
  • Terminal: Ghostty

Bash tool mangles heredoc syntax at command level

Description

The Bash tool's execution environment incorrectly processes heredoc (here-document) syntax, preventing the use of standard shell patterns that work correctly in normal terminals.

Current Behavior

When using any heredoc at the command level, the Bash tool:

  1. Appends < /dev/null to the heredoc content
  2. Fails to recognize the closing delimiter
  3. Produces the error: warning: here-document at line X delimited by end-of-file (wanted 'EOF')

Expected Behavior

Heredocs should be processed according to POSIX shell standards, as they work in Terminal.app, Linux terminals, and other standard shells.

Steps to Reproduce

  1. Try a simple heredoc:
cat << 'EOF'
Hello world
EOF

Actual output:

Hello world
EOF < /dev/null
/opt/homebrew/bin/bash: line 3: warning: here-document at line 1 delimited by end-of-file (wanted `EOF')
  1. Try the standard inverted heredoc pattern:
bash -c 'cat | pbcopy' << 'EOF'
Some content to copy
EOF

Result: Same error - heredoc delimiter not recognized

  1. Try base64 encoding with heredoc:
base64 << 'EOF'
test content
EOF

Result: Encodes "test content\nEOF < /dev/null\n" instead of just "test content\n"

Impact

  • Cannot use idiomatic shell patterns for handling multi-line text
  • Forced to use workarounds that complicate simple tasks
  • Standard shell scripts with heredocs cannot be executed directly
  • Makes it difficult to work with text containing special characters

Environment

  • Shell: /opt/homebrew/bin/bash
  • Observed in Claude Code's Bash tool execution environment

Workarounds

Currently must avoid top-level heredocs entirely:

  • Use heredocs inside bash -c strings (requires complex escaping)
  • Pre-encode content as base64
  • Write to temporary files
  • Read from existing files

Additional Context

This issue appears to be specific to how the Bash tool preprocesses input before passing it to the shell. The same commands work correctly when executed in a standard terminal environment.

Suggested Fix

The Bash tool should preserve heredoc syntax exactly as written, without modifying the content or adding redirections, allowing the shell to process heredocs according to standard POSIX behavior.

View original on GitHub ↗

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