Bash tool hangs on heredoc inside command substitution exceeding ~512 bytes
Bug: Bash tool hangs when heredoc inside $(...) exceeds ~512 bytes
Summary
The Bash tool deadlocks when executing a command containing a here-document inside a command substitution ($(cat <<'EOF' ... EOF)) where the heredoc body exceeds approximately 512 bytes.
Reproduction
Works (511 bytes of heredoc content):
echo "$(cat <<'EOF'
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
FFFFF
EOF
)" | wc -c
Hangs indefinitely (516+ bytes of heredoc content):
echo "$(cat <<'EOF'
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
FFFFFFFFFF
EOF
)" | wc -c
The threshold is exactly 512 bytes of heredoc body content. Content, characters, and line count are irrelevant — only total byte size matters.
Analysis
The hang occurs before any command output is produced (shell profile runs, then silence). This suggests the command string is being written to the shell's stdin, and when the total write exceeds an internal buffer (512 bytes for the heredoc portion within $(...)), the write blocks because the read side hasn't consumed enough yet — a classic pipe/pty deadlock.
Key observations from testing:
- Plain heredocs (not inside
$(...)) of any size work fine - The same content written to a file and used as
$(cat /path/to/file)works fine - The content doesn't matter (tested with plain ASCII, markdown, backticks, special chars)
- The threshold is consistent at 512 bytes regardless of line count
Workaround
Write content to a temporary file first, then reference it:
# Instead of:
glab mr update 231 --description "$(cat <<'EOF'
... long content ...
EOF
)"
# Do:
# (write content to /tmp/desc.md via Write tool)
glab mr update 231 --description "$(cat /tmp/desc.md)"
Environment
- Platform: macOS (Darwin 24.6.0, arm64)
- Shell: bash (from /opt/homebrew/bin/bash)
- Claude Code version: current as of 2026-05-27
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗