Claude compaction restore skill

Use when a Claude Code session is about to compact, has just compacted, reached its context limit, resumed after /compact, or must rebuild its working picture of a long-running seat from its own restore map, its JSONL transcript and the files it touched.

by mvschwarz·Apache-2.0 license·★ 4,707 Stars on the repo·GitHub ↗

Use now

Files of Claude compaction restore

mvschwarz/main1 file shown
SKILL.md
Show the full text225 lines

Claude Compaction Restore

Compaction keeps facts and loses connections. After a compaction you still know file names, row ids and decisions as items. What you lose is the web between them: why a file matters, what depends on what, which decision produced which artifact, what you were about to do next, and how this window relates to the ones before it. Seats whose value is a wide, long-running picture (planners, orchestrators, reviewers holding a standard) lose the most.

This skill keeps that picture alive across compactions. Before compacting, you write a restore map: a short summary plus the connections between things that already exist on disk. After compacting, you re-enter the world, read your own map, and rebuild the picture before acting. Over several compactions the maps chain into one continuous record: a global context window that outlives any single session.

The previous version of this skill is kept at reference/SKILL-v1.md for comparison.

What survives, and what you write

Already on disk; point to it, don't copy it:

  • your session JSONL at ~/.claude/projects/<cwd-slug>/<session-uuid>.jsonl (the post-compaction restore request names the exact path). It holds every message and tool call you made, in order. It does not hold your reasoning;
  • the restore packet the PreCompact hook writes (transcript extract, touched-file triage);
  • queue rows and their transitions, mission files (SPEC.md, NOTES.md, PROGRESS.md), your seat's LEARNED.md, evidence folders, branches and PRs.

Only in your head; write it down:

  • why each important thing matters, and to whom;
  • how things relate: depends on, supersedes, answers, contradicts, was produced by, is owned by;
  • decisions and the reasons for them, options you rejected, judgment and taste you applied;
  • where you were in time: what earlier windows established, what this window did, what comes next and who authorizes it;
  • where to look deeper: which JSONL range or file answers which question.

The map is the second list, pinned to the first.

Two restore classes

Every restored seat must come back competent. It should understand the OpenRig world and its command surface, the project, its own role, and where it stands in time. Some seats also need the global picture.

Both classes read the same thing: the ranked reading list in your own map, in order. They differ only in how far down the list they go.

Class Who Reads
Default drivers, builders, reviewers, QA, and any seat not listed below Tier 1: the top of the list, to about 100k of real context
High-context orchestrators, planners, advisors, leads: any seat that makes product, scope or routing decisions Tier 1 and Tier 2, to about 200k of real context

The tiers are real context added by the restore, on top of what the compaction summary leaves (about 60k). These budgets assume a context window of about 1M tokens; on a smaller window, scale them to about 10% and 20% of it. File size is a poor guide to that cost: in OpenRig's own runs, real context grew 1.7 to 2 times the bytes ÷ 4 estimate, because of line numbers on reads, tool output and your own reasoning. So rank to about 50k of bytes ÷ 4 for Tier 1 and about 100k for Tier 2, and check real usage at each checkpoint with rig compact-plan --json (your seat's estimatedUsedTokens).

Tier 2 buys width, not depth: more sources, more connections, more of the mission's history and the wider worlds, not the same files read more fully. Choose your class from your role (rig whoami --json). A per-seat instruction file or your own map can name the class explicitly, and that overrides the role default. In both classes, transcripts and the session JSONL appear only as targeted line ranges, never as whole files.

If there is no ranked list (no preparation turn happened), use this default order. Default seats stop at about 100k of real context:

  1. the post-compaction world profile;
  2. the mission or slice SPEC.md and NOTES.md;
  3. rows you hold.

High-context seats then add, to about 200k:

  1. the full System World install;
  2. the full Project World, public and private;
  3. the mission's PROGRESS.md and recent returns;
  4. previous maps and RESTORED notes;
  5. LEARNED.md.

If You Are About To Compact

You are about to lose every connection you have built. Spend this turn making them durable.

  1. Think back before writing. Walk the session and, through your previous map, the windows before it. What were the threads? What did you work out about how the pieces fit? What is unfinished? What did you decide, and why? What were you about to be wrong about?
  2. Write the restore map in your seat folder, not in scratch (scratch can be cleaned while you are compacted): <topology root>/rigs/<rig>/seats/<seat>/RESTORE-MAP-<UTC yyyymmdd-hhmm>.md. Derive the folder from rig whoami --json and rig config get topology.root. Run date -u for the timestamp and every time you write in the map. Do not estimate times: an estimated time can land before events it describes, as one did in an early run.
  3. Open the map with a summary of 10 to 20 lines: who you are, what you hold, what mattered in this window, what is next and who authorizes it, and any hold in force. Publish that summary as your seat recap too: save it, plus a line naming the map's path, to a file and run rig context recap-write --rig <rig> --seat <seat> --file <that file>. If your world profile has a seat recap atom, it loads this recap, and an old recap would be served as if it were current.
  4. Then write the connections. Choose what this seat needs; these are examples, not a template:
    • State: rows you hold (id, state), branches and PR heads, the hold or release in force and who gave it, the mission and slice you work in.
    • Nodes with purpose: each file, row, PR or evidence folder that matters, one line each on what it is and why it matters.
    • Edges: "A depends on B", "C supersedes D", "this decision produced that file", "E answers question F", "G is owned by seat H", "I and J disagree; unresolved".
    • Judgment: decisions with reasons, rejected options, what the human cares about here, the tells you caught or nearly missed.
    • Time: what the previous map said happened before, what happened this window, what is next.
    • Lookups: JSONL line ranges or uuids for threads worth re-reading (grep -n the JSONL for a row id or timestamp), and which file holds the evidence for which claim.
    • A small file tree of the paths above, each with a one-line note, when that helps navigation.
  5. Rank what your restored self should read. End the map with a reading list ordered by importance.
    • What each entry gives:
      • the path;
      • the exact part to read (a heading, a line range, or a JSONL range found with grep -n), not the whole file unless the whole file is the point;
      • its approximate size (bytes ÷ 4 ≈ tokens; wc -c);
      • one line on why it matters.
    • The first entry is the post-compaction world profile, with its size from rig context profile … --json (totalEstimatedTokens).
    • Tier lines: keep a running bytes ÷ 4 total, draw the Tier 1 line at about 50k (about 100k of real context), and continue to about 100k for Tier 2 (about 200k real).
    • Rank for connections. Prefer the entry that connects the most other things you need, and choose a section that explains how things fit over a long file of detail you can look up later.
  6. Link the chain. Name the previous restore map (and its RESTORED note, if one exists) so a later reader can walk back through earlier windows.
  7. Keep it readable in one pass. Aim for something you could read in a few minutes: point instead of copying, and leave out what a command can re-derive.
  8. Update the durable homes you own as usual: a lesson that changes future decisions goes in LEARNED.md; mission state goes in the mission's own files; work another seat must act on goes in a queue row. The map points to these rather than repeating them.
  9. End the preparation turn by stating the map path. OpenRig sends /compact next; the summary should name the map path and the next authorized step.

A map that lists files without saying how they connect is an inventory, and an inventory is what compaction already leaves you. The edges are the point.

If You Just Compacted

You have facts without connections. Rebuild the connections before you act on anything.

  1. Check for a hold first. Read the restore request, the per-seat instruction file (<OPENRIG_HOME>/compaction/post-compact-extra/<session>.md, named by your full session such as [email protected]) when it exists, the newest row or message from whoever routes your work, and any hold from the authority above them. A hold, a release order or an operator's own restore map overrides the default order below. Before any write, also run rig whoami --json and rig queue whoami.
  2. Name your class and state its read budget before reading (see "Two restore classes"), with a checkpoint at each step below. The budget exists so that the restore leaves room for the work it was restored to do. Step 5 takes a high-context seat to its Tier 2 line; the extra sources under "Two restore classes" apply only when there is no ranked list.
  3. Re-enter the world. Load the post-compaction world profile your instance provides. Find it with rig context list; for a private world install, run rig context profile <world-ref> --situation post-compaction --rig <rig> --seat <seat> (the seat flags are needed for its seat-scoped recap atom; take both values from rig whoami --json). Without a private world, run rig context profile world-public --situation post-compaction and rig context get onboarding-width. This restores how the system works before you restore what you were doing in it.
  4. Read your own restore map in full: the newest RESTORE-MAP-*.md in your seat folder, which the compaction summary should name. If it points to an earlier map for context you need, read that too.
  5. Read down the map's ranked list to your class's tier line, reading exactly the parts each entry names. Then check every row you hold (rig queue show <id> --full --json) and anything that may have changed since the map was written: merged PRs, new rows, a new hold. The map records what was true when it was written; current state still has to be derived.
  6. Use the packet and the JSONL as lookups, not as reading lists: go to a specific line range when a specific question needs it. The packet's restore-instructions.md and touched-files.md help find things the map does not cover.
  7. If there is no map (the preparation turn did not happen), fall back to the packet: read restore-instructions.md, then the most recent unique narrative, tail first, within the budget; and say in your report that you restored without a map.
  8. Reply with the sentence the restore request asks for, normally restored from packet at <path>; resumed at step <X>, naming the map you used. When no packet exists, give the map's path as <path> and say that you restored from the map.

Required Read-Depth Audit

The audit message asks for a read-depth table and tells you not to conserve tokens. Do both in this form:

  1. List every item you were asked to read (request, instruction files, packet, map, and the sources the map marks required) with FULL, PARTIAL or NOT_READ, the ranges you actually read, and a reason. Mark FULL only for content you read after this compaction; content carried in through the summary is inherited, not read, and a file the harness re-attached after compaction is PARTIAL (injected), not FULL, until you read it.
  2. Read in full now every required item that is not yet FULL. "Required" means the ranked entries above your class's tier line, in the exact parts they name. Everything else is lookup-only: every file in the restore packet (touched-files.md, restore-instructions.md, transcript.md, transcript-latest.md, restore-summary.json), the session JSONL and archives. Those stay NOT_READ with the reason "lookup only", unless a human or the owning seat releases them. The audit message's "do not optimize for token conservation" applies to required items: read those fully rather than skimming them. It does not turn lookups into reading lists. In an early run of this skill, reading the packet transcripts during the audit cost a default seat about 75k, more than the restore itself.
  3. Reconnect, in writing. In the same reply, and in a short RESTORED-<UTC yyyymmdd-hhmm>.md beside the map:
    • where you are in time: what earlier windows established, what the last window did, what is true now;
    • the connections you have rebuilt, in a few lines;
    • the connections you could not rebuild, and where you would look;
    • the next authorized step and who authorizes it. If a hold stands, the next step is waiting.

The next restore map links this note, which keeps the chain unbroken.

Guardrails

  • Compaction is survival, not housekeeping. Compact only when a seat is genuinely near its limit, never to "lean" a seat or prepare a starter image; a compacted seat can sound confident while missing the context it needs.
  • Continue from the map and the files, not from the summary's "next step" alone: a hold placed after the summary was written still binds.
  • Do not launch a fresh session in place of restoring.
  • An honest PARTIAL with its reason is a correct outcome. Claiming coverage you did not reach is the failure.
  • Do not resume task work until the read-depth table and the reconnect note exist.

Failure modes

  1. Inventory instead of map: a list of paths with no edges. The restored seat knows where things are and not why they matter.
  2. Confident restoration: acting on the summary after reading only the touched-file list.
  3. Reading to exhaustion: reading the whole transcript or every linked file and leaving no room for the work.
  4. Map in scratch: writing the map somewhere that is cleaned before you restore.
  5. Broken chain: a map that does not name the previous one, so earlier windows are lost on the second compaction.
1---
2name: claude-compaction-restore
3description: Use when a Claude Code session is about to compact, has just compacted, reached its context limit, resumed after /compact, or must rebuild its working picture of a long-running seat from its own restore map, its JSONL transcript and the files it touched.
4metadata:
5 openrig:
6 sibling_skills:
7 - session-compaction-and-restore
8 - agent-startup-and-context-ingestion
9 - agent-starters
10 - session-source-fork
11 - seat-continuity-and-handover
12---
13 
14# Claude Compaction Restore
15 
16Compaction keeps facts and loses connections. After a compaction you still know file names, row ids and
17decisions as items. What you lose is the web between them: why a file matters, what depends on what, which
18decision produced which artifact, what you were about to do next, and how this window relates to the ones
19before it. Seats whose value is a wide, long-running picture (planners, orchestrators, reviewers holding a
20standard) lose the most.
21 
22This skill keeps that picture alive across compactions. Before compacting, you write a **restore map**: a
23short summary plus the connections between things that already exist on disk. After compacting, you
24re-enter the world, read your own map, and rebuild the picture before acting. Over several compactions the
25maps chain into one continuous record: a global context window that outlives any single session.
26 
27The previous version of this skill is kept at `reference/SKILL-v1.md` for comparison.
28 
29## What survives, and what you write
30 
31**Already on disk; point to it, don't copy it:**
32- your session JSONL at `~/.claude/projects/<cwd-slug>/<session-uuid>.jsonl` (the post-compaction restore
33 request names the exact path). It holds every message and tool call you made, in order. It does not hold
34 your reasoning;
35- the restore packet the PreCompact hook writes (transcript extract, touched-file triage);
36- queue rows and their transitions, mission files (`SPEC.md`, `NOTES.md`, `PROGRESS.md`), your seat's
37 `LEARNED.md`, evidence folders, branches and PRs.
38 
39**Only in your head; write it down:**
40- why each important thing matters, and to whom;
41- how things relate: depends on, supersedes, answers, contradicts, was produced by, is owned by;
42- decisions and the reasons for them, options you rejected, judgment and taste you applied;
43- where you were in time: what earlier windows established, what this window did, what comes next and who
44 authorizes it;
45- where to look deeper: which JSONL range or file answers which question.
46 
47The map is the second list, pinned to the first.
48 
49## Two restore classes
50 
51Every restored seat must come back competent. It should understand the OpenRig world and its command
52surface, the project, its own role, and where it stands in time. Some seats also need the global picture.
53 
54Both classes read the same thing: the **ranked reading list** in your own map, in order. They differ only in
55how far down the list they go.
56 
57| Class | Who | Reads |
58|---|---|---|
59| **Default** | drivers, builders, reviewers, QA, and any seat not listed below | Tier 1: the top of the list, to about **100k** of real context |
60| **High-context** | orchestrators, planners, advisors, leads: any seat that makes product, scope or routing decisions | Tier 1 and Tier 2, to about **200k** of real context |
61 
62The tiers are **real context added by the restore**, on top of what the compaction summary leaves (about 60k).
63These budgets assume a context window of about 1M tokens; on a smaller window, scale them to about 10% and
6420% of it. File size is a poor guide to that cost: in OpenRig's own runs, real context grew 1.7 to 2 times the bytes ÷ 4 estimate,
65because of line numbers on reads, tool output and your own reasoning. So rank to about **50k of bytes ÷ 4 for
66Tier 1** and about **100k for Tier 2**, and check real usage at each checkpoint with
67`rig compact-plan --json` (your seat's `estimatedUsedTokens`).
68 
69Tier 2 buys **width, not depth**: more sources, more connections, more of the mission's history and the wider
70worlds, not the same files read more fully. Choose your class from your role (`rig whoami --json`). A per-seat
71instruction file or your own map can name the class explicitly, and that overrides the role default. In both
72classes, transcripts and the session JSONL appear only as targeted line ranges, never as whole files.
73 
74If there is no ranked list (no preparation turn happened), use this default order. Default seats stop at about
75100k of real context:
761. the post-compaction world profile;
772. the mission or slice `SPEC.md` and `NOTES.md`;
783. rows you hold.
79 
80High-context seats then add, to about 200k:
811. the full System World install;
822. the full Project World, public and private;
833. the mission's `PROGRESS.md` and recent returns;
844. previous maps and `RESTORED` notes;
855. `LEARNED.md`.
86 
87## If You Are About To Compact
88 
89You are about to lose every connection you have built. Spend this turn making them durable.
90 
911. **Think back before writing.** Walk the session and, through your previous map, the windows before it.
92 What were the threads? What did you work out about how the pieces fit? What is unfinished? What did you
93 decide, and why? What were you about to be wrong about?
942. **Write the restore map** in your seat folder, not in scratch (scratch can be cleaned while you are
95 compacted): `<topology root>/rigs/<rig>/seats/<seat>/RESTORE-MAP-<UTC yyyymmdd-hhmm>.md`. Derive the
96 folder from `rig whoami --json` and `rig config get topology.root`. **Run `date -u` for the timestamp and
97 every time you write in the map. Do not estimate times**: an estimated time can land before events it
98 describes, as one did in an early run.
993. **Open the map with a summary** of 10 to 20 lines: who you are, what you hold, what mattered in this
100 window, what is next and who authorizes it, and any hold in force. **Publish that summary as your seat
101 recap** too: save it, plus a line naming the map's path, to a file and run
102 `rig context recap-write --rig <rig> --seat <seat> --file <that file>`. If your world profile has a seat
103 recap atom, it loads this recap, and an old recap would be served as if it were current.
1044. **Then write the connections.** Choose what this seat needs; these are examples, not a template:
105 - **State:** rows you hold (id, state), branches and PR heads, the hold or release in force and who gave
106 it, the mission and slice you work in.
107 - **Nodes with purpose:** each file, row, PR or evidence folder that matters, one line each on what it is
108 and why it matters.
109 - **Edges:** "A depends on B", "C supersedes D", "this decision produced that file", "E answers question
110 F", "G is owned by seat H", "I and J disagree; unresolved".
111 - **Judgment:** decisions with reasons, rejected options, what the human cares about here, the tells you
112 caught or nearly missed.
113 - **Time:** what the previous map said happened before, what happened this window, what is next.
114 - **Lookups:** JSONL line ranges or uuids for threads worth re-reading (`grep -n` the JSONL for a row id
115 or timestamp), and which file holds the evidence for which claim.
116 - **A small file tree** of the paths above, each with a one-line note, when that helps navigation.
1175. **Rank what your restored self should read.** End the map with a reading list ordered by importance.
118 - **What each entry gives:**
119 - the path;
120 - the exact part to read (a heading, a line range, or a JSONL range found with `grep -n`), not the
121 whole file unless the whole file is the point;
122 - its approximate size (bytes ÷ 4 ≈ tokens; `wc -c`);
123 - one line on why it matters.
124 - **The first entry** is the post-compaction world profile, with its size from
125 `rig context profile … --json` (`totalEstimatedTokens`).
126 - **Tier lines:** keep a running bytes ÷ 4 total, draw the Tier 1 line at about 50k (about 100k of real
127 context), and continue to about 100k for Tier 2 (about 200k real).
128 - **Rank for connections.** Prefer the entry that connects the most other things you need, and choose a
129 section that explains how things fit over a long file of detail you can look up later.
1306. **Link the chain.** Name the previous restore map (and its `RESTORED` note, if one exists) so a later
131 reader can walk back through earlier windows.
1327. **Keep it readable in one pass.** Aim for something you could read in a few minutes: point instead of
133 copying, and leave out what a command can re-derive.
1348. **Update the durable homes you own** as usual: a lesson that changes future decisions goes in
135 `LEARNED.md`; mission state goes in the mission's own files; work another seat must act on goes in a queue
136 row. The map points to these rather than repeating them.
1379. **End the preparation turn** by stating the map path. OpenRig sends `/compact` next; the summary should
138 name the map path and the next authorized step.
139 
140A map that lists files without saying how they connect is an inventory, and an inventory is what compaction
141already leaves you. The edges are the point.
142 
143## If You Just Compacted
144 
145You have facts without connections. Rebuild the connections before you act on anything.
146 
1471. **Check for a hold first.** Read the restore request, the per-seat instruction file
148 (`<OPENRIG_HOME>/compaction/post-compact-extra/<session>.md`, named by your full session such as
149 `[email protected]`) when it exists, the newest row or message from whoever routes your work, and any hold
150 from the authority above them. A hold, a release order or an operator's own restore map overrides the default
151 order below. Before any write, also run `rig whoami --json` and `rig queue whoami`.
1522. **Name your class and state its read budget** before reading (see "Two restore classes"), with a
153 checkpoint at each step below. The budget exists so that the restore leaves room for the work it was
154 restored to do. Step 5 takes a high-context seat to its Tier 2 line; the extra sources under "Two restore classes" apply only
155 when there is no ranked list.
1563. **Re-enter the world.** Load the post-compaction world profile your instance provides. Find it with
157 `rig context list`; for a private world install, run
158 `rig context profile <world-ref> --situation post-compaction --rig <rig> --seat <seat>` (the seat flags are
159 needed for its seat-scoped recap atom; take both values from `rig whoami --json`). Without a private world,
160 run `rig context profile world-public --situation post-compaction` and `rig context get onboarding-width`. This restores how the system works before you
161 restore what you were doing in it.
1624. **Read your own restore map in full**: the newest `RESTORE-MAP-*.md` in your seat folder, which the
163 compaction summary should name. If it points to an earlier map for context you need, read that too.
1645. **Read down the map's ranked list** to your class's tier line, reading exactly the parts each entry names.
165 Then check every row you hold (`rig queue show <id> --full --json`) and anything that may have changed since
166 the map was written: merged PRs, new rows, a new hold. The map records what was true when it was written;
167 current state still has to be derived.
1686. **Use the packet and the JSONL as lookups**, not as reading lists: go to a specific line range when a
169 specific question needs it. The packet's `restore-instructions.md` and `touched-files.md` help find
170 things the map does not cover.
1717. **If there is no map** (the preparation turn did not happen), fall back to the packet: read
172 `restore-instructions.md`, then the most recent unique narrative, tail first, within the budget; and say in
173 your report that you restored without a map.
1748. Reply with the sentence the restore request asks for, normally
175 `restored from packet at <path>; resumed at step <X>`, naming the map you used. When no packet exists, give
176 the map's path as `<path>` and say that you restored from the map.
177 
178## Required Read-Depth Audit
179 
180The audit message asks for a read-depth table and tells you not to conserve tokens. Do both in this form:
181 
1821. **List every item** you were asked to read (request, instruction files, packet, map, and the sources the
183 map marks required) with `FULL`, `PARTIAL` or `NOT_READ`, the ranges you actually read, and a reason.
184 Mark `FULL` only for content you read after this compaction; content carried in through the summary is
185 inherited, not read, and a file the harness re-attached after compaction is
186 `PARTIAL (injected)`, not `FULL`, until you read it.
1872. **Read in full now** every required item that is not yet `FULL`. "Required" means the ranked entries
188 above your class's tier line, in the exact parts they name. Everything else is lookup-only: **every file in the restore packet**
189 (`touched-files.md`, `restore-instructions.md`, `transcript.md`, `transcript-latest.md`, `restore-summary.json`),
190 the session JSONL and archives. Those stay
191 `NOT_READ` with the reason "lookup only", unless a human or the owning seat releases them. The audit
192 message's "do not optimize for token conservation" applies to required items: read those fully rather
193 than skimming them. It does not turn lookups into reading lists. In an early run of this skill, reading
194 the packet transcripts during the audit cost a default seat about 75k, more than the restore itself.
1953. **Reconnect, in writing.** In the same reply, and in a short `RESTORED-<UTC yyyymmdd-hhmm>.md` beside the
196 map:
197 - where you are in time: what earlier windows established, what the last window did, what is true now;
198 - the connections you have rebuilt, in a few lines;
199 - the connections you could not rebuild, and where you would look;
200 - the next authorized step and who authorizes it. If a hold stands, the next step is waiting.
201 
202The next restore map links this note, which keeps the chain unbroken.
203 
204## Guardrails
205 
206- Compaction is survival, not housekeeping. Compact only when a seat is genuinely near its limit, never to
207 "lean" a seat or prepare a starter image; a compacted seat can sound confident while missing the context it needs.
208- Continue from the map and the files, not from the summary's "next step" alone: a hold placed after the
209 summary was written still binds.
210- Do not launch a fresh session in place of restoring.
211- An honest `PARTIAL` with its reason is a correct outcome. Claiming coverage you did not reach is the
212 failure.
213- Do not resume task work until the read-depth table and the reconnect note exist.
214 
215## Failure modes
216 
2171. **Inventory instead of map:** a list of paths with no edges. The restored seat knows where things are and
218 not why they matter.
2192. **Confident restoration:** acting on the summary after reading only the touched-file list.
2203. **Reading to exhaustion:** reading the whole transcript or every linked file and leaving no room for the
221 work.
2224. **Map in scratch:** writing the map somewhere that is cleaned before you restore.
2235. **Broken chain:** a map that does not name the previous one, so earlier windows are lost on the second
224 compaction.
225 

Discussion