Skip to content

Sessions Overview

Reference for session initialization, transcript persistence, automatic compaction, resumption, and cleanup. Sessions capture all interactions in immutable JSONL transcripts stored under ~/.claude/sessions/, keyed by project and session ID.

  1. How sessions work
  2. Transcript storage
  3. Session resume
  4. Cleanup & retention
  5. Context management
  6. Auto-compaction
  7. Transcript entry types
  8. Startup recovery
  9. Discrepancies & notes

9 sections, 11+ subsystems covering session state, persistence, resumption, and memory management.

#SectionDescriptionKey files/paths
1How sessions workLifecycle stages: start → message turns → compact → persist → resume. Lazy materialization on first write.sessionStorage.ts, utils/cleanup.ts
2Transcript storageJSONL format, path structure (~/.claude/sessions/projects/<sanitized>/<uuid>.jsonl), metadata tail re-append.sessionStorage.ts:202-207, getProjectDir, sanitizePath
3Session resume--resume/--continue flag behavior, metadata reader (64KB tail), what’s restored vs. dropped, pagination.sessionStorage.ts:448-461, sessionHistory.ts
4Cleanup & retention30-day default (cleanupPeriodDays), disabled via --no-session-persistence, test env, or cleanupPeriodDays=0.cleanup.ts:23-30, settings keys
5Context managementGit status snapshot (2k char cap, cached), CLAUDE.md auto-discovery, per-conversation memoization.context.ts:20-111, getSystemContext, getUserContext
6Auto-compactionTriggered at context-window-20k threshold, 20k output reserve, file+skill restoration, circuit breaker at 2 retries.autoCompact.ts:28-49, compact.ts:122-130
7Transcript entry types17+ entry types: TranscriptMessage, SummaryMessage, AiTitleMessage, CustomTitleMessage, TaskSummaryMessage, etc.types/logs.ts:297-317
8Startup recoveryRelease notes cached to ~/.claude/cache/changelog.md, terminal backup recovery from ~/.claude/backups/.releaseNotes.ts, setup.ts:115-157
9Discrepancies & notesKnown gaps: session state transience, task survival via transcript, metadata tail edge cases.Gaps between docs and implementation

Quick reference — session state by context

Section titled “Quick reference — session state by context”
ContextSession IDStoredOn resumeCleanup
Interactive shell (claude .)UUID, lazy-generatedJSONL on first turnMetadata from tail, full transcript on --resume30-day default; --no-session-persistence disables
Spawned by Tungsten (tmuxSocket)UUIDSkipped (env: CLAUDE_CODE_SKIP_PROMPT_HISTORY)Not availableNever cleaned (not persisted)
Test suite (NODE_ENV=test)UUIDOptional (TEST_ENABLE_SESSION_PERSISTENCE)Not availableNever cleaned
Non-interactive (--stdin, CI)UUIDSkipped (isSessionPersistenceDisabled())Not availableNever cleaned