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.
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.
/clear by default*A design target, not a measured result — see Risks. The five endings: Stop, SubagentStop, PreCompact, SessionEnd, and an explicit /clear, /compact, /exit or /quit.
Three design principles, ranked:
[IMPLEMENTED], [PLANNED], or [DEPRECATED]. A file that lies is worse than no file at all — the next session believes it.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.
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.
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.
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.
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.
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.
All five run without you. The only place a human appears is the last one, and only if the test scan found something.
A context-loss boundary is reached. The hook estimates how much pressure the session is under from the size of the transcript.
What actually changed this session, and which of the context files does that touch?
For each learning: which single file answers it? Canonical first, then project extensions, then sideways to memory.
Terse bullets, status-marked, under a 200-line ceiling. When a file is full, something old gets pruned.
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.
/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.
Eight questions, one home per fact — and the writing rules that keep them worth reading.
→Inherit the eight, declare only what's yours. The whole configuration surface is four lines.
→Tool-context diagram: where the decision to nudge — or to block — actually gets made.
→The same duplication problem, one level up — and a tier projects would inherit from.
→Most days: nothing. The handful of moments you do have a job, and what it is.
→Three real ones. The worst is that these files can quietly lie to you.
→What merged today, what's running, and what's still only a proposal.
→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.
| File | The question it answers | What lives there |
|---|---|---|
| requirements.md | What must this do? | Business rules, user workflows, product constraints |
| architecture.md | How do the pieces connect? | Components, boundaries, data flow, service topology |
| interfaces.md | What are the contracts? | APIs, schemas, entities, events, config surfaces |
| conventions.md | How is the code written here? | Patterns, naming, frameworks, libraries, module layout |
| security.md | Who is allowed to do what? | Auth, secrets, trust boundaries, access rules |
| operations.md | How does it run? | Deployment, containers, networking, config, runtime |
| testing.md | What must not break? | Critical paths, regression checks, coverage strategy |
| invariants.md | What 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."
Every one of these exists because the failure it prevents is what kills documentation. Nobody abandons docs because they were too short.
[PLANNED].CLAUDE.md — directives and knowledge stay separate.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.
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.
CLAUDE.md listed all eight files by name.extends:..md into docs/context/ and it's auto-discovered — adoption costs nothing.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.
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.
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.
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 sees | Pressure | What 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.
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.
Across our projects, the same sentences keep getting written into different repos:
$HOME/projects/secrets/{service}.env" → every security.mddocker run; deploy via the pipeline" → every operations.mdlowercase-with-hyphens, databases snake_case" → every conventions.mdarchitecture.md that touches MCPThe 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.
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:
[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.
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.
Grep every project's docs/context/ for statements that repeat. Count them. If duplication is rare, stop here — the tier isn't earned.
Two files only — invariants.md and security.md, the two with the most repetition and the least project-specific nuance.
Teach the skill the program: key. Inject inherited entries with the [PROGRAM] marker. Project still wins on conflict.
Delete the hoisted lines from the member projects. This is where the benefit actually lands — one fact, one home, at last.
Add the explicit hoist path so future platform-wide facts have a legitimate route up instead of being copied sideways.
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.
The hooks fire on their own. The agent writes on its own. If you never think about this system, it is working correctly.
/context-save init scaffolds docs/context/ with the correct eight from templates./context-save forces a full pass: reads everything, updates stale entries, prunes dead ones./qatests, or decline knowingly./context-save-upgrade, once, to make an implicit file set explicit.extends:. Don't touch the eight.requirements.mdarchitecture.mdinterfaces.mdconventions.mdsecurity.mdoperations.mdtesting.mdinvariants.mdgotchas.mdTracked, not "managed" — each one is live today and none is fully closed.
[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./exit, a killed terminal, a habit of never triggering the tier at all. Every block spends trust.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.
| Piece | State | Detail |
|---|---|---|
| The canonical eight | Shipped | Eight files, eight questions. invariants.md was the last to get a template — it landed today. |
| Hooks + escalation tiers | Running | Five trigger points. Blocking active at the high-pressure tier. |
| Default ∪ extends model | Merged today | MR !2 → c11ee82 on main. Projects stop re-declaring the eight; extends: is the customization point. |
| Gotchas → agent-memory | Shipped | Routes sideways where agent-memory is wired; plain gotchas.md otherwise. |
Test-gap scan → /qatests | Shipped | Final step of every workflow. Targets the session's gaps, not a full audit. |
| Program tier | Proposed | No code. No frontmatter key. Blocked on the duplication audit — which may kill it, correctly. |
| Reconstruction drill | Not done | The 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.
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.