[BUG] Context corruption: auto-memory/compaction causes previous conversation content to be mixed or truncated
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:
- Previous conversation content is truncated or cut off — messages from earlier in the session disappear or become incomplete
- Content from different sessions appears mixed — fragments of older conversations appear in the current session context
- 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
- Enable Auto Memory (default in v2.1.59+)
- Start a long conversation with multiple tool calls and file reads
- Continue working until context compaction triggers automatically
- Observe that earlier messages are truncated or mixed with unrelated content
- Running
/compactmanually 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.jsonlbut the TUI/context window shows corrupted state
This issue has 8 comments on GitHub. Read the full discussion on GitHub ↗