This document details the session initialization process, focusing on how the SessionStart hook injects the using-superpowers skill content before the agent's first turn. This bootstrap mechanism establishes the agent's "prime directive" to check for and use skills.
For information about skill discovery after bootstrap, see Skills Discovery and Resolution. For platform-specific integration details, see Multi-Platform Integration.
The session lifecycle in Superpowers follows a strict sequence:
session-start.sh runs synchronously before agent receives user inputusing-superpowers skill content embedded in session contextCritical timing requirement: The hook must complete before the agent's first response. This ensures the bootstrap context is present when the agent processes its first user message.
Sources: RELEASE-NOTES.md25-27 hooks/session-start.sh1-51 hooks/hooks.json1-16
Diagram: Session Start Hook Execution Flow
The hook configuration in hooks.json uses a regex matcher to trigger on session lifecycle events. The async: false setting forces synchronous execution, ensuring completion before the agent's first turn.
Sources: hooks/hooks.json1-16 hooks/session-start.sh1-51
As of v4.3.0, the SessionStart hook runs synchronously (async: false in hooks/hooks.json10):
Why synchronous is critical:
using-superpowers content is in context from the startPrior to v4.3.0, the hook ran asynchronously (async: true):
Problem: When async, the hook could fail to complete before the model's first turn, meaning using-superpowers instructions weren't in context for the first message.
Windows-specific issue (v4.2.0): On Windows, synchronous hooks blocked the TUI from entering raw mode, freezing all keyboard input. This was temporarily worked around by using async execution, but v4.3.0 resolved the underlying compliance issue with skill enforcement.
Sources: RELEASE-NOTES.md25-27 RELEASE-NOTES.md47-49 hooks/hooks.json10
Diagram: Bootstrap Content Preparation Pipeline
Sources: hooks/session-start.sh11-35
The escape_for_json function hooks/session-start.sh23-31 must handle large content (the entire using-superpowers skill) efficiently:
Implementation (Optimized in v4.2.0):
Performance characteristics:
${s//old/new})Previous O(n²) implementation (removed in v4.2.0):
Sources: hooks/session-start.sh23-31 RELEASE-NOTES.md51-53
The hook outputs JSON with two shapes for cross-platform compatibility:
Platform usage:
additional_contexthookSpecificOutput.additionalContextSession context structure:
<EXTREMELY_IMPORTANT>
You have superpowers.
**Below is the full content of your 'superpowers:using-superpowers'
skill - your introduction to using skills. For all other skills,
use the 'Skill' tool:**
[Full using-superpowers SKILL.md content]
[Optional legacy warning if ~/.config/superpowers/skills exists]
</EXTREMELY_IMPORTANT>
The <EXTREMELY_IMPORTANT> wrapper signals critical bootstrap information. The explicit statement "For all other skills, use the 'Skill' tool" prevents agents from trying to read skill files directly instead of using the platform's skill tool.
Sources: hooks/session-start.sh35-49 RELEASE-NOTES.md176-183
Diagram: Complete Session Lifecycle Sequence
Key timing constraints:
Sources: hooks/session-start.sh1-51 hooks/hooks.json1-16
The hook checks for the deprecated ~/.config/superpowers/skills directory hooks/session-start.sh12-15:
Historical context: Prior to v4.0.0, Superpowers maintained a separate skills repository at ~/.config/superpowers/skills. Since v4.0.0, skills are embedded in the plugin repository at ${CLAUDE_PLUGIN_ROOT}/skills/.
Warning content:
~/.claude/skills/ (platform's native location)This prevents confusion when users upgrade from very old versions (v3.x) that used the separate repository structure.
Sources: hooks/session-start.sh11-15 RELEASE-NOTES.md557-567
hooks.json calls session-start.sh directly hooks/hooks.json9:
Platform behavior:
.sh file directly (has shebang #!/usr/bin/env bash).sh extension and prepends bash commandPrior to Claude Code 2.1.x, a polyglot run-hook.cmd wrapper provided cross-platform compatibility hooks/run-hook.cmd1-44 This file was both a valid Windows CMD script and a bash script.
Why deprecated: Claude Code 2.1.x changed hook execution on Windows to auto-detect .sh files. The command bash "run-hook.cmd" session-start.sh attempted to execute the .cmd file as a bash script, causing failures.
Current approach is simpler:
.sh file with Unix shebangOn Windows, the .sh file executes via Git Bash (typically C:\Program Files\Git\bin\bash.exe). This is automatically handled by Claude Code's hook execution system.
Sources: hooks/run-hook.cmd1-44 RELEASE-NOTES.md41-46 RELEASE-NOTES.md137-141
The script determines its location using BASH_SOURCE fallback hooks/session-start.sh7-8:
Why the fallback: ${BASH_SOURCE[0]:-$0} handles environments where BASH_SOURCE is unbound. In Claude Code's hook execution context, BASH_SOURCE may not be set, so $0 provides the script path.
Path resolution:
hooks/)This resolved a v2.0.1 bug where hooks failed silently with "Plugin hook error" when BASH_SOURCE was unbound.
Sources: hooks/session-start.sh7-8 RELEASE-NOTES.md542-547
The script uses set -euo pipefail hooks/session-start.sh4 for strict error handling:
Flags:
-e: Exit on first error-u: Treat unset variables as errors-o pipefail: Propagate errors through pipesFallback for skill reading hooks/session-start.sh18:
If the skill file is missing or unreadable, the error message is captured and included in the bootstrap context rather than causing hook failure.
Sources: hooks/session-start.sh4 hooks/session-start.sh18
The injected context has three components:
<EXTREMELY_IMPORTANT>
You have superpowers.
**Below is the full content of your 'superpowers:using-superpowers'
skill - your introduction to using skills. For all other skills,
use the 'Skill' tool:**
Establishes that:
Full markdown content of skills/using-superpowers/SKILL.md, including:
<important-reminder>
IN YOUR FIRST REPLY AFTER SEEING THIS MESSAGE YOU MUST TELL THE USER:
⚠️ **WARNING:** Superpowers now uses Claude Code's skills system...
</important-reminder>
Only included if ~/.config/superpowers/skills directory exists.
Sources: hooks/session-start.sh33-35
After bootstrap completes, the agent has:
using-superpowers content - Already loaded, no tool invocation neededThe agent then uses the Skill tool (see Tool Mapping Layer) to load other skills as needed.
Sources: hooks/session-start.sh35
Refresh this wiki
This wiki was recently refreshed. Please wait 3 days to refresh again.