Feature Request: Preserve recent conversation turns after context compaction

Status Fixed / completed
Maintainer reply None cached
Activity 3 comments · opened Feb 2, 2026 · closed Feb 2, 2026

Current behavior

When context compaction occurs, the entire conversation is summarized into prose. Zero recent turns are preserved verbatim.

Problem

This causes significant continuity issues:

  • AI loses track of what was actively being worked on
  • Stale/incorrect information in summary gets treated as current state
  • User has to re-explain context that was just discussed
  • Mid-task compaction leaves AI unable to continue work seamlessly

Requested behavior

After compaction, reinject the last N conversation turns (e.g., 5-10 exchanges) verbatim, similar to how Claude.ai handles this. The summary provides long-term context; recent turns provide immediate continuity.

Example failure

After compaction, my AI assistant believed I was using 'Open WebUI (third-party, can't modify)' when we had just been editing my custom UI together. The summary captured stale context and there were no recent turns to correct it. I had to spend several minutes re-orienting the AI to what we were actually working on.

Suggested implementation

  • Keep last 5-10 user/assistant turn pairs after summary
  • Or allow configuration via settings/CLAUDE.md for number of turns to preserve
  • Consider marking 'in-progress work' specially so it survives compaction

View original on GitHub ↗

3 Comments

github-actions[bot] · 8 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/18089
  2. https://github.com/anthropics/claude-code/issues/14176
  3. https://github.com/anthropics/claude-code/issues/22376

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

AgnosticMonk · 8 months ago

Closing - found a user-side solution that achieves the same result.

Workaround: Add instructions to your CLAUDE.md file telling Claude to read the transcript directly after compaction:

## Post-Compaction Context Recovery

When you see a conversation summary indicating compaction occurred, recover recent context by:

1. Find the current transcript: `ls -t ~/.claude/projects/**/*.jsonl | head -1`
2. Read the last 200 lines of that file
3. Extract the last 5-10 user/assistant exchanges to understand what was actively being worked on

Do this BEFORE responding to any user message after compaction.

This works because:

  • Transcript JSONL files are available at ~/.claude/projects/<project>/<session>.jsonl
  • CLAUDE.md is loaded after compaction
  • Claude can read and parse the transcript to recover immediate context

No built-in feature needed - the pieces are already there.

github-actions[bot] · 8 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.