Skip to content

feat: Session mirror log rotation and cleanup #23

@martymcenroe

Description

@martymcenroe

Problem

Session mirror logs grow unbounded and accumulate noise, especially from early versions before the cursor-tracking ANSI parser was implemented.

Current state:

  • 111,423 lines across 10 session mirror files
  • Largest single session: 49,607 lines (1.5MB)
  • Current session: 10,518 lines (550KB)
  • Much of the older content is garbage — raw ANSI artifacts, spinner frames, duplicated lines from before mirror_strip_ansi() was implemented

The session mirror tab (tail -f) becomes slow and hard to navigate in long sessions. The log files on disk accumulate without cleanup.

Proposed Solutions

1. Log Rotation (Within a Session)

  • Cap mirror log at N lines (e.g., 5,000) or N MB (e.g., 2MB)
  • When the cap is hit, rotate: rename current to session-{ts}.1.log, start fresh
  • Or truncate the top (oldest content) and keep the bottom (most recent)
  • tail -f handles rotation gracefully with tail -F (follows file name, not inode)

2. Session Startup Cleanup

  • On launch, archive or delete session mirror logs older than N days
  • Or compress old logs (gzip)
  • Add a --keep-days <N> flag (default: 7)

3. Smarter Filtering (Reduce Volume)

  • The cursor-tracking parser already filters a lot, but long sessions still produce thousands of lines
  • Consider rate-limiting mirror writes (e.g., flush every 500ms instead of every PTY read)
  • Deduplicate more aggressively — current dedup window is 32 lines, could be larger
  • Skip writing during heavy TUI repaints (detect rapid cursor-home sequences)

4. Summary Mode

  • Instead of raw transcript, periodically write a summary line:
    [09:15:23] Working on: updating CLAUDE.md files (5 tool calls in last 2 min)
  • Would require tracking tool call patterns, but dramatically reduces volume

Immediate Quick Win

Delete/archive the pre-parser garbage logs. Everything before the cursor-tracking parser was added is mostly unreadable noise.

Acceptance Criteria

  • Session mirrors stay under a reasonable size (configurable)
  • Old logs are cleaned up automatically
  • tail -f remains responsive in long sessions
  • No data loss for recent session content

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