[BUG] SessionStart hook with "compact" matcher output not injected into context

Resolved 💬 3 comments Opened Dec 23, 2025 by anthonyscolaro Closed Dec 27, 2025

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:

  1. Fire when context is compacted
  2. Have their stdout output added to Claude's context

Actual Behavior

  1. The hook does execute - Claude Code reads the hook file (visible in system reminders)
  2. The hook stdout is NOT injected into Claude's context after compaction
  3. Claude has no awareness of the hook output post-compaction

Error Messages/Logs

Steps to Reproduce

  1. Configure SessionStart hook with compact matcher (as shown above)
  2. Start a conversation and fill context until compaction triggers (or run /compact)
  3. After compaction, check if Claude received the hook output
  4. Result: Hook output is not in Claude's context

Attempts Made

  1. JSON format with additionalContext - Output added "discretely" but not visible in context
  2. Plain stdout format - Same result, output not in context
  3. 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.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗