diff options
Diffstat (limited to 'hooks')
| -rw-r--r-- | hooks/hooks-cursor.json | 10 | ||||
| -rw-r--r-- | hooks/hooks.json | 2 | ||||
| -rwxr-xr-x | hooks/session-start | 28 |
3 files changed, 23 insertions, 17 deletions
diff --git a/hooks/hooks-cursor.json b/hooks/hooks-cursor.json new file mode 100644 index 0000000..6df4461 --- /dev/null +++ b/hooks/hooks-cursor.json @@ -0,0 +1,10 @@ +{ + "version": 1, + "hooks": { + "sessionStart": [ + { + "command": "./hooks/session-start" + } + ] + } +} diff --git a/hooks/hooks.json b/hooks/hooks.json index 7e3d30d..79d8cee 100644 --- a/hooks/hooks.json +++ b/hooks/hooks.json @@ -2,7 +2,7 @@ "hooks": { "SessionStart": [ { - "matcher": "startup|resume|clear|compact", + "matcher": "startup|clear|compact", "hooks": [ { "type": "command", diff --git a/hooks/session-start b/hooks/session-start index f9e94dd..2371935 100755 --- a/hooks/session-start +++ b/hooks/session-start @@ -4,7 +4,7 @@ set -euo pipefail # Determine plugin root directory -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)" +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" PLUGIN_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" # Check if legacy skills directory exists and build warning @@ -39,23 +39,19 @@ 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. -if [ -n "${CLAUDE_PLUGIN_ROOT:-}" ]; then +# +# 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 "${CURSOR_PLUGIN_ROOT:-}" ]; then + # Cursor sets CURSOR_PLUGIN_ROOT (may also set CLAUDE_PLUGIN_ROOT) — emit additional_context + printf '{\n "additional_context": "%s"\n}\n' "$session_context" +elif [ -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 + # Other platforms — emit additional_context as fallback + printf '{\n "additional_context": "%s"\n}\n' "$session_context" fi exit 0 |
