Bad substitution error when using heredoc/EOF syntax in bash commands
Resolved 💬 3 comments Opened Jan 16, 2026 by holdforever2021-bot Closed Jan 19, 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?
Claude Code crashes with "Bad substitution" error when attempting to write multi-line files using heredoc syntax.
Error message:
"Error: Failed to parse command: Bad substitution: strategy"
and
"Error: Failed to parse command: Bad substitution: orderId"
This happens when Claude Code generates bash commands like:
cat > file.js << 'EOF'
[multi-line content with variables like ${strategy} or ${orderId}]
EOF
The command fails before execution. Rewind doesn't help - the same error repeats.
What Should Happen?
Claude Code should successfully write multi-line files to the filesystem, either by:
- Properly escaping variables in heredoc syntax
- Using alternative methods (echo, printf, or file editing tools)
- Detecting the substitution issue and auto-correcting the approach
Error Messages/Logs
Steps to Reproduce
- Start Claude Code: npx @anthropic-ai/claude-code
- SSH to a remote server
- Ask Claude Code to create or modify a JavaScript file with template literals or variables (e.g., "Add email notifications to my Node.js webhook server")
- Claude Code attempts heredoc syntax with ${variable} patterns
- Error: "Bad substitution" - command fails
- /rewind doesn't fix - same error on retry
Claude Model
Not sure / Multiple models
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
v2.1.9
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗