session-state-snapshot-reuse

Save and restore conversation state using JSONL snapshots with atomic writes.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/liuyu520/cc_source --skill session-state-snapshot-reuse
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: session-state-snapshot-reuse
Source: https://github.com/liuyu520/cc_source/tree/main/.claude/skills/session-state-snapshot-reuse
Command: npx skills add https://github.com/liuyu520/cc_source --skill session-state-snapshot-reuse

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides reusable patterns for saving and restoring conversation state by snapshotting the messages to disk and loading them back in a deterministic, JSONL-based format.

Core Features & Use Cases

  • Snapshot → Store → Restore workflow: serialize messages to per-line JSON, write atomically using a .tmp file and rename to prevent corruption.
  • Load and apply: read the JSONL, parse each line into Message objects, and apply with context.setMessages to restore a prior session state.
  • Reusable, portable storage guidance: uses session-scoped project directories and portable paths to keep per-session state co-located with the working project.
  • Examples and references: file paths and utility modules in the codebase demonstrate how to integrate and reuse the pattern in features that checkpoint or manipulate messages.

Quick Start

Use this skill when saving conversation state to disk, restoring from a saved state, manipulating the messages array, or building features that need conversation checkpointing.

Frequently Asked Questions about session-state-snapshot-reuse

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I save and restore conversation state to disk using JSONL snapshots?

To save and restore conversation state, serialize messages to per-line JSON in JSONL format and write atomically using a .tmp file and rename operation to prevent corruption. Restore by reading the JSONL, parsing each line into Message objects, and applying them with context.setMessages.

What's the best way to implement conversation checkpointing for session state?

Conversation checkpointing is best implemented using a Snapshot → Store → Restore workflow that serializes messages to per-line JSON and uses atomic write discipline with .tmp files and renames. This ensures session state remains uncorrupted during persistence and enables deterministic state restoration.

Why does atomic write discipline matter when persisting session state to JSONL files?

Atomic write discipline matters for session state persistence because it prevents file corruption by writing to a .tmp file first and renaming it only after successful serialization. This guarantees the JSONL snapshot remains intact even if the process crashes during the write operation.

Can I use session-scoped project directories for storing conversation snapshots?

Yes, you can use session-scoped project directories to store conversation snapshots. This Skill employs portable paths to keep per-session state co-located with the working project, ensuring saved JSONL snapshots remain accessible and organized for subsequent state restoration.

How do I restore a prior session state from saved JSONL messages?

To restore a prior session state from saved JSONL messages, read the JSONL file, parse each line into Message objects, and apply them using context.setMessages. This replaces the current UI state and deterministically reconstructs the conversation from the persisted snapshot.

When do I need JSONL format for message snapshot persistence?

You need JSONL format for message snapshot persistence when building features that require conversation checkpointing, state restoration, or message manipulation. JSONL provides per-line serialization that allows deterministic saving and loading of individual session state records without parsing an entire JSON document.