Session State Recovery

Session compaction and restore

by mvschwarz · Apache-2.0 license · ★ 4,707 on GitHub

Session compaction and restore cover

Use when reasoning about what survives compaction/context-loss/restart/seat-refresh, designing a high-fidelity restore packet, or distinguishing native runtime resume vs fork vs artifact-backed mental-model rebuild. Covers the 4 failure…

---
name: session-compaction-and-restore
description: Use when reasoning about what survives compaction/context-loss/restart/seat-refresh, designing a high-fidelity restore packet, or distinguishing native runtime resume vs fork vs artifact-backed mental-model rebuild. Covers the 4 failure modes that prevent honest restore (compacted seat drops hot potato; restore packet preserves details but loses product intent; runtime resume mistaken for handover or fork; rebuilt seat starts with stale instructions).
metadata:
  cli_surfaces_referenced:
    - whoami
  openrig:
    stage: factory-approved
    sibling_skills:
      - claude-compaction-restore
      - agent-startup-and-context-ingestion
      - agent-starters
      - session-source-fork
      - seat-continuity-and-handover
      - retiring-and-inheriting-a-seat
---

# Session Compaction and Restore

Overview

Preserving useful working state across compaction, context loss, restart, or seat refresh. Includes Claude compaction restore, Codex resume/fork mechanics, transcript-based mental-model rebuilds, and durable handoff packets.

Manual install (npx, ZIP)
Claude Codenpx skills add mvschwarz/openrig --skill session-compaction-and-restore -g -a claude-code
Claude Code (degit)npx degit mvschwarz/openrig/packages/daemon/assets/plugins/openrig-core/skills/session-compaction-and-restore#main ~/.claude/skills/session-compaction-and-restore
Claude.ai / desktopZip the folder and upload it under Settings → Capabilities → Skills.
Codex, Cursor, other agentsPoint them at SKILL.md. The other files are plain text.

Connects with Agent Alley MCP · agentalley.io/mcp

Files included

  • SKILL.md8.0 KB
Read SKILL.md here
mvschwarz/main1 file shown
SKILL.md
Show the full text156 lines

Session Compaction and Restore

Preserving useful working state across compaction, context loss, restart, or seat refresh. Includes Claude compaction restore, Codex resume/fork mechanics, transcript-based mental-model rebuilds, and durable handoff packets.

Long-lived seats are valuable only if they can survive context pressure. If compaction turns a senior seat into a cold-started agent, users will avoid persistent topologies and fall back to throwaway agents.

Use this when

  • A seat is approaching compaction or just compacted
  • Designing a high-fidelity restore packet for an active workflow
  • Distinguishing native runtime resume vs fork vs artifact-backed mental-model rebuild
  • Reasoning about what should be preserved vs reconstructable
  • Auditing a restore for product-intent preservation (not just detail preservation)

Don't use this when

  • The session is fresh and has no working state to preserve
  • The intent is to create a new seat from a primed source — that's session-source-fork or agent-starters
  • The packet is a one-off snapshot for human review — restore packets are for re-entering active work

The 5 distinctions (do not collapse)

Per the cross-runtime restore/reentry packet standard:

Mode What it means Outcome literal
Native resume Continue the same managed seat with native runtime token resumed
Fork New managed seat from prior native runtime conversation; new post-fork token forked
Rebuild Fresh-launch seeded with operator-declared artifacts in trust-precedence order rebuilt
Artifact-backed mental-model rebuild Restored seat derives understanding from a packet rather than native runtime continuity (case of rebuilt)
Fresh launch New agent without prior continuity fresh

These are load-bearing distinctions. Do NOT collapse fork into artifact-backed reentry; do NOT collapse rebuild into fork.

The three mechanisms — who owns each (verified vs main d37a08ad, 2026-07-21)

The outcomes above ride on three DISTINCT mechanisms; keep them separate:

  1. Claude built-in /compact — a Claude Code HARNESS feature, not OpenRig code. OpenRig only emits the literal /compact toward the pane after a prep turn; there is no compaction algorithm in the OpenRig repo. Provider-owned.
  2. OpenRig-managed restore — the enforcer + hook bridge: a precompact hook WRITES a restore packet; a bridge READER injects exactly ONE restore directive back via the harness hook channel (hookSpecificOutput.additionalContext), seat-isolated. The OpenRig-owned half.
  3. Codex session continuity — resume/rollout tokens (codex resume <token>), a separate path from the Claude mechanisms. Never conflate with Claude restore.

Safety boundary (ties to native-session-file-lab-boundary): no supported OpenRig path EDITS provider-owned native session / auth / transcript files to inject context. Context enters ONLY through sanctioned channels: the hook additionalContext, a normal user message via rig send, or Codex resume tokens. Precise nuance: OpenRig does write ~/.codex/config.toml — but only to install OpenRig activity hooks and [features], never session or auth state. So the rule is "never edits native session/auth/transcript files," NOT "never touches any provider-owned file."

Current CLI surface (operator / kernel seats; verified vs main d37a08ad)

Managed compaction/restore is driven by five shipped verbs — pick per intent, and stay durable-substrate-first (the packet/artifacts are the truth; the CLI is the trigger):

  • rig compact <session> — guided managed compaction for ONE Claude seat (prep → /compact → restore → audit). Non-Claude seats rejected. ~180s.
  • rig compact-plan — READ-ONLY triage; does not compact. Flags --rig, --refresh, --threshold-tokens, --threshold-percent. (Codex seats flagged codex_not_managed_by_claude_compact_in_place.)
  • rig restore-check — restore-readiness probe across running rigs; read-only; exit 0/1/2. Flags --full, --ready, --rig, --no-queue, --no-hooks.
  • rig restore-packet {write,read,validate} — the cross-runtime restore packet (v0): write / read / validate the durable packet this skill's contract defines.
  • rig restore <snapshotId> --rig <rigId> — ⚠ RIG SNAPSHOT restore (infra), a DIFFERENT mechanism — NOT session-context restore. Do not conflate.

Failure modes (4)

  1. A compacted seat forgets active workflow state and drops the hot potato. Compaction without continuity preservation is silent failure.
  2. A restore packet preserves details but loses the user's product intent. Restore must preserve why this work matters, not just what was happening.
  3. A runtime resume is mistaken for a seat handover or fork. These have different continuity outcomes and provenance — don't conflate.
  4. A rebuilt seat starts with stale instructions that conflict with current workflow mode. Restore must include current state, not just historical state.

Proof standard

Proof should include a deliberate compaction/restart of a seat with active work, followed by measured recovery: identity, current workflow, next owner, relevant files, and constraints all restored without human re-briefing.

Canonical packet contract (16-field, v0)

The cross-runtime restore/reentry packet standard v0 defines:

  • Source/target identity
  • Runtimes
  • Workspace root, default repo, role pointer
  • Bounded latest transcript
  • Touched-path inventory
  • Durable work pointers
  • Current work + next owner
  • Caveats + authority boundaries
  • Omitted classes + redaction policy
  • Source-trust ranking
  • Generated-at + generator version

Plus a 6-item restored-seat acceptance checklist.

Source-trust ranking applies when restored seat ingests packet evidence: rig whoami > target rigspec > bounded latest transcript > full transcript > touched-files > restore-summary.json.

Memory surfaces consumed at restore time

A restore may consume transcripts, durable messages, startup context, checkpoints and a restore packet. Inventory the surfaces actually present for this seat, with their source, freshness and purpose. Do not infer that a named surface exists or grants write authority.

The active project/rig policy and task authorization determine what may be written. Treat provider-owned conversation records as evidence to read through supported tooling. For placement and durable context, load skills/openrig-operating-model/SKILL.md with rig context get; for the selected startup path, use skills/core/agent-startup-and-context-ingestion/SKILL.md. A packet or marker proves retained/delivered evidence, not successful provider restoration; measure the resumed seat against the proof standard above.

See also

  • claude-compaction-restore skill — the Claude Code restore SOP (PreCompact hook + JSONL restore script for post-compaction recovery)
  • session-source-fork skill — fork mode for native-runtime-continuity-based restoration
  • seat-continuity-and-handover skill — occupant-creation primitives (resume/fork/rebuild/fresh) that this primitive instantiates
  • openrig-operating-model skill — placement and authority of durable context
1---
2name: session-compaction-and-restore
3description: Use when reasoning about what survives compaction/context-loss/restart/seat-refresh, designing a high-fidelity restore packet, or distinguishing native runtime resume vs fork vs artifact-backed mental-model rebuild. Covers the 4 failure modes that prevent honest restore (compacted seat drops hot potato; restore packet preserves details but loses product intent; runtime resume mistaken for handover or fork; rebuilt seat starts with stale instructions).
4metadata:
5 cli_surfaces_referenced:
6 - whoami
7 openrig:
8 stage: factory-approved
9 sibling_skills:
10 - claude-compaction-restore
11 - agent-startup-and-context-ingestion
12 - agent-starters
13 - session-source-fork
14 - seat-continuity-and-handover
15 - retiring-and-inheriting-a-seat
16---
17 
18# Session Compaction and Restore
19 
20Preserving useful working state across **compaction, context loss,
21restart, or seat refresh.** Includes Claude compaction restore, Codex
22resume/fork mechanics, transcript-based mental-model rebuilds, and
23durable handoff packets.
24 
25**Long-lived seats are valuable only if they can survive context
26pressure.** If compaction turns a senior seat into a cold-started
27agent, users will avoid persistent topologies and fall back to
28throwaway agents.
29 
30## Use this when
31 
32- A seat is approaching compaction or just compacted
33- Designing a high-fidelity restore packet for an active workflow
34- Distinguishing native runtime resume vs fork vs artifact-backed mental-model rebuild
35- Reasoning about what should be preserved vs reconstructable
36- Auditing a restore for product-intent preservation (not just detail preservation)
37 
38## Don't use this when
39 
40- The session is fresh and has no working state to preserve
41- The intent is to *create* a new seat from a primed source — that's `session-source-fork` or `agent-starters`
42- The packet is a one-off snapshot for human review — restore packets are for re-entering active work
43 
44## The 5 distinctions (do not collapse)
45 
46Per the cross-runtime restore/reentry packet standard:
47 
48| Mode | What it means | Outcome literal |
49|---|---|---|
50| **Native resume** | Continue the same managed seat with native runtime token | `resumed` |
51| **Fork** | New managed seat from prior native runtime conversation; new post-fork token | `forked` |
52| **Rebuild** | Fresh-launch seeded with operator-declared artifacts in trust-precedence order | `rebuilt` |
53| **Artifact-backed mental-model rebuild** | Restored seat derives understanding from a packet rather than native runtime continuity | (case of `rebuilt`) |
54| **Fresh launch** | New agent without prior continuity | `fresh` |
55 
56These are load-bearing distinctions. **Do NOT collapse `fork` into
57artifact-backed reentry; do NOT collapse `rebuild` into fork.**
58 
59## The three mechanisms — who owns each (verified vs main d37a08ad, 2026-07-21)
60 
61The outcomes above ride on three DISTINCT mechanisms; keep them separate:
62 
631. **Claude built-in `/compact`** — a Claude Code HARNESS feature, **not OpenRig
64 code**. OpenRig only *emits* the literal `/compact` toward the pane after a prep
65 turn; there is no compaction algorithm in the OpenRig repo. Provider-owned.
662. **OpenRig-managed restore** — the enforcer + hook bridge: a precompact hook
67 WRITES a restore packet; a bridge READER injects exactly ONE restore directive
68 back via the harness hook channel (`hookSpecificOutput.additionalContext`),
69 seat-isolated. The OpenRig-owned half.
703. **Codex session continuity** — resume/rollout tokens (`codex resume <token>`),
71 a separate path from the Claude mechanisms. Never conflate with Claude restore.
72 
73**Safety boundary (ties to `native-session-file-lab-boundary`):** no supported
74OpenRig path EDITS provider-owned native **session / auth / transcript** files to
75inject context. Context enters ONLY through sanctioned channels: the hook
76`additionalContext`, a normal user message via `rig send`, or Codex resume tokens.
77Precise nuance: OpenRig *does* write `~/.codex/config.toml` — but only to install
78OpenRig activity **hooks** and `[features]`, never session or auth state. So the
79rule is "never edits native session/auth/transcript files," NOT "never touches any
80provider-owned file."
81 
82## Current CLI surface (operator / kernel seats; verified vs main d37a08ad)
83 
84Managed compaction/restore is driven by five shipped verbs — pick per intent, and
85stay durable-substrate-first (the packet/artifacts are the truth; the CLI is the trigger):
86 
87- **`rig compact <session>`** — guided managed compaction for ONE Claude seat
88 (prep → `/compact` → restore → audit). Non-Claude seats rejected. ~180s.
89- **`rig compact-plan`** — READ-ONLY triage; *does not compact*. Flags `--rig`,
90 `--refresh`, `--threshold-tokens`, `--threshold-percent`. (Codex seats flagged
91 `codex_not_managed_by_claude_compact_in_place`.)
92- **`rig restore-check`** — restore-readiness probe across running rigs; read-only;
93 exit 0/1/2. Flags `--full`, `--ready`, `--rig`, `--no-queue`, `--no-hooks`.
94- **`rig restore-packet {write,read,validate}`** — the cross-runtime restore
95 packet (v0): write / read / validate the durable packet this skill's contract defines.
96- **`rig restore <snapshotId> --rig <rigId>`** — ⚠ RIG SNAPSHOT restore (infra), a
97 DIFFERENT mechanism — NOT session-context restore. Do not conflate.
98 
99## Failure modes (4)
100 
1011. **A compacted seat forgets active workflow state and drops the hot potato.** Compaction without continuity preservation is silent failure.
1022. **A restore packet preserves details but loses the user's product intent.** Restore must preserve *why this work matters*, not just *what was happening*.
1033. **A runtime resume is mistaken for a seat handover or fork.** These have different continuity outcomes and provenance — don't conflate.
1044. **A rebuilt seat starts with stale instructions that conflict with current workflow mode.** Restore must include current state, not just historical state.
105 
106## Proof standard
107 
108Proof should include a deliberate compaction/restart of a seat with
109active work, followed by **measured recovery**: identity, current
110workflow, next owner, relevant files, and constraints all restored
111without human re-briefing.
112 
113## Canonical packet contract (16-field, v0)
114 
115The cross-runtime restore/reentry packet standard v0 defines:
116 
117- Source/target identity
118- Runtimes
119- Workspace root, default repo, role pointer
120- Bounded latest transcript
121- Touched-path inventory
122- Durable work pointers
123- Current work + next owner
124- Caveats + authority boundaries
125- Omitted classes + redaction policy
126- Source-trust ranking
127- Generated-at + generator version
128 
129Plus a 6-item restored-seat acceptance checklist.
130 
131Source-trust ranking applies when restored seat ingests packet evidence:
132**`rig whoami` > target rigspec > bounded latest transcript > full
133transcript > touched-files > `restore-summary.json`.**
134 
135## Memory surfaces consumed at restore time
136 
137A restore may consume transcripts, durable messages, startup context,
138checkpoints and a restore packet. Inventory the surfaces actually present for
139this seat, with their source, freshness and purpose. Do not infer that a named
140surface exists or grants write authority.
141 
142The active project/rig policy and task authorization determine what may be
143written. Treat provider-owned conversation records as evidence to read through
144supported tooling. For placement and durable context, load
145`skills/openrig-operating-model/SKILL.md` with `rig context get`; for the
146selected startup path, use `skills/core/agent-startup-and-context-ingestion/SKILL.md`.
147A packet or marker proves retained/delivered evidence, not successful provider
148restoration; measure the resumed seat against the proof standard above.
149 
150## See also
151 
152- `claude-compaction-restore` skill — the Claude Code restore SOP (PreCompact hook + JSONL restore script for post-compaction recovery)
153- `session-source-fork` skill — `fork` mode for native-runtime-continuity-based restoration
154- `seat-continuity-and-handover` skill — occupant-creation primitives (resume/fork/rebuild/fresh) that this primitive instantiates
155- `openrig-operating-model` skill — placement and authority of durable context
156 
View all files on GitHub →

Details

License
Apache-2.0
Stars on the repo
★ 4,707
Checked
Source
mvschwarz/openrig ↗
Creator
mvschwarz · 13 listings
View creator

Similar skills

See all →
SkillExperiment Resume Toolalirezarezvani/claude-skills · by alirezarezvaniResume a paused experiment. Checkout the experiment branch, read results history, continue iterating. Use when the user runs /ar:ar-resume or asks to pick up a previously started autoresearch experiment.★ 26.3k GitHub starsSkillComet Classic Workflowrpamis/comet · by rpamisComet Classic workflow entry. Use when the user explicitly invokes /comet-classic, asks to start or resume Classic, or resume-probe returns auto_resume for one unambiguously recoverable active Classic change.★ 3.1k GitHub starsSkillAcademic CV FormatterParamchoudhary/ResumeSkills · by ParamchoudharyFormat CVs for academic positions with publications, grants, and teaching★ 2.4k GitHub starsSkillProduct Manager Resume Reviewphuryn/pm-skills · by phurynComprehensive PM resume review and tailoring against 10 best practices including XYZ+S formula, keyword optimization, job-specific tailoring, and structure. Use when reviewing a PM resume, preparing for job applications, or improving resume impact.★ 26.6k GitHub starsSkillLinkedIn Profile Optimizercharlie947/social-media-skills · by charlie947Rebuild a LinkedIn profile for maximum conversions. Produces new headline options, about section, experience section, featured section strategy, and 4 image generation prompts (banner, profile picture, 2 featured tiles). Use this skill whenever the user says "optimize my profile", "fix my LinkedIn", "rewrite my headline", "profile review", "LinkedIn audit", "rebuild my profile", or wants help with any part of their LinkedIn profile. Also trigger when the user uploads a LinkedIn profile PDF or screenshot for review.★ 3.7k GitHub starsSkillLinkedIn Profile Strategistsergebulaev/linkedin-skills · by sergebulaevAudit and rewrite a LinkedIn profile end-to-end for 2026: headline, About 7-step, Featured, banner, photo, Experience metrics, Skills, custom URL, recommendations. Triggers on "review my profile", "rewrite my headline", "fix my About", "optimize banner", "profile audit", "LinkedIn bio". Converts resume-style profiles to ones that convert 3-5x better. Not for writing feed content (use linkedin-post-writer).★ 3.1k GitHub stars

More from mvschwarz

SkillSession Compaction Restoremvschwarz/openrig · by mvschwarzUse 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.★ 4.7k GitHub starsSkillTask Delegation Advisormvschwarz/openrig · by mvschwarzUse when you have a task and must decide WHO does it — yourself, a spawned subagent, or another agent in the topology that already holds the context. The rule: how much would a blank slate have to read in to do this correctly? A lot → route to a context-holding agent; a little → subagent; unsure → a real agent or yourself. NOT the mechanics of fanning out (that's dispatching-parallel-agents / subagent-driven-development) — this is the who/whether decision, and the failure mode that makes teams abandon subagents.★ 4.7k GitHub starsSkillOpenRig Development Guidemvschwarz/openrig · by mvschwarzUse when changing OpenRig's own source in a clone of the openrig repository: finding which package or file owns a behaviour, choosing which tests to run, testing a change without disturbing the OpenRig daemon your own session runs on, judging whether a diff touches a high-risk area, or preparing a pull request. Not for operating rigs (openrig-skills) or designing rig topologies.★ 4.7k GitHub starsSkillSystem Architecture Primermvschwarz/openrig · by mvschwarzUse when the system around you does not make sense yet: you just booted into a seat and do not know how the pieces fit; someone said rig, pod, seat, fleet, topology, or slice and you are not certain what they mean here; you are unsure what kind of rig you are in or what it is for; you do not know how skills reach you or where context comes from; or you are about to act on a guess about how OpenRig works. Gives the runtime mental model fast, so you stop guessing.★ 4.7k GitHub starsSkillHuman Communication Handlermvschwarz/openrig · by mvschwarzUse when project policy calls for a human decision or update, a human delivery is pending or failed, or a reply must resume the right work.★ 4.7k GitHub starsSkillMission Lifecycle Frameworkmvschwarz/openrig · by mvschwarzUse when starting, building, handing off, restoring, or closing a mission or slice under the default lightweight SDLC.★ 4.7k GitHub stars