Feature request: PostCompact hook event

Resolved 💬 3 comments Opened Mar 8, 2026 by metafishTV Closed Mar 11, 2026

Feature Request: PostCompact Hook Event

Problem

Claude Code has a PreCompact hook event that fires before context compaction, but no corresponding PostCompact event that fires after. This creates a gap for plugins that need to inject structured data into the post-compaction context.

Current Behavior

  1. PreCompact fires → plugin can inject systemMessage that becomes part of the pre-compaction context
  2. Claude Code compresses all messages into a summary (lossy)
  3. No hook fires → the compressed context may or may not retain the PreCompact injection
  4. SessionStart fires on NEW sessions (exit + re-run claude), but NOT after mid-session compaction

The Gap

For mid-session compaction (context fills up during a conversation), there is no hook point after compaction completes. Plugins that need to preserve structured state across compaction boundaries have no reliable injection point.

Current Workaround

Our buffer plugin uses UserPromptSubmit as a PostCompact proxy:

  • PreCompact writes a .compact_marker file to disk
  • The UserPromptSubmit hook checks for this marker on every prompt
  • If found, it injects the preserved buffer state and deletes the marker

This works but is fragile — it piggybacks on a hook designed for a different purpose, adds latency to every prompt (checking for a file that only exists after compaction), and the injection happens one turn late (on the next user message, not immediately after compaction).

Proposed Solution

Add a PostCompact hook event that fires immediately after context compaction completes:

{
  "PostCompact": [
    {
      "matcher": "*",
      "hooks": [{
        "type": "command",
        "command": "my-plugin/scripts/post-compact.sh",
        "timeout": 30
      }]
    }
  ]
}

Hook input should include:

  • session_id, cwd, transcript_path (standard fields)
  • compaction_type: "auto" or "manual" (was it triggered by context limit or user action?)

Hook output should support:

  • systemMessage: text injected into the post-compaction context (same as other hooks)
  • additionalContext: structured data to preserve

Use Case

Session buffer plugins that maintain structured state (active work tracking, concept maps, open threads) across compaction boundaries. The PreCompact hook captures state, the PostCompact hook injects it back — creating a lossless memory pipeline through compaction.

Priority

Low — the UserPromptSubmit workaround functions. But a dedicated PostCompact event would be cleaner, faster, and semantically correct.

View original on GitHub ↗

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