[BUG] /compact Command Causes Session Corruption
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?
Bug Report: /compact Command Causes Session Corruption
Summary
The /compact command fails with "Compaction interrupted" error after approximately 60 seconds, and subsequently corrupts the session state, making the session completely unusable (unable to send any messages).
Environment
- Claude Code Version: 2.1.12
- Node.js Version: v25.2.1
- OS: macOS 26.2 (Build 25C56)
- Platform: darwin arm64
- Installation: npm-global
Steps to Reproduce
- Have a long-running session with large conversation history (~41MB jsonl file, ~18,000+ lines)
- Run
/compactcommand - Wait ~60 seconds
- Observe "Compaction interrupted" error
- Try to send any message - it will fail silently (stream starts but stops after ~10 seconds with no response)
Expected Behavior
/compactshould complete successfully for large sessions- If compaction fails, the session should remain in a usable state
- There should be a configurable timeout for compaction operations
Actual Behavior
- Compaction times out at ~60 seconds - Despite setting
API_TIMEOUT_MS: 300000(5 minutes) in settings, compaction still fails around 60 seconds - Session becomes corrupted - After failed compaction:
- The
summary.leafUuidin the jsonl file no longer matches the actual message chain - New messages are recorded but no assistant responses are generated
- Stream starts ("Stream started - received first chunk") but stops after ~10 seconds with no error
- Repeated /compact attempts show no "Summarizing" logs - Indicating the session is in an inconsistent state
Debug Log Analysis
Timeline of Failed Compaction
06:46:00 - /compact command initiated
06:46:02 - Summarizing all 24 messages (~13797 tokens)
06:46:05 - Summarizing all 23 messages (~13797 tokens)
06:46:07 - Summarizing all 23 messages (~14787 tokens)
06:46:09 - Summarizing all 26 messages (~15216 tokens)
06:46:11 - Summarizing all 32 messages (~15489 tokens)
06:46:13 - Stream started - received first chunk (last successful stream)
06:46:20 - [INTERRUPTION] - No completion log, jumped to user input handling
06:46:37 - ERROR: "Error in non-streaming fallback: Request was aborted"
Subsequent /compact Attempts (All Failed ~60s)
| Attempt | PreCompact Time | Snapshot Time | Duration |
|---------|-----------------|---------------|----------|
| 1 | 06:46:39 | 06:48:35 | ~116s |
| 2 | 06:49:47 | 06:50:37 | ~50s |
| 3 | 06:54:44 | 06:55:45 | ~61s |
| 4 | 06:55:51 | 06:56:51 | ~60s |
| 5 | 06:56:56 | 06:57:56 | ~60s |
| 6 | 07:03:06 | 07:04:32 | ~86s |
Note: After setting API_TIMEOUT_MS: 300000, attempt #6 took 86s, suggesting the setting partially worked, but compaction still failed.
Key Observations
- No "Summarizing" logs after first failure - Context shows only
1065 chars, indicating partial compaction occurred - Session file corruption -
summary.leafUuid(415a744a-35fc-47fe-973f-d4644ce17f1f) doesn't match current message chain - Messages send but get no response - Debug shows "Stream started" then "Stop" after ~10 seconds with no error
Session State Analysis
Session ID: 8d5acade-f4aa-44d1-b6f0-e6c15c87608f
Session File Size: 42MB
Session Lines: 18,923
Context after partial compact: 1065 chars (extremely small)
Message Chain Issue
The last user message (590ab490) has no corresponding assistant response in the jsonl file, and the session enters "idle_prompt" state without ever generating a response.
Configuration
// ~/.claude/settings.json
{
"env": {
"DISABLE_TELEMETRY": "1",
"DISABLE_ERROR_REPORTING": "1",
"MCP_TIMEOUT": "60000",
"API_TIMEOUT_MS": "300000" // Added after initial failures
}
}
Suggested Fixes
- Implement atomic compaction - Compaction should either fully complete or fully rollback, never leaving session in partial state
- Add dedicated compaction timeout setting -
COMPACT_TIMEOUT_MSseparate from general API timeout - Increase default compaction timeout - 60 seconds is too short for large sessions
- Add compaction progress indicators - Show which batch is being processed
- Implement compaction recovery - Detect and repair corrupted session state
- Add session validation - Verify
summary.leafUuidmatches actual message chain on session load
Workaround
Currently, the only workaround is to abandon the corrupted session and start a new one with claude --new.
Additional Files
Debug log file location: ~/.claude/debug/8d5acade-f4aa-44d1-b6f0-e6c15c87608f.txt (12MB)
Session file location: ~/.claude/projects/-Users-stone-Works-AIO-AIO/8d5acade-f4aa-44d1-b6f0-e6c15c87608f.jsonl (42MB)
---
Severity: High - Session becomes completely unusable after this bug occurs
Impact: Data loss - All conversation history in the affected session becomes inaccessible
What Should Happen?
Expected Behavior
/compactshould complete successfully for large sessions- If compaction fails, the session should remain in a usable state
- There should be a configurable timeout for compaction operations
Error Messages/Logs
Steps to Reproduce
- Have a long-running session with large conversation history (~41MB jsonl file, ~18,000+ lines)
- Run
/compactcommand - Wait ~60 seconds
- Observe "Compaction interrupted" error
- Try to send any message - it will fail silently (stream starts but stops after ~10 seconds with no response)
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.1.12
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Other
Additional Information
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗