Skip to content

Back up CLI --resume transcripts so idle tabs stay resumable - #26

Merged
SergKam merged 1 commit into
mainfrom
feat/session-transcript-backup
Jun 19, 2026
Merged

SergKam merged 1 commit into
mainfrom
feat/session-transcript-backup

Conversation

@SergKam

@SergKam SergKam commented Jun 19, 2026

Copy link
Copy Markdown
Owner

Problem

Tabs left idle for weeks fail to resume with "No conversation found with session ID", even though the full chat history is still on screen.

Root cause: claude --resume <id> reads the CLI's own transcript at ~/.claude/projects/<encoded-cwd>/<id>.jsonl — not our chat history. The CLI prunes those by age (cleanupPeriodDays, default 30 days), so a long-idle workspace loses its backing file and can no longer be resumed.

Fix

Keep a rolling backup of each session's CLI transcript under ~/.config/flycrys/sessions/transcripts/<id>.jsonl, so it survives the CLI's cleanup (and manual cleanup, disk wipes, machine migration).

  • Off the main thread. The locate + copy run on a worker thread during autosave — the GTK main loop only spawns it. Sync copy only on shutdown so the final turn is captured before exit.
  • Zero idle churn. Gated on chat-history growth (reuses the existing autosave signal), so it only runs when a conversation actually advances. A stat-only up-to-date check skips redundant copies.
  • Safe writes. Atomic temp+rename copy; a reader never sees a half-written transcript.
  • Encoding-robust. Computes the CLI project-dir name from cwd as a fast path, falls back to scanning project folders (session ids are UUIDs, so a match is unambiguous).

Note on recovery

This PR is backup only — no auto-restore on resume failure (by design). Resume keeps working because the live transcript is preserved; pair this with a raised cleanupPeriodDays so the CLI stops pruning the originals. If an original is ever lost, restoring is a manual file copy from the backup dir back to ~/.claude/projects/<encoded-cwd>/.

Tests

Unit tests cover the project-dir encoding, the up-to-date check, and the atomic copy (no temp files left behind). cargo clippy --lib --bins -- -D warnings clean; full suite green.

`claude --resume <id>` reads the CLI's own transcript at
~/.claude/projects/<encoded-cwd>/<id>.jsonl, which the CLI prunes by age
(cleanupPeriodDays, default 30). A workspace left idle past that window
loses its backing file and can no longer resume ("No conversation found
with session ID"), even though we still hold the full chat history.

Keep a rolling copy under ~/.config/flycrys/sessions/transcripts/. The
locate + copy run on a worker thread during autosave (sync only on
shutdown), gated on chat-history growth so there is zero idle churn and
the GTK main loop never touches the disk. Atomic temp+rename copy; a
stat-only up-to-date check skips redundant writes.

Tests cover the project-dir encoding, the up-to-date check, and the
atomic copy.
@SergKam
SergKam merged commit 3242400 into main Jun 19, 2026
2 checks passed
@SergKam
SergKam deleted the feat/session-transcript-backup branch June 19, 2026 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant