claude-code - 💡(How to fix) Fix Context compaction drops recent messages, keeps old ones [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#46457Fetched 2026-04-11 06:19:48
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Author
Timeline (top)
labeled ×3commented ×1

Root Cause

  • ~3 days of iterative context wiped
  • Model lost awareness of 400+ lines of code it had written
  • Model lost debugging findings (XPU failure root cause, OOM root cause)
  • User had to manually re-explain what was already done
  • Memory files (.claude/memory/) partially mitigated the loss, but conversational context (why decisions were made, what was tried and failed) was gone
RAW_BUFFERClick to expand / collapse

Bug Description

Context compaction is behaving backwards: it keeps the oldest summary/messages and drops the most recent work. This causes loss of significant context mid-session.

Expected Behavior

Compaction should compress older messages and preserve recent ones, so the model retains awareness of the latest work and decisions.

Actual Behavior

Compaction preserves the initial summary (from session start / prior compaction) and wipes out all intermediate and recent work, leaving the model with stale context and no knowledge of what was just done.

Reproduction

  • Long-running session: 37MB transcript, 10,946 lines (JSONL)
  • Session spanned ~3 days of iterative development (April 8–11, 2026)
  • After compaction triggered:
    • Kept: Initial compaction summary from April 8 (dataset build, early monitoring setup)
    • Lost: All work from April 9–11 — OpenVINO model export & integration, voice server expansion (836 → 1253 lines), XPU debugging, OOM root-cause analysis, multiple code iterations
    • Result: Model reverted to stale context, re-suggested already-completed work, lost awareness of architectural decisions and root-cause findings

Impact

  • ~3 days of iterative context wiped
  • Model lost awareness of 400+ lines of code it had written
  • Model lost debugging findings (XPU failure root cause, OOM root cause)
  • User had to manually re-explain what was already done
  • Memory files (.claude/memory/) partially mitigated the loss, but conversational context (why decisions were made, what was tried and failed) was gone

Environment

  • Claude Code CLI (desktop app on Ubuntu 24.04)
  • Model: Claude Opus 4.6 (1M context)
  • Session ID: 16bf4830-c72a-4f7a-b2b5-13aba43044d4
  • Transcript: 37MB, 10,946 lines JSONL

Suggestion

Compaction should use a recency-biased strategy: always keep the N most recent turns verbatim, compress middle history, and keep (or refresh) the initial summary. The current behavior appears to keep the head and drop the tail, which is the worst possible outcome for an interactive development session.

extent analysis

TL;DR

Implement a recency-biased compaction strategy to preserve recent context and compress older messages.

Guidance

  • Review the current compaction algorithm to identify why it prioritizes older messages over recent ones.
  • Consider implementing a strategy that keeps the N most recent turns verbatim, as suggested, to maintain awareness of the latest work and decisions.
  • Evaluate the impact of the proposed recency-biased strategy on session context and model performance.
  • Test the updated compaction strategy with a similar long-running session to verify its effectiveness in preserving recent context.

Example

No specific code snippet can be provided without knowing the implementation details of the compaction algorithm. However, the general idea would be to modify the compaction function to prioritize recent messages, for example, by using a data structure like a queue or a priority queue to store messages.

Notes

The suggested recency-biased strategy may have implications for memory usage and performance, particularly for very long sessions. It's essential to monitor and evaluate these aspects when implementing the updated compaction strategy.

Recommendation

Apply the suggested workaround by implementing a recency-biased compaction strategy, as it directly addresses the issue of preserving recent context and compressing older messages, aligning with the expected behavior of the compaction feature.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING