Skip to content
Back to skills

Compaction Survival

ASecurity

Maintain a persisted, re-readable control anchor so a long autonomous run survives context compaction without losing the plot — one file holding the mission, a plan pointer, a live cursor (done / in progress / next action), invariants, last-known-good state, and exact resume steps, updated after each step and re-read at the start of each turn. Use when starting or driving a multi-hour or multi-phase autonomous task, a self-driving loop, or any unattended run that will cross one or more automa...

  • 2 stars
  • 0 votes
  • 0 copies
  • 13 views
  • Added August 31, 2026
ai-agentsrustgodocumentation

Works with

  • cursor

Security analysis

A100/100

Pro scans all 5 files and shows the line behind each finding

Scanned November 10, 2026

npx -y skills add grimaldost/craft-collection --skill compaction-survival --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Compaction Survival?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Compaction Survival
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/grimaldost-compaction-survival/badge)](https://www.skillsdirectory.com/skills/grimaldost-compaction-survival)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: compaction-survival
description: >
  Maintain a persisted, re-readable control anchor so a long autonomous run
  survives context compaction without losing the plot — one file holding the
  mission, a plan pointer, a live cursor (done / in progress / next action),
  invariants, last-known-good state, and exact resume steps, updated after each
  step and re-read at the start of each turn. Use when starting or driving a
  multi-hour or multi-phase autonomous task, a self-driving loop, or any
  unattended run that will cross one or more automatic compactions or
  context-window resets; on asks like "make sure compaction doesn't lose the
  work", "keep state across auto-compact", "persist the current state so a reset
  doesn't disrupt this", "this is a long autonomous run", or "resume cleanly
  after a reset". The anchor is intra-actor state recovery — the same actor
  re-reading its own working state across a discontinuity. Not for handing work
  to a fresh context or a teammate (that is context-handoff's inter-actor
  brief), not for post-hoc capture of what a finished session learned (that is
  journaling-sessions), and not for tracking a short task that fits comfortably
  in one context window. The /anchor command is the one-off snapshot entry
  point; when the running session lacks the plugin surface entirely (stale
  snapshot, harness without the skill menu), references/cold-start.md has the
  by-hand recipe.
---

# Compaction Survival

A long autonomous run loses most often to this — the context that
held the plan gets compacted or reset, and the next turn resumes from a summary
that dropped the load-bearing detail. The defense is an anchor on disk that the
run re-reads and rewrites as it goes, so the plan lives in a file, not only in
the context window.

This is a **flexible** skill: the anchor's schema and update cadence adapt to
the task. What stays firm is small — the anchor is the single source of truth
for run state, re-read at the start of each turn and updated before the state
it describes can be lost. New anchor features are frozen as of 0.26.0: fixes and
documentation still land, and a new capability first needs evidence that the
existing ones are used.

## The anchor

The anchor has authority over task position only: the cursor. A rule that must
never be broken belongs in a hook that enforces it, not in the anchor.

One file, at a stable path the run can find again after a reset. It has two
tiers, split by a literal `<!-- anchor:tail -->` marker line: above it the live
**HEAD** — the only part the re-injection hook emits — and below it the
**TAIL**, which stays on disk. A marker-less anchor still injects whole, but
then a long run's live state is whatever the 8,000-character bound keeps.

HEAD — bounded, rewritten in place. **The order below is the survival order.**
The injection reserves the cursor, then spends what is left top-down and drops
whole trailing sections, naming them: a section's position is its priority for
everything except the cursor, and putting one above another demotes that other.

1. **Mission** — the goal, and the owner's authorizations and instructions about
   *mechanism* as dated, literal quotes with a stable id: a record of what the
   owner said and when, never a grant the anchor makes itself.
2. **Cursor** — done / in progress / **next action on resume**, rewritten in
   place. The newest two steps, newest first; older ones fold into the TAIL at
   each boundary.
3. **Resume steps** — how a cold reader re-orients, in absolute paths.
4. **Invariants** — decisions about the task that a post-compaction turn must
   not relitigate.
5. **Parallel tracks** — a peer run's anchor path and this track's never-touch
   surface, when the trees are shared.
6. **In-flight work** — background tasks the cursor depends on, with a
   do-not-relaunch guard.
7. **Last-known-good** — commits, branches, PRs, tags, files, checkpoints.
8. **Plan pointer** — where the full plan lives, so the anchor stays a cursor.

TAIL — append-only, read on demand: the decisions log, and closed phases' folded
one-line outcomes.

What each section holds and why, and how to measure a draft against the
injection budget: [`references/anchor-spec.md`](references/anchor-spec.md).

## The protocol

1. **Create the anchor at the start of the run**, in `.claude/anchors/` under the
   directory the session started in, before the first irreversible step, so there
   is something to resume from immediately. Arming is also the sweep moment — read
   `scripts/anchor_inject.py --list-dormant <anchors dir>` and close, adopt or park
   any track it names. A subagent anchors in its own work folder, never there; see
   failure-modes.
2. **Update the cursor whenever durable state moves** — a commit, push, deploy step,
   background launch, or write outside the repo. State only in the context window is
   one compaction from gone.
3. **Re-read the anchor at the start of each turn** — especially when a summary
   has appeared or the context feels thinner than the work already done — the
   signs of a compaction. Re-read before acting, not after. A
   cursor is an Edit, so during tool outages it can lag reality by a phase; when
   it disagrees with durable state (the version-control log, run ledgers), trust
   the durable state.
4. **Write atomically and keep one anchor.** Overwrite the single file; a half-written or
   duplicated anchor is worse than a terse one.
5. **Keep the HEAD bounded.** As a phase closes, fold its detail into a
   one-line outcome in the TAIL, below the marker. Measure rather than estimate:
   `scripts/anchor_inject.py --head-fit <anchor>` prints the head's characters
   against the budget and the sections a cut would take.
6. **Make resume idempotent.** The resume steps let a fresh context recover the
   run from the anchor and the real on-disk state alone; re-entering a
   half-finished step checks the artifact before redoing it, so re-reading is
   always safe. A stored recovery command (a ledger-count grep, a resume key)
   is validated against the live artifact before the run goes unattended —
   unchecked, it is a fabricated inference waiting to misfire.
7. **Close by stubbing, then renaming.** When the run ends, rewrite the anchor
   to a minimal landed stub — status, a one-line outcome, resume: none — and
   rename it `<name>.closed.md`. The rename is the only close signal the hook
   honors: a prose "status: CLOSED" line does not stop re-injection, and a
   full-ledger close overflows the injection budget on the next session. Close
   at the moment the cycle ends; a track closed only in prose accumulates. And
   close on the *deliverable*, not the session: if the session carries on into
   new substantive work, arm the next anchor in the same breath — a closed
   anchor beside a live session is an uncovered window. At wind-down, the
   owner's `/anchor close --stale` sweeps the dir for anchors marked done
   in-content but never renamed and offers the exact rename for each.

## Explicit surfaces

- Invoked directly (`/compaction-survival`), arm the protocol now: create or
  refresh the anchor immediately from the current conversation state, then
  follow the update-and-re-read cadence for the rest of the run.
- **`/anchor`** (session-workflow command) is the owner's one-off backstop: a
  single snapshot on demand, with or without this protocol armed — the
  deliberate checkpoint before a manual `/compact`. The model does not invoke
  it, and closes an anchor by the step 7 rename. It replaces asking in prose
  for the state to be persisted; it does not replace the cadence, which is
  what protects against *automatic* compactions that arrive unannounced.
- **Automatic re-injection** ships on; `SESSION_WORKFLOW_ANCHOR_HOOKS=0` opts
  out. A SessionStart hook on `compact`, `resume`, `clear`, and `startup`
  re-injects the newest **active** anchor's HEAD into fresh context, so the
  re-read stops depending on the model remembering the protocol; without
  session-start hooks, the manual re-read is the whole mechanism. `startup`
  (crash restart) injects only an anchor updated within 6h (a pointer if it
  wrote none). Ranking, pointers, cuts: `references/anchor-spec.md`.
- **Cold start without the plugin surface** — a session whose plugin snapshot
  predates the skill, or a harness whose menu omits it, arms everything by hand:
  `references/cold-start.md` has the full recipe (the anchor file by hand, manual
  hook registration, a verify-by-piping step). Because that recipe is unreachable
  exactly when the skill is absent, keep the compact minimal contract — anchor
  path, the `<!-- anchor:tail -->` split, a cursor with a next action, the
  `.closed.md` rename — in the CLAUDE.md protocol snippet, where a menu-less
  session still has it.

## Common failure modes

The recurring ones and what each costs: [`references/failure-modes.md`](references/failure-modes.md).

## Boundaries

The description names the three neighbours this is not. The discriminator worth
having in hand: a handoff is written once and read by someone else; an anchor is
rewritten continuously and read by the same run.

Files in this skill

  • SKILL.md10.2 KB
  • references/cold-start.md3.8 KB
  • references/failure-modes.md2.9 KB
  • scripts/anchor_inject.py20.7 KB
  • scripts/test_anchor_inject.py33.6 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.