Skip to content

[BUG] Bash tool breaks single-quoted heredocs containing single quotes — unexpected EOF while looking for matching error #32563

@nv186000

Description

@nv186000

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

What's Wrong?
Single quotes inside a bash heredoc body cause a parsing error. A << 'EOF' heredoc is supposed to pass its entire body as a literal string with no substitution or escaping. Single quotes inside the body should be inert. Instead, the Bash tool fails with a shell quoting error.

What Should Happen?

The content between << 'EOF' and EOF should be passed to the command completely literally. Single quotes, backticks, and dollar signs inside the heredoc body should have no special meaning.

Error Messages/Logs

/usr/bin/bash: -c: line 12: unexpected EOF while looking for matching `''
/usr/bin/bash: -c: line 14: syntax error: unexpected end of file

Steps to Reproduce

In the Bash tool, run the following command:
cat > /tmp/test.ps1 << 'EOF'
$lines = @()
$lines += 'hello world'
Write-Host $lines
EOF

The command fails at the line containing single quotes inside the heredoc body

Claude Model

Sonnet (default)

Is this a regression?

No, this never worked

Last Working Version

No response

Claude Code Version

latest

Platform

Other

Operating System

Windows

Terminal/Shell

Other

Additional Information

The root cause appears to be that the Bash tool passes commands to the shell as a single-quoted -c argument: bash -c '...'. When the command string itself contains single quotes (even inside a heredoc body), those quotes prematurely close the outer -c quoting, breaking the parse. Heredocs with no single quotes in the body work correctly. The workaround is to replace all single-quoted strings in the heredoc content with double-quoted strings. A proper fix would be to pass commands to the shell via stdin or using ANSI-C quoting ($'...') rather than wrapping in single quotes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:bashbugSomething isn't workingplatform:windowsIssue specifically occurs on WindowsstaleIssue is inactive

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions