Claude Code deletes your old session logs after 30 days by default (~/.claude/projects/*.jsonl). I built session-archive (PyPI) so the full transcript is backed up before that window closes.
pip install session-archive, then:
session-archive archive --dry-run # preview what would be archived
session-archive archive # archive expired sessions
What it does:
- Finds every session older than the retention window (default 30 days, configurable).
- Gzips each one into
<archive>/YYYY-MM/<session-id>.jsonl.gz, byte-for-byte verified before the original is deleted (--no-delete-sourcekeeps originals). - Builds a searchable JSON index: session id, original path, message counts, first/last timestamps, a text preview, and a sha256 per archive.
-
session-archive search "login flow"searches id / project / path / preview;session-archive restore <id>verifies the checksum and writes the original.jsonlback.
Stdlib-only, no dependencies. Config lives in ~/.config/session-archive/config.json; everything is CLI-flag-overridable. Run it manually or on a cron — the point is to run it before day 30.
Backup is not handover
This is deliberately the opposite of my session-handover tool: handover distills a session into a compact packet for the next agent and throws away detail on purpose. session-archive keeps the transcript verbatim — full-fidelity backup, searchable, restorable. Backup and handover are two different jobs; this one does backup.
11 tests, all green (expiry detection, gzip+index, delete/keep-source, dry-run side-effect-free, search, restore round-trip byte-identical, re-archive idempotency, CLI end-to-end).
Top comments (0)