[BUG] SessionStart hook with 'compact' matcher: executes successfully but additionalContext not injected
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?
SessionStart hooks with the compact matcher execute successfully and output valid JSON with hookSpecificOutput.additionalContext, but the content is silently not injected into the conversation context.
Debug logs show the hook fires, runs, outputs valid JSON, gets parsed successfully, and is marked as "success" - but the additionalContext never appears in Claude's context.
Critical: The same hook with startup matcher works perfectly. Only compact fails to inject.
This appears related to previously closed issues #13650, #15174, #12151, #12117 which were marked as duplicates but the underlying bug persists.
What Should Happen?
Per documentation, SessionStart hooks should have their additionalContext added to Claude's context regardless of which matcher triggered (startup, resume, compact, clear).
The compact matcher should behave identically to startup - both execute the same hook, both show "success" in debug logs, but only startup actually injects the content into the conversation.
Error Messages/Logs
With debug mode enabled after running /compact:
- Hook matcher fires correctly:
21:38:18.107Z [DEBUG] Getting matching hook commands for SessionStart with query: compact
21:38:18.108Z [DEBUG] Found 4 hook matchers in settings
21:38:18.108Z [DEBUG] Matched 1 unique hooks for query "compact" (1 before deduplication)
- Hook executes and outputs valid JSON (~10KB of context):
21:38:21.837Z [DEBUG] Hooks: Checking initial response for async: {"hookSpecificOutput": {"hookEventName": "SessionStart", "additionalContext": "[LTM context content here...]"}}
- JSON parsed and marked as success:
21:38:22.024Z [DEBUG] Successfully parsed and validated hook JSON output
21:38:22.025Z [DEBUG] Hook SessionStart:compact (SessionStart) success:
- But UI shows NO injection - only PreCompact appears:
/compact
L Compacted (ctrl+o to see full summary)
PreCompact [uv run ...] completed successfully
L Read ...rules/shared/documentation.md (81 lines)
L Skills restored (load-deferred)
Compare to startup matcher which DOES inject:
21:35:24.707Z [DEBUG] Successfully parsed and validated hook JSON output
21:35:24.708Z [DEBUG] Hook SessionStart:startup (SessionStart) success:
And the full context appears in Claude's conversation.
Steps to Reproduce
- Create a SessionStart hook that outputs JSON with
additionalContext:
{
"hooks": {
"SessionStart": [
{
"matcher": "startup",
"hooks": [{"type": "command", "command": "python my_hook.py"}]
},
{
"matcher": "compact",
"hooks": [{"type": "command", "command": "python my_hook.py"}]
}
]
}
}
- Hook script outputs:
import json
print(json.dumps({
"hookSpecificOutput": {
"hookEventName": "SessionStart",
"additionalContext": "TEST: This should appear in context"
}
}))
- Start a fresh session →
startuphook fires, content IS injected ✅ - Run
/compact→compacthook fires, debug shows success, but content NOT injected ❌
Claude Model
Opus
Is this a regression?
I don't know
Claude Code Version
2.1.51
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
Windows Terminal
Additional Information
Hook configuration that reproduces the issue:
{
"hooks": {
"SessionStart": [
{"matcher": "startup", "hooks": [{"type": "command", "command": "uv run python -m myapp.hooks.session_start"}]},
{"matcher": "resume", "hooks": [{"type": "command", "command": "uv run python -m myapp.hooks.session_start"}]},
{"matcher": "compact", "hooks": [{"type": "command", "command": "uv run python -m myapp.hooks.session_start"}]},
{"matcher": "clear", "hooks": [{"type": "command", "command": "uv run python -m myapp.hooks.session_start"}]}
]
}
}
All four matchers use the exact same hook command. The startup and presumably resume/clear work correctly. Only compact silently fails to inject despite showing success in debug logs.
Impact: This breaks post-compaction context restoration for any system that relies on SessionStart hooks for context injection (memory systems, orchestration reminders, project context loading, etc.).
Related Issues: #13650, #15174, #12151, #12117 - all closed as duplicates but bug persists
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗