resume shows stale messages: broken parentUuid chain after context compaction

Open 💬 4 comments Opened Apr 11, 2026 by pkusnail

Bug

claude --resume <session-id> displays messages from days ago instead of the most recent conversation, making it appear that hours of recent work have been lost.

Root Cause

Context compaction creates new messages whose parentUuid references a UUID that was part of the compacted (deleted) context. This UUID never gets written to the session JSONL file, breaking the parentUuid chain.

When --resume reconstructs the conversation by walking the parentUuid chain backwards from the last message, it hits a break point and can only reach a subset of messages. The terminal then renders from the earliest reachable message, which may be days old.

Reproduction

In a long-running session (10K+ messages, multiple compactions over several days):

  1. Work normally for several hours after the last compaction
  2. Exit the session (Ctrl+C or accidental disconnect)
  3. claude --resume <session-id>
  4. Expected: see the most recent messages
  5. Actual: see messages from days ago; recent work appears lost (but is present in the JSONL file)

Analysis

Session JSONL structural analysis (no content, only metadata):

{
  "total_lines": 11595,
  "total_uuids": 10549,
  "broken_parent_references": 10,
  "messages_reachable_from_last_message": 1813,
  "messages_orphaned": 8736
}

Each broken reference follows the same pattern:

  • A message has parentUuid pointing to a UUID that does not exist anywhere in the JSONL as a uuid field
  • The missing parent was likely part of context that was compacted away
  • The compaction replaced old messages with a summary but didn't update child messages' parentUuid to point to the summary message instead

Example of chain break (UUID prefixes only, no content):

Line N:   uuid=dc6f3d47  parent=cff6bd7b  ts=2026-04-07T17:37  ← chain OK
Line N+1: uuid=4835f006  parent=43936483  ts=2026-04-07T17:39  ← parent 43936483 MISSING

The file has 10 such breaks, all occurring around compaction events. The deepest break (at depth 1813 from the last message) causes --resume to only render ~17% of the conversation.

Suggested Fix

When context compaction removes messages from the conversation, update the parentUuid of the first post-compaction message to point to the compaction summary message (or the last surviving message before the compacted range). This maintains chain continuity.

Alternatively, --resume rendering could fall back to chronological order when the parentUuid chain is broken, rather than stopping at the break point.

Environment

  • Claude Code version: 2.1.96 → 2.1.101 (bug spans multiple versions)
  • OS: macOS (Darwin, Apple Silicon)
  • Session duration: ~4 days, 8 compaction events

View original on GitHub ↗

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