session-start 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env bash
  2. # SessionStart hook for superpowers plugin
  3. set -euo pipefail
  4. # Determine plugin root directory
  5. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
  6. PLUGIN_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
  7. # Check if legacy skills directory exists and build warning
  8. warning_message=""
  9. legacy_skills_dir="${HOME}/.config/superpowers/skills"
  10. if [ -d "$legacy_skills_dir" ]; then
  11. warning_message="\n\n<important-reminder>IN YOUR FIRST REPLY AFTER SEEING THIS MESSAGE YOU MUST TELL THE USER:⚠️ **WARNING:** Superpowers now uses Claude Code's skills system. Custom skills in ~/.config/superpowers/skills will not be read. Move custom skills to ~/.claude/skills instead. To make this message go away, remove ~/.config/superpowers/skills</important-reminder>"
  12. fi
  13. # Read using-superpowers content
  14. using_superpowers_content=$(cat "${PLUGIN_ROOT}/skills/using-superpowers/SKILL.md" 2>&1 || echo "Error reading using-superpowers skill")
  15. # Escape string for JSON embedding using bash parameter substitution.
  16. # Each ${s//old/new} is a single C-level pass - orders of magnitude
  17. # faster than the character-by-character loop this replaces.
  18. escape_for_json() {
  19. local s="$1"
  20. s="${s//\\/\\\\}"
  21. s="${s//\"/\\\"}"
  22. s="${s//$'\n'/\\n}"
  23. s="${s//$'\r'/\\r}"
  24. s="${s//$'\t'/\\t}"
  25. printf '%s' "$s"
  26. }
  27. using_superpowers_escaped=$(escape_for_json "$using_superpowers_content")
  28. warning_escaped=$(escape_for_json "$warning_message")
  29. session_context="<EXTREMELY_IMPORTANT>\nYou have superpowers.\n\n**Below is the full content of your 'superpowers:using-superpowers' skill - your introduction to using skills. For all other skills, use the 'Skill' tool:**\n\n${using_superpowers_escaped}\n\n${warning_escaped}\n</EXTREMELY_IMPORTANT>"
  30. # Output context injection as JSON.
  31. # Keep both shapes for compatibility:
  32. # - Cursor hooks expect additional_context.
  33. # - Claude hooks expect hookSpecificOutput.additionalContext.
  34. cat <<EOF
  35. {
  36. "additional_context": "${session_context}",
  37. "hookSpecificOutput": {
  38. "hookEventName": "SessionStart",
  39. "additionalContext": "${session_context}"
  40. }
  41. }
  42. EOF
  43. exit 0