[BUG] SessionStart hook with "compact" matcher output not injected into context
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Summary
SessionStart hooks configured with the compact matcher execute but their stdout output is not added to Claude's context after compaction completes.
Environment
- Claude Code version: 2.0.72+
- OS: Linux/macOS
- Shell: bash
Configuration
.claude/settings.json:
{
"hooks": {
"SessionStart": [
{
"matcher": "compact",
"hooks": [
{
"type": "command",
"command": "bash $CLAUDE_PROJECT_DIR/.claude/hooks/restore-orchestrator-role.sh"
}
]
}
]
}
}
Hook script (.claude/hooks/restore-orchestrator-role.sh):
#!/bin/bash
cat << 'EOF'
🎯 POST-COMPACTION REMINDER
You are the Orchestrator Agent. Read .claude/agents/orchestrator.md for instructions.
EOF
exit 0
Workaround
Added reminder to CLAUDE.md which does get loaded after compaction. But this defeats the purpose of having a dedicated hook mechanism.
Impact
This prevents automated context restoration after compaction, which is critical for:
- Multi-agent orchestration systems that need role reminders
- Projects with specific post-compaction initialization needs
- Any workflow that depends on injecting context after compaction
What Should Happen?
Expected Behavior
Per the documentation, SessionStart hooks with compact matcher should:
- Fire when context is compacted
- Have their stdout output added to Claude's context
Actual Behavior
- The hook does execute - Claude Code reads the hook file (visible in system reminders)
- The hook stdout is NOT injected into Claude's context after compaction
- Claude has no awareness of the hook output post-compaction
Error Messages/Logs
Steps to Reproduce
- Configure SessionStart hook with compact matcher (as shown above)
- Start a conversation and fill context until compaction triggers (or run /compact)
- After compaction, check if Claude received the hook output
- Result: Hook output is not in Claude's context
Attempts Made
- JSON format with additionalContext - Output added "discretely" but not visible in context
- Plain stdout format - Same result, output not in context
- Verified hook executes - File is read by Claude Code, script runs successfully
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
v2.0.76
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
I'm trying to get claude code to automatically read my orchistrator.md instructions after compaction automatically.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗