{"slug":"claude-compaction-restore","title":"claude-compaction-restore","summary":"Use when a Claude Code session has just compacted, is about to compact, reached context limit, resumed after /compact, or needs to rebuild its working mental model from Claude JSONL transcripts and touched files.","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-08-31T16:20:53.619167Z","repo":{"url":"https://github.com/mvschwarz/openrig","stars":371,"forks":51,"license":"Apache-2.0","updatedAt":"2026-09-25T04:59:18Z"},"bodyHtml":"<hr>\n<h2>name: claude-compaction-restore\ndescription: Use when a Claude Code session has just compacted, is about to compact, reached context limit, resumed after /compact, or needs to rebuild its working mental model from Claude JSONL transcripts and touched files.\nmetadata:\nopenrig:\nstage: factory-approved\nsibling_skills:\n- mental-model-ha\n- scope-recovery\n- session-compaction-and-restore\n- agent-startup-and-context-ingestion\n- agent-starters\n- composable-priming-packs\n- session-source-fork\n- seat-continuity-and-handover\n- claude-compact-in-place\n- pre-maintenance-agent-preservation</h2>\n<h1>Claude Compaction Restore</h1>\n<p>Use this skill to preserve continuity before Claude Code compacts and to\nrestore continuity after compaction. Do the work described here; do not merely\nexplain the protocol.</p>\n<h2>If You Are About To Compact</h2>\n<p>Prepare durable continuity before the context boundary.</p>\n<ol>\n<li>Identify the active task, queue item, mission/slice, branch or commit, and\ncurrent working directory.</li>\n<li>Record the current state: decisions made, files changed, commands/tests run,\nevidence produced, blockers, caveats, and the next concrete step.</li>\n<li>Create or update a durable mental-model restore map. This map is the main\nartifact future-you will use to rebuild context after compaction.</li>\n<li>In the restore map, write an ASCII file/folder tree of every path that\nmattered to your working mental model during this session. Include:\n<ul>\n<li>the active queue item or mission packet;</li>\n<li>mission notes, progress, decisions, and evidence files;</li>\n<li>Claude memory/project notes you used or wrote, especially when the memory\nfolder is shared by many agents;</li>\n<li>files with active edits or recently inspected source;</li>\n<li>root instructions such as <code>AGENTS.md</code>, <code>CLAUDE.md</code>, or <code>README.md</code>;</li>\n<li>as-built docs, codemaps, conventions, skills, and product docs needed\nbefore code/review work;</li>\n<li>source files, tests, scripts, UI evidence, screenshots, logs, or reports\nthat shaped your current state.</li>\n</ul>\n</li>\n<li>For every file or folder in the tree, add a short note explaining why it\nmatters and whether it is required reading after compaction.</li>\n<li>Write any important glue context that is not already on disk into the\nhandoff/restore map. This includes assumptions, partial conclusions, failed\npaths, and why the listed files fit together.</li>\n<li>In the compaction summary, include the restore map path and the top required\nreading paths from that map.</li>\n</ol>\n<h2>If You Just Compacted</h2>\n<p>Treat your memory as unreliable until you restore from durable evidence.\nRestoration is your current task. Do not wait for a future user request or a\nnew task assignment before reading the required files.</p>\n<ol>\n<li>Read any restore prompt, marker path, packet path, transcript path, restore\nmap, or extra instruction file named by the operator or OpenRig.</li>\n<li>Run the restore script from this skill:</li>\n</ol>\n<pre><code>node ~/.claude/skills/claude-compaction-restore/scripts/restore-from-jsonl.mjs --out /tmp/claude-compaction-restore\n</code></pre>\n<p>If the prompt names a specific Claude JSONL transcript, pass it explicitly:</p>\n<pre><code>node ~/.claude/skills/claude-compaction-restore/scripts/restore-from-jsonl.mjs /path/to/session.jsonl --out /tmp/claude-compaction-restore\n</code></pre>\n<ol start=\"3\">\n<li>Read the generated <code>restore-instructions.md</code>.</li>\n<li>Read the generated <code>touched-files.md</code>.</li>\n<li>Find and read the mental-model restore map if one exists. Treat it as the\nhighest-value guide to which memory files, mission files, source files, and\ndocs mattered before compaction.</li>\n<li>Identify the important files for the active task. The touched-file list is\na triage aid, not a complete inventory.</li>\n<li>Read every important file in full. Prioritize the restore map, Claude memory\nfiles named in the map, Markdown state/planning files, queue/mission packets,\nsource files with active edits, root instruction files, and as-built or\ncodemap docs.</li>\n<li>After the required reads are complete, state:</li>\n</ol>\n<pre><code>restored from packet at &lt;path&gt;; resumed at step &lt;X&gt;\n</code></pre>\n<p>Include the main files you read in full when you make that statement.</p>\n<ol start=\"9\">\n<li><p><strong>REFOCUS BEFORE YOU RESUME — the restore returns your TASK, not your BEARINGS.</strong> Everything\nabove rebuilds <em>what you were doing</em>. None of it rebuilds <em>what the work is for</em> or <em>how this\nrig operates</em> — those live in the chains, and nothing in steps 1–8 walks them. Invoke the\n<code>refocus</code> skill and do its reads before your next substantive move.</p>\n<p><strong>Measured 2026-08-13, and this step exists because of it:</strong> a seat completed this protocol\nfaithfully — packet built, narrative read tail-first, read-depth audit reported honestly — and\nresumed with a perfect picture of its atom and <em>zero</em> work-tree context. It had never opened\nthe mission or project nodes, and could only paraphrase the release's intent second-hand from\na peer's message. It then produced a technically-correct trace concluding <em>\"I hold nothing\"</em>\nwhile holding 18 pending rows. <strong>A restore that returns you to your task without your bearings\nis how a confidently-wrong agent gets back to work.</strong></p>\n</li>\n</ol>\n<p><strong>On the marker and the packet's size (measured across restores, 2026-08):</strong> two realities the restore\nmust handle honestly —</p>\n<ul>\n<li><strong>The per-seat marker (<code>restore-pending/&lt;session&gt;.json</code>) is frequently absent</strong> — in five observed\nrestores it was never present. Treat the JSONL rebuild via <code>restore-from-jsonl.mjs</code> as the <strong>primary</strong>\npath, not a fallback: run it regardless of whether a marker exists. (When product-infra reliably writes\nthe marker for tmux-launched seats, it becomes a fast-path upgrade — not a prerequisite that keeps failing.)</li>\n<li><strong>The generated transcript can be very large</strong> (measured at ~346k tokens in one restore). Do <strong>not</strong>\nread it front-to-back or claim to. <code>restore-instructions.md</code> declares its token cost up front; default\nto the <strong>most recent ~50k tokens of unique narrative first</strong> (recency is what a restore needs — the\nthread that produced the current frontier, not the boot handshake), and go earlier only if a specific\nquestion requires it. A restore must leave room for the work it was restored to do.</li>\n</ul>\n<h2>Required Read-Depth Audit</h2>\n<p>After the first restore pass, audit yourself before continuing.</p>\n<ol>\n<li>List every file, packet, marker, restore map, instruction file, and source\ndocument you were asked to read during restore.</li>\n<li>Mark each item as <code>FULL</code>, <code>PARTIAL</code>, or <code>NOT_READ</code>.</li>\n<li>You will be given a task where all of these files are required reading in\norder to understand the task.</li>\n<li>Read <code>PARTIAL</code>/<code>NOT_READ</code> items in full — but <strong>to a declared budget with a stopping rule</strong>, not\nunbounded. Prioritize by relevance to the active task; for a large transcript read the most recent\nunique narrative first (see <em>If You Just Compacted</em>), not front-to-back.</li>\n<li><strong>Stop</strong> when either every task-relevant item is <code>FULL</code>, or you reach the budget — <em>a restore that\ncannot leave room for the work it was restored to do is not a successful restore.</em> \"Read everything,\nnever conserve\" has no termination condition; that open-endedness is the bug, not the goal.</li>\n<li>Report the final read-depth table <strong>honestly</strong> (<code>FULL</code>/<code>PARTIAL</code>/<code>NOT_READ</code>, each with a reason)\nbefore task work. <strong>An honest <code>PARTIAL</code> with its reason is a correct outcome, not a failure</strong> — do\nnot claim a completion you did not reach.</li>\n</ol>\n<h2>Guardrails</h2>\n<ul>\n<li>Compaction is survival, not housekeeping — never compact to free space, \"lean\" a seat, or capture/prepare an agent starter (the <code>rig agent-image</code> library). It is lossy (a compacted Claude is confident-but-hollow); compact only when a seat is genuinely near its context limit, with a before/after plan. A starter's value is being <em>functional</em>, not small — see the <code>agent-starters</code> skill.</li>\n<li>Do not silently launch fresh after compaction.</li>\n<li>Do not continue from memory when restore evidence exists.</li>\n<li>Do not defer required restore reading until a later user task. The restore is\nthe current task.</li>\n<li>Do not skip root instructions, as-built docs, or codemaps before product\ncode/review work.</li>\n<li>Do not treat the generated touched-file list as exhaustive.</li>\n<li>Do not mark a file <code>FULL</code> unless you actually read the full file content\nafter compaction.</li>\n<li>Do not resume task work until the restore sentinel and read-depth audit are\ncomplete.</li>\n</ul>\n<h2>Failure Modes To Avoid</h2>\n<ol>\n<li><strong>Confidently-wrong restoration</strong>: claiming restoration after reading only\nthe touched-file list or summary.</li>\n<li><strong>Partial restore</strong>: reading the first few files, then continuing before the\nfull reading list is complete.</li>\n<li><strong>Skipping project instructions</strong>: missing <code>AGENTS.md</code>, <code>CLAUDE.md</code>,\n<code>README.md</code>, as-built docs, or codemaps that govern the task.</li>\n<li><strong>Treating the packet as exhaustive</strong>: ignoring mission or workspace files\nthat are important but were not discovered by the script.</li>\n<li><strong>Waiting for the next task</strong>: treating restore reading as conditional on a\nfuture user assignment instead of completing it immediately.</li>\n</ol>\n","files":[{"path":"scripts/precompact-hook.mjs","sizeBytes":12428,"isText":false},{"path":"scripts/restore-from-jsonl.mjs","sizeBytes":20308,"isText":false},{"path":"SKILL.md","sizeBytes":8980,"isText":true},{"path":"templates/compact-instruction.md","sizeBytes":191,"isText":true},{"path":"templates/post-compact-restore-instruction.md","sizeBytes":90,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-09-12T07:22:00.702465Z","sha256":"720E9AFEA2E7F60CE1CEE01B8195DF56B9AF061221FCE053ED0BC970535F116F","sizeBytes":15560},"review":null,"source":{"repositoryUrl":"https://github.com/mvschwarz/openrig","path":"packages/daemon/assets/plugins/openrig-core/skills/claude-compaction-restore","license":"Apache-2.0","commit":"b374dde300fd2a3cf1ee139b89b11e2fa3945784","subtreeSha":"957AD9603A4DC148FC64B098245C9632414A764402F7C150A8BFD2E4B19A4CD8","lastSyncedAt":"2026-09-25T06:48:47.236757Z"},"reviewedAt":"2026-09-12T07:23:12.586851Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/mvschwarz/openrig/tree/main/packages/daemon/assets/plugins/openrig-core/skills/claude-compaction-restore"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install mvschwarz-openrig@llmmart"},{"target":"git","command":"git clone https://github.com/mvschwarz/openrig.git"}]}