Session Persistence & Storage Architecture
Overview
Sessions are the unit of durability in Claude Code. Every conversation is recorded, compressed, and stored for later retrieval, resume, or analysis. This system enables long-term memory and conversation recovery.
Plain text
┌─────────────────────────────────────────────────────────────────────────────┐
│ SESSION LIFECYCLE │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ CREATE │
│ │ │
│ ▼ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Start │───►│ Messages │───►│ Write to │ │
│ │ Session │ │ Buffer │ │ Disk │ │
│ │ │ │ (memory) │ │ (.jsonl) │ │
│ └─────────────┘ └──────┬──────┘ └──────┬──────┘ │
│ │ │ │
│ RUNTIME ──► Continuous append to disk │ │
│ │ │ │
│ ▼ ▼ │
│ ┌─────────────┐ ┌─────────────┐ │
│ │ Auto-Save │ │ Sessions │ │
│ │ (every 5s) │ │ Registry │ │
│ └─────────────┘ │ (index) │ │
│ └──────┬──────┘ │
│ │ │
│ END ──► Final flush + metadata update │ │
│ │ │
│ ┌─────────────┐ ┌─────────────┐ │ │
│ │ Compress │───►│ Update │◄──────────┘ │
│ │ History │ │ Index │ │
│ │ (gzip) │ │ │ │
│ └─────────────┘ └─────────────┘ │
│ │
│ RESUME ──► Load from disk ──► Replay messages ──► Continue conversation │
│ │
└─────────────────────────────────────────────────────────────────────────────┘