agentleFS
IlyaGorskyIlyaGorsky/memory-toolkit/skills/session-restore/SKILL.md

session-restore

Skill13 starsChanged 11 days agoMITView on GitHub

Context restoration from .jsonl session backups. Parses history, builds chronology, saves key decisions to memory.

3 other projects use a version of this.

Adopted by

Most recently taken up by

  • Other versions3 projects use a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 3

    1. Arman-Kudaibergenov/1c-ai-development-kit★ 163same name
    2. AhmedAbdelfattah0/AI-Skills★ 4same name
    3. anymasoft/1c-ai★ 0same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository9 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

6 rules. 0 are common, 3 are distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Write to memory file project_session_snapshot.md:

    line 106
  2. Distinctive:

    Update MEMORY.md if needed

    line 131
  3. Distinctive:

    Search for a specific moment in session history:

    line 135
  4. Distinctive:

    If there are many results (>10) — show the first 5 and ask "show more?"

    line 167
  5. Very specific:

    If not found in .jsonl — check .jsonl.bak

    line 168
  6. Very specific:

    If .bak exists — it contains the full history before compact, .jsonl may contain a compact summary

    line 174

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Session Restore — backup and context restoration

Parses .jsonl files of Claude Code sessions, extracts chronology and key decisions.

Where data is stored

~/.claude/projects/-<project-key>/
├── <UUID>.jsonl          # current session (or completed)
├── <UUID>.jsonl.bak      # backup before last compact
└── <UUID>/
    └── subagents/        # subagent logs

Commands

/session-restore list

Show all sessions with dates and sizes:

SESSIONS_DIR="${CLAUDE_CONFIG_DIR:-$HOME/.claude}/projects/$(pwd | sed 's/[^a-zA-Z0-9]/-/g')"
ls -lat "$SESSIONS_DIR"/*.jsonl 2>/dev/null | head -20

Output a table: | File | Date | Size | .bak |

/session-restore restore

Restore context from the latest (or specified) session:

  1. Find the file — by default the most recent .jsonl, or by UUID from the argument
  2. Parse — extract USER and CLAUDE messages using python3:
import json, sys

path = sys.argv[1]
with open(path) as f:
    lines = f.readlines()

for i, line in enumerate(lines):
    try:
        obj = json.loads(line.strip())
        role = obj.get('role', '?')
        msg_type = obj.get('type', '?')
        c = obj.get('message', {}).get('content', obj.get('content', ''))

        if isinstance(c, list):
            for item in c:
                if isinstance(item, dict):
                    tp = item.get('type', '')
                    if tp == 'text':
                        text = item.get('text', '').strip()
                        if role == '?' and msg_type == 'user':
                            if text and not text.startswith('<ide_') and not text.startswith('<system') and not text.startswith('<local-command') and not text.startswith('<command-') and len(text) > 5:
                                print(f'USER [{i}]: {text[:200]}')
                        elif role == '?' and msg_type == 'assistant':
                            if text and len(text) > 20:
                                print(f'  CLAUDE [{i}]: {text.split(chr(10))[0][:200]}')
        elif isinstance(c, str):
            clean = c.strip()
            if role == '?' and msg_type == 'user' and clean and not clean.startswith('<') and len(clean) > 3:
                print(f'USER [{i}]: {clean[:200]}')
            elif role == '?' and msg_type == 'assistant' and clean and len(clean) > 20:
                print(f'  CLAUDE [{i}]: {clean.split(chr(10))[0][:200]}')
    except:
        pass
  1. Group into blocks — identify thematic blocks of the session (by topic changes)
  2. Show the user a brief chronology:
## Session restoration <UUID>
Date: <file date>
Lines: <N>

### Block 1: <topic>
- <what was done>
- <key decisions>

### Block N: <topic>
- <what was done>
- **Last action:** <what was happening at the moment of termination/crash>
  1. Find the termination reason — check the last 20 lines:
    • API Error — crash, specify the reason
    • context summary — compact, context was compressed
    • Normal termination — user closed the session

/session-restore backup

Save current session state to memory:

  1. Identify the current task (from todo, plan, or context)
  2. Write to memory file project_session_snapshot.md:
---
name: Session snapshot
description: Session state snapshot as of <date>
type: project
---

## Task
<what we are doing>

## Done
- <list>

## In progress
- <current step>

## Remaining
- <list>

## Key decisions
- <decisions that affect further work>
  1. Update MEMORY.md if needed

/session-restore search <query>

Search for a specific moment in session history:

  1. Find the file — the most recent .jsonl (or .jsonl.bak for pre-compact history)
  2. Grep — quick search through jsonl without full parsing:
grep -i "<query>" "$SESSIONS_DIR"/*.jsonl | head -30
  1. Context — for each found fragment, show ±5 lines around it (to understand the topic):
grep -n -i "<query>" <file> | head -10
# for each line number:
sed -n '<line-5>,<line+5>p' <file>
  1. Parse the results — extract text from JSON, filter out system messages
  2. Show the result:
## Search: "<query>" in <file>
Found: N matches

### Match 1 (line N)
USER: <text>
CLAUDE: <text>

### Match 2 (line N)
...
  1. If there are many results (>10) — show the first 5 and ask "show more?"
  2. If not found in .jsonl — check .jsonl.bak

Rules

  • During restore DO NOT show system messages, ide_opened_file, tool calls — only USER and CLAUDE text
  • Group by topics, not by lines — the user needs the big picture, not a log
  • If .bak exists — it contains the full history before compact, .jsonl may contain a compact summary
  • During backup do not duplicate what is already in memory files — only save what is missing
  • For large sessions (>10K lines) parse in chunks using offset

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.