You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
session-start hook hangs on bash 5.3+ due to heredoc bug with large variable expansion #571
The session-start hook hangs indefinitely on systems where /usr/bin/env bash resolves to bash 5.3.9 (e.g., installed via Homebrew on macOS). Claude Code never finishes starting and the hook process must be killed manually from another terminal.
The system bash (/bin/bash v3.2 on macOS) works fine.
Root Cause
Bash 5.3 has a bug where heredoc variable expansion hangs when the expanded content exceeds ~512 bytes. The session-start script uses a cat <<EOF heredoc that expands ${session_context} — a ~4,500 byte string containing the escaped SKILL.md content. This triggers the bash 5.3 hang.
Additional Context: Claude Code v2.1.72 Trigger + Secondary Bug
I hit this same deadlock and traced it to the root cause. Adding some details that may be useful for the fix.
Why This Started — Claude Code v2.1.72
Claude Code v2.1.72 (released March 10, 2026) changed bash command parsing to use a native module:
"Improved bash command parsing by switching to a native module — faster initialization and no memory leak"
This was the fix for anthropics/claude-code#3991 (the original request to respect Homebrew bash). Hook commands are now spawned using PATH-resolved bash, so #!/usr/bin/env bash resolves to Homebrew bash 5.3.9 on machines that have it. Previously hooks used /bin/sh or system /bin/bash, which uses temp files for heredocs (no size limit).
The pipe buffer deadlock mechanism is exactly as described in this issue — Homebrew bash 5.3.9 uses pipes for heredoc stdin redirection, and macOS pipe buffers are only 512 bytes. The session-start hook's cat <<EOF heredoc contains the escaped SKILL.md content (~5.2KB), well over the threshold.
The hook uses an unquoted heredoc (cat <<EOF instead of cat <<'EOF'), which means bash performs variable expansion and backtick command substitution on the heredoc content. The SKILL.md contains markdown backticks (inline code, code fences, a ```dot block with Graphviz DOT language).
On machines with Graphviz installed (dot on PATH), the backtick content would trigger command execution — dot reads from stdin and hangs waiting for input. This is currently masked by the pipe buffer deadlock (which occurs first, before bash processes heredoc content), but it would surface if the pipe deadlock were fixed independently (e.g., by forcing system bash) while keeping the unquoted heredoc.
The escape_for_json() function escapes \, ", newlines, carriage returns, and tabs — but does not escape backticks.
Recommended Fix
Replacing cat <<EOF ... EOF with printf '%s' "$session_context" eliminates both bugs:
No heredoc → no pipe buffer deadlock
No unquoted heredoc → no backtick command substitution
I've been using this locally as a workaround and it works with both system and Homebrew bash.
Cross-References
CharlesWiltgen/Axiom#24 — same class of bug in the Axiom plugin's session-start.sh hook (2,684-byte Python heredoc)
Activity
fix: replace herestring with process substitution in gitstatus.sh
lukelabonte commentedon Mar 12, 2026
Additional Context: Claude Code v2.1.72 Trigger + Secondary Bug
I hit this same deadlock and traced it to the root cause. Adding some details that may be useful for the fix.
Why This Started — Claude Code v2.1.72
Claude Code v2.1.72 (released March 10, 2026) changed bash command parsing to use a native module:
This was the fix for anthropics/claude-code#3991 (the original request to respect Homebrew bash). Hook commands are now spawned using PATH-resolved bash, so
#!/usr/bin/env bashresolves to Homebrew bash 5.3.9 on machines that have it. Previously hooks used/bin/shor system/bin/bash, which uses temp files for heredocs (no size limit).The pipe buffer deadlock mechanism is exactly as described in this issue — Homebrew bash 5.3.9 uses pipes for heredoc stdin redirection, and macOS pipe buffers are only 512 bytes. The
session-starthook'scat <<EOFheredoc contains the escaped SKILL.md content (~5.2KB), well over the threshold.Secondary Bug: Unquoted Heredoc + Backtick Command Substitution
The hook uses an unquoted heredoc (
cat <<EOFinstead ofcat <<'EOF'), which means bash performs variable expansion and backtick command substitution on the heredoc content. The SKILL.md contains markdown backticks (inline code, code fences, a```dotblock with Graphviz DOT language).On machines with Graphviz installed (
doton PATH), the backtick content would trigger command execution —dotreads from stdin and hangs waiting for input. This is currently masked by the pipe buffer deadlock (which occurs first, before bash processes heredoc content), but it would surface if the pipe deadlock were fixed independently (e.g., by forcing system bash) while keeping the unquoted heredoc.The
escape_for_json()function escapes\,", newlines, carriage returns, and tabs — but does not escape backticks.Recommended Fix
Replacing
cat <<EOF ... EOFwithprintf '%s' "$session_context"eliminates both bugs:I've been using this locally as a workaround and it works with both system and Homebrew bash.
Cross-References
session-start.shhook (2,684-byte Python heredoc)fix(hooks): replace heredoc with printf to fix bash 5.3+ hang
Update changelog: add bash 5.3+ fix, link all issues/PRs
fix(hooks): replace heredoc with printf to fix bash 5.3+ hang
Update changelog: add bash 5.3+ fix, link all issues/PRs
fix(hooks): replace heredoc with printf to fix bash 5.3+ hang
Update changelog: add bash 5.3+ fix, link all issues/PRs
Squashed commit of the following:
Squashed commit of the following:
feat: sync upstream v5.0.0-v5.1.0 (209 commits) while preserving fork
fix(hooks): restore session-start's output comments and keep heredocs…