Feature request: PostCompact hook event
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
PreCompactfires → plugin can injectsystemMessagethat becomes part of the pre-compaction context- Claude Code compresses all messages into a summary (lossy)
- No hook fires → the compressed context may or may not retain the PreCompact injection
SessionStartfires on NEW sessions (exit + re-runclaude), 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:
PreCompactwrites a.compact_markerfile to disk- The
UserPromptSubmithook 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.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗