[BUG] SessionStart hook with 'compact' matcher: executes successfully but additionalContext not injected

Resolved 💬 5 comments Opened Feb 24, 2026 by matt-grain Closed Apr 22, 2026

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:

  1. 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)
  1. 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...]"}}
  1. 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:
  1. 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

  1. 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"}]
      }
    ]
  }
}
  1. Hook script outputs:
import json
print(json.dumps({
    "hookSpecificOutput": {
        "hookEventName": "SessionStart",
        "additionalContext": "TEST: This should appear in context"
    }
}))
  1. Start a fresh session → startup hook fires, content IS injected ✅
  2. Run /compactcompact hook 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

View original on GitHub ↗

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