Skip to content

feat: Session mirror compress — deduplicate resumed session content #24

@martymcenroe

Description

@martymcenroe

Problem

When Claude Code resumes a session (--continue or --resume), it re-renders the entire previous conversation in the Ink TUI. The PTY reader sees all that re-rendered output and writes it to the new session mirror file. This means:

  1. The old mirror file has lines 1-5000 from the original session
  2. The new mirror file has lines 1-5000 (re-rendered) + lines 5001-8000 (new work)
  3. With 10K line truncation, the duplicated replay eats into the budget

Observation

The re-rendered content should be nearly identical to what was already captured in the previous session's mirror. The line count from the replay should be roughly constant and the content should match line-for-line (same Ink TUI, same conversation data).

Proposed Solution: Compress Command

A post-hoc --compress option that deduplicates resumed session content:

# Compress the current session mirror (remove duplicated replay blocks)
unleashed --compress logs/session-20260213-081257.log

# Or automatically on startup — detect replay and skip writing until new content appears

Algorithm (Post-Hoc)

  1. Read the new mirror file
  2. Find the longest prefix that matches a suffix of the previous mirror file
  3. Remove the duplicated prefix from the new mirror
  4. Optionally merge both mirrors into one continuous file

Algorithm (Real-Time, Harder)

  1. On session start, check if Claude is replaying (rapid burst of content with no permission prompts)
  2. Buffer the replay content
  3. Compare against the most recent previous mirror file
  4. Start writing to the new mirror only when content diverges from the old mirror

The post-hoc approach is simpler and more reliable since it doesn't need to distinguish replay from fast new work in real time.

Impact

With 10K line truncation (#23), this matters more: a 5K-line resumed session wastes half the budget on duplicate content. Compress would reclaim those lines.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions