[BUG] /compact Command Causes Session Corruption

Resolved 💬 3 comments Opened Jan 20, 2026 by yishuiliunian Closed Jan 23, 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?

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

  1. Have a long-running session with large conversation history (~41MB jsonl file, ~18,000+ lines)
  2. Run /compact command
  3. Wait ~60 seconds
  4. Observe "Compaction interrupted" error
  5. Try to send any message - it will fail silently (stream starts but stops after ~10 seconds with no response)

Expected Behavior

  • /compact should 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

  1. Compaction times out at ~60 seconds - Despite setting API_TIMEOUT_MS: 300000 (5 minutes) in settings, compaction still fails around 60 seconds
  2. Session becomes corrupted - After failed compaction:
  • The summary.leafUuid in 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
  1. 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

  1. No "Summarizing" logs after first failure - Context shows only 1065 chars, indicating partial compaction occurred
  2. Session file corruption - summary.leafUuid (415a744a-35fc-47fe-973f-d4644ce17f1f) doesn't match current message chain
  3. 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

  1. Implement atomic compaction - Compaction should either fully complete or fully rollback, never leaving session in partial state
  2. Add dedicated compaction timeout setting - COMPACT_TIMEOUT_MS separate from general API timeout
  3. Increase default compaction timeout - 60 seconds is too short for large sessions
  4. Add compaction progress indicators - Show which batch is being processed
  5. Implement compaction recovery - Detect and repair corrupted session state
  6. Add session validation - Verify summary.leafUuid matches 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

  • /compact should 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

  1. Have a long-running session with large conversation history (~41MB jsonl file, ~18,000+ lines)
  2. Run /compact command
  3. Wait ~60 seconds
  4. Observe "Compaction interrupted" error
  5. 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_

View original on GitHub ↗

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