diff options
| author | jesse <jesse@magic-kingdom> | 2026-03-15 19:14:34 +0000 |
|---|---|---|
| committer | jesse <jesse@magic-kingdom> | 2026-03-15 19:14:34 +0000 |
| commit | 537ec640fd8fd47fc0ff596abeb445d1515bd2bd (patch) | |
| tree | b9198d81a535942ca6ac72b8187c0c23f6e79b2f | |
| parent | c5e953831186a59c26f3e200aba0f8099e160a76 (diff) | |
fix(hooks): replace heredoc with printf to fix bash 5.3+ hang
Bash 5.3 has a regression where heredoc variable expansion blocks when
content exceeds ~512 bytes. The session_context variable is ~4,500 bytes,
causing the SessionStart hook to hang indefinitely on macOS with Homebrew
bash 5.3+. Replace cat <<EOF with printf.
Tested on Linux (bash 5.2) and Windows (Git Bash 5.2). The hang only
affects 5.3+ but printf works correctly on all versions.
Based on #572, closes #572. Fixes #571.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| -rwxr-xr-x | hooks/session-start | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/hooks/session-start b/hooks/session-start index b4f9918..dca5389 100755 --- a/hooks/session-start +++ b/hooks/session-start @@ -39,23 +39,16 @@ session_context="<EXTREMELY_IMPORTANT>\nYou have superpowers.\n\n**Below is the # Claude Code hooks expect hookSpecificOutput.additionalContext. # Claude Code reads BOTH fields without deduplication, so we must only # emit the field consumed by the current platform to avoid double injection. +# +# Uses printf instead of heredoc (cat <<EOF) to work around a bash 5.3+ +# bug where heredoc variable expansion hangs when content exceeds ~512 bytes. +# See: https://github.com/obra/superpowers/issues/571 if [ -n "${CLAUDE_PLUGIN_ROOT:-}" ]; then # Claude Code sets CLAUDE_PLUGIN_ROOT — emit only hookSpecificOutput - cat <<EOF -{ - "hookSpecificOutput": { - "hookEventName": "SessionStart", - "additionalContext": "${session_context}" - } -} -EOF + printf '{\n "hookSpecificOutput": {\n "hookEventName": "SessionStart",\n "additionalContext": "%s"\n }\n}\n' "$session_context" else # Other platforms (Cursor, etc.) — emit only additional_context - cat <<EOF -{ - "additional_context": "${session_context}" -} -EOF + printf '{\n "additional_context": "%s"\n}\n' "$session_context" fi exit 0 |
