PreCompact/PostCompact hooks have no visibility into what's being lost
Problem
I built a "lossless compaction" system using PreCompact and PostCompact hooks. PreCompact dumps critical state (current task, file paths, decisions, git branch) to disk. PostCompact reads it back and re-injects it.
It works, but it's held together with duct tape because the hooks get zero information about the compaction itself:
- No context size info — I don't know how much is being dropped. Am I losing 10K tokens or 200K? The preservation strategy should differ.
- No ability to influence preservation — I can save state externally, but I can't tell the compaction engine "these 3 messages are critical, keep them." My hook is essentially racing against compaction with no coordination.
- No diff — PostCompact doesn't know what survived vs what was lost, so it blindly re-injects everything, often duplicating what the compaction already kept.
What I'd want
Pass richer metadata to compaction hooks:
{
"pre_compact_token_count": 180000,
"post_compact_target": 40000,
"tokens_being_dropped": 140000,
"message_count_before": 87,
"message_count_after": 12
}
And ideally, let PreCompact return a preserve_hints array — short strings the compaction engine should try to keep:
{
"preserve_hints": [
"Currently on branch feat/agent-metrics",
"Editing /Users/josh/hemp-route/lib/crm/accounts.ex",
"Josh decided to use GenServer over Task.Supervisor"
]
}
Why this matters
Compaction is the #1 context loss event for long sessions. Power users who build memory systems around it are doing so completely blind. Even just exposing token counts before/after would be a massive improvement.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗