-
Notifications
You must be signed in to change notification settings - Fork 0
Description
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:
- The old mirror file has lines 1-5000 from the original session
- The new mirror file has lines 1-5000 (re-rendered) + lines 5001-8000 (new work)
- 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 appearsAlgorithm (Post-Hoc)
- Read the new mirror file
- Find the longest prefix that matches a suffix of the previous mirror file
- Remove the duplicated prefix from the new mirror
- Optionally merge both mirrors into one continuous file
Algorithm (Real-Time, Harder)
- On session start, check if Claude is replaying (rapid burst of content with no permission prompts)
- Buffer the replay content
- Compare against the most recent previous mirror file
- 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
- feat: Session mirror log rotation and cleanup #23 — Session mirror log rotation (10K truncation, implemented)
- feat: Document and test Claude Code CLI passthrough args #21 — CLI passthrough (enables
--continue/--resumewhich triggers this)