Back to Signal Feed
CodeTracked since May 20, 2026

Add PreCompact hook to persist session context before compaction

Introduces a new `pre-compact` lifecycle hook in claude-mem that captures a structured session summary before context compaction and restores it on the next `SessionStart`, so long-running Claude Code sessions retain prior decisions after window resets.

PreCompact hooksession_summariesSessionManager.queuePreCompact/api/sessions/pre-compact

What Happened

  • Introduces a new `pre-compact` lifecycle hook in claude-mem that captures a structured session summary before context compaction and restores it on the next `SessionStart`, so long-running Claude Code sessions retain prior decisions after window resets.
  • Introduces a new `pre-compact` lifecycle hook in claude-mem that captures a structured session summary before context compaction and restores it on the next `SessionStart`, so long-running Claude Code sessions retain prior decisions after window resets.
  • 1 evidence item attached for review.

What is Different

Before

Scattered source updates, isolated context, and manual follow-up across multiple feeds.

Now

Added an explicit pre-compaction workflow: register a `pre-compact` hook and route, queue and generate a summary through the existing summarize pipeline before compaction, persist it, then inject the latest summary on the next session start; includes opt-in control via `CLAUDE_MEM_PRECOMPACT_ENABLED`.

Why Track This

Why It Matters

Developers using Claude Code sessions will keep key context (decisions, findings, and state) across compaction resets, reducing session continuity breaks and manual context recovery after context window overflow. This is implemented by executing summary generation in the pre-compact path and replaying it via context injection on the next session start, so follow-up prompts can continue from the right state. Watch whether summary generation ever misses edge cases (large sessions, provider-specific routing, or skipped hook execution) because those cases would reintroduce context loss.

Impact

Developers using Claude Code sessions will keep key context (decisions, findings, and state) across compaction resets, reducing session continuity breaks and manual context recovery after context window overflow. This is implemented by executing summary generation in the pre-compact path and replaying it via context injection on the next session start, so follow-up prompts can continue from the right state. Watch whether summary generation ever misses edge cases (large sessions, provider-specific routing, or skipped hook execution) because those cases would reintroduce context loss.

What To Watch Next

  • Watch whether PreCompact hook becomes a repeated pattern.
  • Track follow-up changes around Agent Memory and Context Engineering.
  • Compare future signals against this evidence trail.
  • Re-check risk flags: precompact_skip_when_flag_off, missing_summary_on_large_sessions.
Open Topic TimelineOpen Technical EventOpen Original Sourceprecompact_skip_when_flag_off / missing_summary_on_large_sessions / inconsistent_provider_precompact_handling / session_summaries_growth_without_cleanup

Supporting Evidence