[BUG] Context corruption: auto-memory/compaction causes previous conversation content to be mixed or truncated

Resolved 💬 8 comments Opened Feb 26, 2026 by jung-wan-kim Closed Apr 1, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

After upgrading to v2.1.59+ (which introduced the Auto Memory feature), conversation context becomes corrupted during sessions. Symptoms include:

  1. Previous conversation content is truncated or cut off — messages from earlier in the session disappear or become incomplete
  2. Content from different sessions appears mixed — fragments of older conversations appear in the current session context
  3. Compaction (/compact) fails or produces corrupted output when Auto Memory is enabled

The issue appears to be a race condition between the Auto Memory system and the context compaction mechanism. Both systems concurrently access and modify the message storage, leading to message boundary corruption during compaction.

Root Cause Analysis

Investigation suggests the following:

  • Auto Memory + Auto Compaction race condition: When both systems are active, the compaction logic can trigger at incorrect boundaries, splitting or merging messages incorrectly
  • Auto-save overwriting with stale data: The auto-save mechanism may write older/incorrect data back into the context, overwriting current conversation state
  • This correlates with historical compaction bugs seen in previous versions (v2.1.47, v2.1.21, v2.1.14), suggesting the compaction logic has a recurring vulnerability pattern

Workaround

Disabling Auto Memory via settings resolves the compaction failure:

// ~/.claude/settings.json
{
  "autoMemoryEnabled": false
}

After disabling, /compact works correctly and context is no longer corrupted.

What Should Happen?

  • Auto Memory and compaction should coexist without corrupting conversation context
  • Compaction should never produce truncated or mixed content regardless of Auto Memory state
  • If concurrent access is unavoidable, proper locking or sequencing should prevent race conditions

Error Messages/Logs

No explicit error messages — the corruption is silent. The only observable symptom is that earlier conversation content is missing, truncated, or mixed with content from other sessions when reviewing the conversation mid-session.

Steps to Reproduce

  1. Enable Auto Memory (default in v2.1.59+)
  2. Start a long conversation with multiple tool calls and file reads
  3. Continue working until context compaction triggers automatically
  4. Observe that earlier messages are truncated or mixed with unrelated content
  5. Running /compact manually may also produce corrupted output

Claude Model

Opus 4.5 / Opus 4.6

Is this a regression?

Yes, this worked in versions prior to v2.1.59 (before Auto Memory was introduced)

Last Working Version

v2.1.58

Claude Code Version

2.1.61

Platform

Anthropic API

Operating System

macOS 15.5

Terminal/Shell

zsh (iTerm2 / Terminal.app)

Additional Information

  • Related to existing compaction issues: the compaction logic has had recurring bugs across multiple versions
  • Issue #27242 documents a related problem where post-compaction conversation history becomes inaccessible
  • Disabling Auto Memory (autoMemoryEnabled: false) is a confirmed workaround
  • The data appears to be preserved in transcript.jsonl but the TUI/context window shows corrupted state

View original on GitHub ↗

This issue has 8 comments on GitHub. Read the full discussion on GitHub ↗