← all decks
Capability Deck · Internal

The code survives.
The reasoning doesn't.

context-save captures the why behind a project into eight terse, version-controlled files — written at the exact moments an AI session is about to forget everything it learned.

context-save · claude-shared · 2026-07-16

Every session ends by throwing away the reasoning that produced the code.

Git remembers what changed. It does not remember why we picked Postgres over Mongo, which constraint made that retry loop necessary, or the trap someone already fell into twice. That knowledge lives in the conversation — and conversations get compacted, cleared, and exited. When the transcript dies, the reasoning dies with it, and the next session re-derives it from scratch. Or worse, derives something different.

0
Decisions that survive a /clear by default
5
Ways a session ends and takes its reasoning with it
~75%
Of the app we want rebuildable from the notes alone*

*A design target, not a measured result — see Risks. The five endings: Stop, SubagentStop, PreCompact, SessionEnd, and an explicit /clear, /compact, /exit or /quit.

01 · The gap

So we made the AI write down the why — at the moment it's about to forget.

A set of hooks that fire when context is about to be lost, and a discipline that routes what was learned into eight terse markdown files in the repo — so the next session, human or AI, starts where the last one stopped. — context-save, in one sentence

Three design principles, ranked:

  • Truth over narrative. Only what is true, marked [IMPLEMENTED], [PLANNED], or [DEPRECATED]. A file that lies is worse than no file at all — the next session believes it.
  • A default nobody has to configure. Eight canonical files ship inside the skill. Projects don't declare them; they inherit them, and only name what's uniquely theirs.
  • Capture at the boundary, not from memory. Nobody remembers to write docs at 2am. The hooks fire on their own — and when the stakes are high enough, they refuse to let the session end quietly.
02 · The shape

Three ideas make the whole thing make sense.

This is the scaffolding everything else in the deck hangs on. Each one answers a question people ask in their first five minutes with the system.

1

Directives and knowledge are different things

CLAUDE.md tells the agent what to do. docs/context/ records what is true. They never repeat each other — a rule the skill enforces explicitly. Mixing them is how both become unreadable.

2

Every fact has exactly one home

Eight files, eight questions. Before writing anything the test is "which ONE question does this answer?" A fact in two places is a fact that will disagree with itself in three months.

3

The file set is inherited, not declared

The eight are baked into the skill. A project appends only its own additions via extends:. Nobody re-types the defaults, so nobody's defaults drift.

Idea 3 is the newest — it shipped today. It is also the one the proposed program tier extends one level further up.

03 · Mental model

Where context-save sits: between a session ending and the knowledge that should outlive it.

Triggers above, sinks below. The skill itself holds no state — it is a routing discipline. Everything it produces lands in git, next to the code it describes, in the same commit.

Triggers
Lifecycle hooks
Stop · SubagentStop · PreCompact · SessionEnd
Prompt hook
UserPromptSubmit on /clear /compact /exit /quit
The human
/context-save · /context-save init
↓ fire
Skill
context-save
reads CLAUDE.md frontmatter → resolves the effective file set (default 8 ∪ extends ∪ auto-discovered) → routes each learning to exactly one destination → scans for test gaps
↓ ↓ ↓ ↓
Sinks
docs/context/*.md
the canonical eight · git'd · bundled with the code commit
agent-memory
project gotchas · one memory per lesson · promoted later
troubleshooting skill
lessons true across every service, not just this one
/qatests
handoff when the test-gap scan finds holes

Two things worth noticing. The skill writes nothing outside the repo it's working in — except gotchas, which it deliberately routes sideways into agent-memory because they accrete and don't suit a static file. And there is no server: this is a skill plus two shell hooks, not a service.

04 · System architecture

From a hook firing to a fact on disk — five stages.

All five run without you. The only place a human appears is the last one, and only if the test scan found something.

1

Fire

A context-loss boundary is reached. The hook estimates how much pressure the session is under from the size of the transcript.

→
2

Assess

What actually changed this session, and which of the context files does that touch?

→
3

Route

For each learning: which single file answers it? Canonical first, then project extensions, then sideways to memory.

→
4

Write

Terse bullets, status-marked, under a 200-line ceiling. When a file is full, something old gets pruned.

→
5

Scan & bundle

Check the session's code for missing tests, offer /qatests, and stage everything into the same commit as the code.

The bundling rule in stage 5 is load-bearing, not tidiness: context changes ride with the code that caused them, so a reviewer sees the claim and the change together, and drift between them shows up in the diff rather than months later.

05 · Lifecycle

What do you want to know more about?

Quick recap: context-save is a skill plus two hooks. When an AI session is about to lose its context — it stops, compacts, or you type /clear — the hooks fire and make it write what it learned into eight terse markdown files in the repo, one fact per file, bundled into the same commit as the code. The eight are baked into the skill, so every project inherits them and declares only its own additions. The goal is that if the code vanished, the notes would rebuild most of it. Each card below opens a focused topic; the purple one is a proposal, not shipped.
06 · Index
← hub

Eight files, eight questions, one home per fact.

The set isn't arbitrary — it's the questions someone would have to answer to rebuild the system. If a fact doesn't answer one of these, it probably doesn't belong in docs/context/ at all.

FileThe question it answersWhat lives there
requirements.mdWhat must this do?Business rules, user workflows, product constraints
architecture.mdHow do the pieces connect?Components, boundaries, data flow, service topology
interfaces.mdWhat are the contracts?APIs, schemas, entities, events, config surfaces
conventions.mdHow is the code written here?Patterns, naming, frameworks, libraries, module layout
security.mdWho is allowed to do what?Auth, secrets, trust boundaries, access rules
operations.mdHow does it run?Deployment, containers, networking, config, runtime
testing.mdWhat must not break?Critical paths, regression checks, coverage strategy
invariants.mdWhat must always hold?Hard rules — anchored, and cited by ADRs and tests

invariants.md is the newest of the eight; its template shipped today. It's different in kind from the rest — the others describe, it forbids. Entries there get anchors so a test or a design record can point at one and say "this is the rule I'm enforcing."

topic · the eight (1/2)
← hub

The rules that keep the files worth reading.

Every one of these exists because the failure it prevents is what kills documentation. Nobody abandons docs because they were too short.

Must

  • Terse — bullets and tables. No prose paragraphs.
  • Factual — only what is true, or explicitly marked [PLANNED].
  • Scoped — each entry belongs to exactly one file.
  • Bounded — under 200 lines. Full means prune, not append.
  • Atomic — each bullet stands alone, no surrounding context needed.

Must not

  • No filler, pleasantries, or narrative.
  • No timestamps on entries — git already knows.
  • No repeating what's in CLAUDE.md — directives and knowledge stay separate.
  • No empty section headers.
  • No context-only commits — it rides with the code.

The 200-line ceiling is the one people push back on. It's deliberate: an unbounded file is an append-only log, and an append-only log is something no one reads. Forcing a prune forces a judgment about what still matters — which is the actual work.

topic · the eight (2/2)
← hub

Projects inherit the eight. They declare only what's theirs.

This changed today. It's worth seeing what it replaced, because the old shape had a slow failure mode that nobody would have noticed for months.

Before

Every project re-declared the whole list

  • Each CLAUDE.md listed all eight files by name.
  • Adding a ninth canonical file meant editing every project.
  • A project that mistyped or omitted one silently lost that file — no error, just a gap.
  • The defaults drifted apart, project by project, invisibly.
After

The eight are baked in; projects append

  • The default set lives inside the skill. Nobody re-declares it.
  • A project names only its additions, via extends:.
  • Drop a new .md into docs/context/ and it's auto-discovered — adoption costs nothing.
  • Improving the default improves every project at once.

Resolution order: start from the default eight, unless files: is present — that replaces the default for projects that genuinely want less. Then append extends:. Then add anything auto-discovered. Effective set = default ∪ extensions.

topic · extends (1/2)
← hub

Four lines of frontmatter is the whole configuration surface.

This block goes at the top of a project's CLAUDE.md. Every key is optional — a project that writes none of it still gets the correct eight.

---
context-save:
  extends: [signal-lifecycle, options-exec]      # APP-SPECIFIC files, appended to the default eight.
                                                 #   ← this is the knob you actually want
  files: [architecture, operations, invariants]   # OPTIONAL. Replaces the default (a trim, not an add).
                                                 #   Omit unless you truly want fewer than eight.
  gotchas_via_memory: false                       # true  → gotchas route to agent-memory (one per lesson)
                                                 # false → keep a plain local gotchas.md
  routing:                                        # OPTIONAL. Teach the skill where app content belongs —
    trading-rules: tradingrequirements.md         #   especially big docs living OUTSIDE docs/context/
---
      

One rule for extension files: each must open with a one-line > Purpose: … header, so its scope is obvious to the next reader without opening anything else. Same terse rules as the canonical eight apply.

If the frontmatter is missing entirely but docs/context/ exists, the skill uses the default eight plus whatever it auto-discovers, and suggests a one-time /context-save-upgrade to make the choice explicit rather than accidental.

topic · extends (2/2)
← hub

Inside the box: how one hook fire becomes one written fact.

The interesting part isn't the writing — it's the decision at the top. The hook has to guess how much trouble the session is in, using only what it can cheaply see.

 Session reaches a boundary
 (agent stops · subagent stops · about to compact · session ends · user types /clear)
        │
        │ hook payload includes transcript_path
        ▼
   ┌─────────────────────────────────────────────────────────────────┐
   │ context-save-check.sh  /  context-save-on-prompt.sh             │
   │   1. Estimate context pressure                                   │
   │      · proxy = size of the transcript file on disk               │
   │      · PreCompact is bumped one tier — the next compaction       │
   │        will lose detail no matter what we decide here            │
   │   2. Measure the work at stake                                   │
   │      · lines of code diff this session                           │
   │      · has docs/context/ been touched already?                   │
   │   3. Pick a response tier  →  nudge, remind, or BLOCK            │
   └────────────────────┬────────────────────────────────────────────┘
                        │ always injects the routing checklist,
                        │ whatever the tier
                        ▼
   ┌─────────────────────────────────────────────────────────────────┐
   │ The routing checklist (the actual discipline)                   │
   │   (a) decisions, tradeoffs      → architecture.md / requirements.md
   │   (b) lessons — project-scope   → agent-memory (or gotchas.md)  │
   │       lessons — every service   → troubleshooting skill          │
   │   (c) user corrections          → feedback memory                │
   │   (d) changes that move arch /  → the matching context file      │
   │       interfaces / security /                                    │
   │       operations                                                 │
   └────────────────────┬────────────────────────────────────────────┘
                        │ agent writes, terse + status-marked
                        ▼
   ┌─────────────────────────────────────────────────────────────────┐
   │ git — staged into the SAME commit as the code                   │
   └─────────────────────────────────────────────────────────────────┘
      

Note what the checklist does that a reminder can't: it names the destination for every category. "Remember to document" produces nothing. "Decisions go here, cross-service lessons go there" produces a file edit.

topic · tool-context (1/2)
← hub

The tier that decides whether you get a nudge or a wall.

Only one row in this table actually stops you. That restraint is the design — a system that blocks constantly gets routed around, and then it protects nothing.

What the hook seesPressureWhat happens
Code changed >15 diff lines · docs/context/ untouched high / critical Blocks the stop. The agent cannot finish until it saves. On /clear or /exit, blocks the prompt — you resubmit once the saves land.
Code changed >15 diff lines · docs/context/ untouched low / medium Strong reminder, naming the eight files explicitly. No block.
docs/context/ already touched this session any Soft reminder plus the checklist. Never escalates — you already did the thing.
Minor code changes only any Soft reminder.
No code changed — a decision-only session any Checklist only. Decisions still need a home even when nothing was built.

Two judgments are embedded here and both are debatable. Transcript size as a proxy for context pressure is crude — a long session about nothing scores the same as a dense one. And 15 lines is a guess at where "worth documenting" starts. Both are cheap to compute and required no new instrumentation, which is why they won.

topic · tool-context (2/2)
← hub
Proposed · not built · no code exists

The same duplication problem, one level up.

The extends: model fixed duplication within a project: nobody re-declares the eight. But look across projects and the same shape reappears — and this time the skill's own rules are what's being broken.

What's actually happening today

Across our projects, the same sentences keep getting written into different repos:

  • "Secrets live in $HOME/projects/secrets/{service}.env" → every security.md
  • "Never docker run; deploy via the pipeline" → every operations.md
  • "Services are lowercase-with-hyphens, databases snake_case" → every conventions.md
  • The Tier-1 MCP pattern → every architecture.md that touches MCP

Why that's a structural bug, not sloppiness

The skill says: no duplicate information, and each entry belongs in exactly one file. Both are being violated — but not by carelessness. They're violated because there is nowhere else to put a fact that's true for every project at once.

A rule with no compliant destination isn't a rule people are ignoring. It's a missing tier.

Today these facts have two homes, and neither is right. ~/.claude/CLAUDE.md holds them as directives — but "secrets live at path X" is knowledge, not an instruction. The troubleshooting skill holds cross-project gotchas — but it's explicitly for hard-won traps, not for platform architecture. Neither is a knowledge tier, so the facts get copied into projects instead.

topic · program tier (1/3) · PROPOSED
← hub
Proposed · not built · no code exists

A program tier projects inherit from — the way they inherit the eight.

One new level, the same inheritance mechanic that already works. A program is a set of projects sharing a platform: ours is everything on linuxserver.lan.

   skill default  ─────────────────────  the canonical 8            [SHIPPED]
        │                                 baked into context-save
        │                                 nobody declares it
        ▼ inherited by
   program/docs/context/  ──────────────  platform-wide knowledge   [PROPOSED]
        │                                 invariants · security
        │                                 operations · architecture
        │                                 read-only from a project session
        ▼ inherited by
   project/docs/context/  ──────────────  what ships today          [SHIPPED]
                                          default 8 ∪ extends ∪ auto-discovered
                                          project wins on conflict (more specific)

   ── frontmatter ──────────────────────────────────────────────────────────
   context-save:
     program: ai-servicers-platform    # NEW — the only added key
     extends: [signal-lifecycle]       # unchanged
      

Three rules make it safe rather than just clever:

  • The program tier is read-only from a project session. A project may read it; it may not silently write it. Otherwise one project's local truth becomes platform law by accident — which is the worst outcome available here.
  • Promotion is explicit. Hoisting a fact upward is a deliberate act with a human in it, mirroring how agent-memory already promotes durable memories. Never automatic.
  • Only hoist what's true for every member. The test is "would this be false for any project in the program?" If yes, it stays local. Inherited entries render with a [PROGRAM] marker so a reader always knows what isn't theirs.

Opt-in by construction: a project with no program: key sees zero behaviour change — the same opt-out pattern the criticality.yml integration already uses.

topic · program tier (2/3) · PROPOSED
← hub
Proposed · not built · no code exists

What it would take, in order — starting with proving it's needed.

Step one is not code. It's evidence, because this proposal has a real argument against it and that argument deserves to win if the data says so.

1

Audit

Grep every project's docs/context/ for statements that repeat. Count them. If duplication is rare, stop here — the tier isn't earned.

2

Start narrow

Two files only — invariants.md and security.md, the two with the most repetition and the least project-specific nuance.

3

Resolve

Teach the skill the program: key. Inject inherited entries with the [PROGRAM] marker. Project still wins on conflict.

4

Prune

Delete the hoisted lines from the member projects. This is where the benefit actually lands — one fact, one home, at last.

5

Promote

Add the explicit hoist path so future platform-wide facts have a legitimate route up instead of being copied sideways.

The honest argument against

Our own standing guidance says skills should be minimalist guidelines, not prescriptive structure — and this adds a tier, a resolution order, and a new failure mode. It also concentrates blast radius: a wrong fact in the program tier is wrong in every member project simultaneously, where today it would be wrong in one. That trade is only worth making if step 1 shows the duplication is real and growing. If the audit comes back thin, the correct outcome is to not build this.

Home for the tier, if built: claude-shared/docs/program-context/<program>/ — it's already the versioned repo symlinked into ~/.claude/, so it inherits git history and the existing distribution path rather than inventing one.

topic · program tier (3/3) · PROPOSED
← hub

Most days you do nothing. Here's the rest.

0

Things you have to do on a normal day

The hooks fire on their own. The agent writes on its own. If you never think about this system, it is working correctly.

When you do have a job

  • Starting a new project — /context-save init scaffolds docs/context/ with the correct eight from templates.
  • After a big session — /context-save forces a full pass: reads everything, updates stale entries, prunes dead ones.
  • The agent gets blocked — that's the high-pressure tier. Let it save; don't fight it. It'll finish in one turn.
  • A test-gap scan reports holes — answer yes to /qatests, or decline knowingly.
  • Inheriting an older project — /context-save-upgrade, once, to make an implicit file set explicit.
  • Your project needs a ninth file — add it to extends:. Don't touch the eight.

Where to put a thing you just learned

  • Clarified what the system must do → requirements.md
  • Changed how components connect → architecture.md
  • Changed an API, schema, or event → interfaces.md
  • Changed patterns, libs, naming → conventions.md
  • Found a security constraint → security.md
  • Changed deploy, build, or run → operations.md
  • Changed test strategy or found a gap → testing.md
  • Found a rule that must always hold → invariants.md
  • Hit non-obvious behaviour → agent-memory, or gotchas.md
topic · operator cheat-sheet
← hub

Three honest risks.

Tracked, not "managed" — each one is live today and none is fully closed.

  • 1
    The files can lie, and a lie is worse than a gap. Nothing verifies a context file against the code. A stale [IMPLEMENTED] claim doesn't fail loudly — the next session simply believes it and builds on it. A missing file makes an agent go look; a wrong file makes it confident.
    Mitigation: context rides in the same commit as the code, so a reviewer sees claim and change together. Partial — it catches drift at write time, not decay over months.
  • 2
    Blocking trains avoidance. Refusing to let a session end is a strong lever, and strong levers get routed around — a second /exit, a killed terminal, a habit of never triggering the tier at all. Every block spends trust.
    Mitigation: blocking fires only at high pressure and >15 diff lines and untouched context. Four of the five tiers can't block at all. Unvalidated: nobody has measured whether the block rate is actually low in practice.
  • 3
    The 75% reconstruction goal has never been tested. It's the design target the whole system is justified by, and no one has deleted a codebase and tried to rebuild it from the notes. The number is an intent, not a result.
    Mitigation: none currently. The honest fix is a real drill on one small project — cheap to run, and it would either validate the bar or tell us the files are thinner than we think.

A fourth arrives only if the program tier is built: it concentrates blast radius, turning a one-project error into an every-project error. That risk is discussed on its own slides and is the main reason the proposal starts with an audit rather than an implementation.

topic · risks
← hub

The extends model merged today. The program tier is a proposal.

PieceStateDetail
The canonical eightShippedEight files, eight questions. invariants.md was the last to get a template — it landed today.
Hooks + escalation tiersRunningFive trigger points. Blocking active at the high-pressure tier.
Default ∪ extends modelMerged todayMR !2 → c11ee82 on main. Projects stop re-declaring the eight; extends: is the customization point.
Gotchas → agent-memoryShippedRoutes sideways where agent-memory is wired; plain gotchas.md otherwise.
Test-gap scan → /qatestsShippedFinal step of every workflow. Targets the session's gaps, not a full audit.
Program tierProposedNo code. No frontmatter key. Blocked on the duplication audit — which may kill it, correctly.
Reconstruction drillNot doneThe 75% target remains unmeasured. See Risks.

One operational note that isn't about the skill: claude-shared currently has no CI pipeline and no required reviewer on main. MR !2 merged with neither. Fine for a docs-shaped change; a gap worth closing separately before this repo carries anything executable.

topic · status

Code is what we built.
Context is why.

Git has always kept the first one safe. context-save is how the second one stops evaporating every time a session ends — eight files, one fact each, written at the boundary, committed next to the code they explain.

questions welcome · context-save · 2026-07-16