Learn
[Utilities] Use when teaching Claude a lesson that persists across sessions, including an extra r…
by duc01226 · MIT
The skill
[Utilities] Use when teaching Claude a lesson that persists across sessions, including an extra rule for one skill or task kind (routes to project-skill-protocol).
Quick Summary
Goal: Teach Claude lessons that persist across sessions by generalizing each lesson to its failure mode and routing it to the carrier a future session will actually read — the matching skill's project protocol when the lesson is skill-specific, otherwise the best-fit prose reference doc, docs/project-config.json when the lesson is really a machine-readable project fact, or the root CLAUDE.md project-rules section when it is a short, broad, project-specific rule or context note every task benefits from.
Summary: read-this-if-nothing-else digest of the main steps —
- Concise learned guidance — state intent, purpose, and the quality gate directly; retain enough context and owner pointers for AI discovery. Apply the Learned Guidance Quality Gate before saving.
- Generalize before anything else — climb from the incident to the reusable failure mode; a lesson naming this ticket's files/services/tools is not a lesson yet.
- Triage (value + recurrence + auto-fix) BEFORE routing — persist only a project convention or a universal best-practice protocol worth reading on everyday work; a rare AI-agent quirk, a one-off incident or a detail of the current task is noise, and so is a lesson a review skill already catches.
- Skill-specific lessons use the project protocol route: when the lesson is an extra rule for a skill — learned during an active skill invocation, during a task whose route matched a skill, naming a skill, or about the kind of task one skill mainly owns (e.g. "when writing integration tests…" →
integration-test) — treat it as a candidate overlay for that skill, compare it against the project-reference docs (docs/project-referenceby default) anddocs/project-config.jsonbefore recommending, ask the Carrier Choice question, and on an overlay pick call/project-skill-protocolwithaddfor a new overlay orupdate <exact-name>only after exact-name resolution; save to a reference doc or config field only when the user picks that carrier. - Root-context route (CLAUDE.md): a lesson that is a general project rule/convention or project context info (architecture constraint, naming rule, domain term, tool quirk of THIS project) is a candidate for the hand-owned
## Project Rules & Contextsection of the rootCLAUDE.md— only when ALL of: applies to most tasks, ≤ 3 lines, project-specific (a universal framework rule is never a project note), not better served by a reference doc / overlay / config field, and size headroom exists (root ≤ 32768 bytes). Show the exact line + target section and get the user's confirmation, write only that section, then runsync-codexsoAGENTS.mdand the mirrors follow. Otherwise keep today's routing. Full gate: Project Root Context Route. - Ask which carrier, with a recommendation: present the carrier options via
ask user question tool— recommended option first, labelled(Recommended)— before any write; never pick the carrier silently. - Keep ordinary routing for ordinary lessons: when the lesson is not skill-specific or no active/matching skill exists, use the existing FACT/RULE carrier route and confirmation flow.
- Classify the carrier, don't default to prose: a lesson stating a project FACT (path, run-command, module map, convention, tooling choice) belongs in
docs/project-config.json, the machine-readable map every skill reads first; a lesson stating a RULE or pattern belongs in the matchingdocs/project-reference/doc. Both can apply — write the fact to config AND the rule to prose. To learn what the config holds and its exact field names, read the file or use/project-config(it runs--describe). - Delegate overlay correctness:
/project-skill-protocolretains its mode resolution, target/scope resolution, additive-only constraint, collision/contradiction handling, proposal/user-confirmation gate and two-write contract; Learn must not bypass or replace it. - Assess prevention depth — doc/config update, prompt rule, static protocol lesson, hook, test, or skill update.
- Confirm target with the user, save, then run the 3 mandatory end tasks — Learn Review →
/why-review→ carrier-specific final quality pass (Markdown enhancement, or configuration parser/schema validation).
Workflow:
- Capture -- Identify the lesson from user instruction or experience
- Route -- Analyze lesson content against any active/matching skill, the Reference Doc Catalog, AND
docs/project-config.json; select the project-protocol route for skill-specific lessons, otherwise the best target carrier (prose doc, config field, or both) - Save -- After the applicable confirmation gates, delegate a skill-specific lesson the user placed in an overlay to
/project-skill-protocol; otherwise append the lesson to the selected file (a CLAUDE.md pick writes only the hand-owned## Project Rules & Contextsection, andsync-codexruns after the end tasks) - Confirm -- Acknowledge what was saved and where
- Learn Review -- Run the mandatory 2-step end gate (
Learn Review+/why-review)
Key Rules:
- GENERALIZE FIRST (the #1 protocol): Extract the GENERIC lesson that applies to many cases — NEVER save the specific case as-is. The user's words describe one incident; your job is to climb from that incident to the reusable rule. Strip every project/file/tool/domain name. If the saved text only helps on this exact ticket, you failed — abstract it up a level. (Enforced by the Lesson Quality Gate below.)
- Triggers on "remember this", "always do X", "never do Y"
- Triage first: pass the Value gate (project convention or universal best-practice protocol, worth reading on everyday work) + Recurrence gate + Auto-fix gate BEFORE routing or saving
- Smart-route to the most relevant file, NOT always
lessons.mdin the reference-docs root (defaultdocs/project-reference; adocsRoots.projectReference.pathentry indocs/project-config.jsonoverrides the path) - Consider
docs/project-config.jsonon EVERY routing decision — a lesson that is really a project fact (path, run-command, module map, tooling choice) belongs in the machine-readable map, not in prose; read it or use/project-configto know its schema before deciding - Use exact config schema field names (
node .claude/hooks/lib/project-config-schema.cjs --describe) and prefer an existing field — NEVER invent a key, and route config writes through/project-config - Check for existing entries before creating duplicates
- Confirm target file with user before writing
- Skill-specific route: When any trigger of the Skill-Specific Project-Protocol Route holds (active skill, matched route, named skill, or a task kind one skill owns), treat the lesson as a candidate extension of that skill's project protocol and compare carriers before asking. On an overlay pick, call
/project-skill-protocol add ...for a new overlay, or/project-skill-protocol update <exact-name> ...only after exact-name resolution identifies an existing overlay. Save it only to a reference doc,lessons.mdor a config field when the user picks that carrier. - Protocol authority: Preserve
/project-skill-protocol's mode resolution, target/scope resolution, additive-only constraint, target-collision and contradiction handling, proposal/user-confirmation gate, three-write contract, and mirror-sync rule. Learn must not bypass or replace any of them. - Confirmation remains required: Keep Learn's existing user confirmation and mandatory end-task flow; delegating a skill-specific candidate does not waive the project protocol's own proposal/user-confirmation gate.
- Ordinary-route fallback: When no active/matching skill exists or the lesson is not skill-specific, keep the existing FACT/RULE classification, carrier routing, confirmation, save, and end-task flow.
- CLAUDE.md is a destination, not a default: offer it only when every Root-Context condition holds (broad + ≤ 3 lines + project-specific + no better carrier + headroom); a detailed, lookup-style or niche lesson stays in its reference doc, a one-skill rule in an overlay, a machine-readable fact in config, a universal framework rule in a shared protocol. — why: CLAUDE.md is loaded into every session, so each byte costs every task.
- CLAUDE.md consent + sync: NEVER silently self-edit an instruction file — show the exact proposed line and target section, ask via
ask user question tool, write only after confirmation, then runsync-codex(after the end tasks) and report which mirrors changed.
Be skeptical. Apply critical thinking, sequential thinking. Every claim needs traced proof, confidence percentages (Idea should be more than 80%).
Contents
- Quick Summary
- Usage
- Reference Doc Catalog (READ before routing)
- Smart File Routing (CRITICAL)
- Budget Enforcement (MANDATORY for
lessons.md) - Behavior
- Auto-Inferred Activation
- How Lessons Reach the AI
- Prompt Enhancement (MANDATORY final step)
- Closing Reminders
Usage
Add a lesson
/learn always use the validation framework fluent API instead of throwing ValidationException
/learn never call external APIs in command handlers - use Entity Event Handlers
/learn prefer async/await over .then() chains
Add a skill-specific lesson (routes to a /project-skill-protocol overlay)
/learn when reviewing changes, always check that migration scripts are idempotent
/learn /plan should always include a rollback step
Add a project-wide rule or context note (routes to the root CLAUDE.md when it qualifies)
/learn in this repo every new module needs an entry in the module registry before any other change
/learn the term "tenant" always means the billing account here, never a user group
List lessons
/learn list
Remove a lesson
/learn remove 3
Clear all lessons
/learn clear
Reference Doc Catalog (READ before routing)
Reference docs live in the reference-docs root (default docs/project-reference; a docsRoots.projectReference.path entry in docs/project-config.json overrides the path). The session-init-docs.cjs hook initializes missing selected references and always-on routing inputs as placeholders; their declared /scan --target=<key> owners populate them, while manual guides remain owner-maintained. This catalog lists supported carriers, not mandatory files.
Routing is static: read the doc whose Read Trigger matches your task. Before recommending a target, read the configured Doc Lookup and docs index, preserve an existing authoritative project guide, and compare viable alternatives, explaining any new file or selection needed. Keep one owner per rule and link executable budgets and harness details instead of duplicating them.
| File | Role & Content | Read Trigger (static) | Scan Skill |
|---|---|---|---|
project-structure-reference.md |
Architecture, directory tree, tech stack, module registry, service map | New area / architecture work | /scan --target=project-structure |
backend-patterns-reference.md |
Backend/hook patterns: CJS modules, CQRS, repositories, validation, message bus, background jobs | Editing backend / CQRS / API files | /scan --target=backend-patterns |
seed-test-data-reference.md |
Seed/dev-data patterns: environment gate, idempotency loop, DI scope safety, command-dispatch | Seeder / DataSeeder file edits | /scan --target=seed-test-data |
frontend-patterns-reference.md |
Frontend patterns: components, state mgmt, API services, styling conventions, directives | Editing frontend / UI files | /scan --target=frontend-patterns |
integration-test-reference.md |
Test architecture: base classes, fixtures, helpers, service-specific setup, test runners | Integration test file edits | /scan --target=integration-tests |
performance-test-reference.md |
Project performance-test preferences: reusable harness, workload/data/resource budgets, commands, evidence and quality gates | Planning, writing, reviewing, running or fixing performance/load/soak/capacity tests | /scan --target=performance-tests |
feature-spec-reference.md |
Feature doc templates, app-to-service mapping, doc structure conventions | Authoring / reading feature specs | /scan --target=feature-spec |
code-review-rules.md |
Review rules, conventions, anti-patterns, decision trees, checklists | Any review skill activation | /scan --target=code-review-rules |
lessons.md |
General lessons — fallback catch-all. Read on EVERY task (per project-reference-docs gate) | Every task | Managed by /learn |
| Configured styling reference | CSS/preprocessor conventions, naming, tokens, theming, responsive behavior | Styling edits | Follow the configured scan owner; generic custom docs use scan --target=generic-reference-doc --filename=<configured-file>; manual docs remain owner-maintained |
design-system/README.md |
Design system: tokens overview, component inventory, app-to-doc mapping | Design / UI file edits | /scan --target=design-system |
e2e-test-reference.md |
E2E test patterns: framework, page objects, config, best practices | E2E file edits | /scan --target=e2e-tests |
domain-entities-reference.md |
Domain entities, data models, DTOs, aggregate boundaries, ER diagrams, cross-service sync | Backend / frontend domain work | /scan --target=domain-entities |
docs-index-reference.md |
Documentation tree, file counts, doc relationships, keyword-to-doc lookup | Doc lookup / navigation | /scan --target=docs-index |
Key insight: lessons.md and code-review-rules.md are the highest-recurrence routing targets — read them on every relevant task. Place high-recurrence lessons where the matching Read Trigger guarantees a future session opens them.
Also a routing destination: docs/project-config.json (machine-readable, NOT prose)
The catalog above is prose. docs/project-config.json is the project's machine-readable map — modules/paths, framework + search keywords, test/E2E/integration run-commands, design system, architecture rules, workflow patterns — and it is what CLAUDE.md and the docs/project-reference/** docs are generated from. Every skill is told to read it BEFORE investigating, planning, or coding, so a fact recorded there reaches more sessions than the same fact written into one prose doc.
Read Trigger: every task, ahead of the prose docs. Owned by: /project-config.
Learn its shape before routing anything into it — either read docs/project-config.json directly, or invoke /project-config, which knows the schema and its exact field names:
node .claude/hooks/lib/project-config-schema.cjs --describe # exact field names + per-field derivation notes
| Lesson really is… | Carrier |
|---|---|
| A project FACT a schema field already models — a path, glob, run-command, module/service map, framework or tooling choice, doc root, test/E2E/integration setup, startup or health-check command | docs/project-config.json (via /project-config) |
| A RULE, pattern, or anti-pattern an agent must reason with | the matching doc in the reference-docs root (default docs/project-reference; a docsRoots.projectReference.path entry in docs/project-config.json overrides the path) |
| Both — a new fact AND the rule for using it | write the fact to config AND the rule to prose |
Rules:
- MUST check
docs/project-config.jsonas a candidate on EVERY routing decision — why: a project fact written only as prose is invisible to the tooling that reads the config, and is silently overwritten the next time the generated docs regenerate from it. - MUST use exact schema field names (
--describe, copy verbatim) and prefer an EXISTING field over a new one — why: unknown keys are accepted as warnings (project-config-schema.cjsunknown-key warnings), so an invented key looks like it worked while no consumer ever reads it. - No existing field fits → do NOT invent a top-level key silently. Route the lesson to prose and surface the gap to the user as a proposed schema addition — why: a schema change is a framework decision, not a side effect of
/learn. - Prefer routing the config write through
/project-config(Plan → Review → Execute + validation) over hand-editing the JSON — why: it validates after each phase and knows the field names this skill would otherwise guess. - Config carries FACTS, never prose lessons — NEVER paste a narrative lesson into a config string field. — why: the config is consumed by tooling and by every skill's prefetch; prose there bloats every session and belongs in a reference doc.
Smart File Routing (CRITICAL)
Lesson Triage Gate (MANDATORY — run FIRST, before routing or saving)
| Gate | Question | Pass | Fail → Action |
|---|---|---|---|
| Value | "Is this a project convention (a stable rule this codebase follows in everyday work) or a universal best-practice protocol — worth an agent reading on an ordinary day?" | Yes → continue | No → skip /learn; rare AI-agent quirks, one-off incidents, tool/environment hiccups and details of the current session's task are not lessons |
| Recurrence | "Would this mistake recur in a future session WITHOUT this reminder?" | Yes → continue | No → skip /learn; mistake is situational |
| Auto-fix | "Could /code-quality-review, /simplify, /security-audit, or a linter catch this automatically?" |
No → continue | Yes → skip /learn; update the review skill instead |
All three gates must pass. Persistent memory is read on every task, so it holds only what makes everyday work better: a project convention or a universal best practice. A rare agent quirk or a detail of this session's task costs every future reader attention and prevents nothing; a lesson review skills already catch adds noise; a one-off situational mistake won't be prevented by a persisted rule.
Skill-Specific Project-Protocol Route (BLOCKING)
A project overlay (owned by /project-skill-protocol) is the carrier that fires exactly when the skill runs — a skill-specific rule saved to lessons.md or a prose doc reaches the skill only by chance. Before applying the generic Routing Table, detect whether ANY trigger holds:
| # | Trigger | Example |
|---|---|---|
| T1 | The user asks to learn something during an active skill invocation | mid-/changes-review: "remember to also check X" |
| T2 | The lesson is learned while performing a task whose route matched a skill | a custom-simple [… → changes-review] route surfaces a review gap |
| T3 | The lesson names a skill, or adds a rule/step/check to what a skill does | "/plan should always list rollback steps" |
| T4 | The lesson is about a kind of task one skill mainly owns, even without naming it | "when writing integration tests, always seed via commands" → integration-test |
Resolve the owning skill (T3/T4): match the lesson's task kind against skill Use when … descriptions in the skills catalog; cite the matching description. One clear owner → exact target. A family sharing a name pattern (e.g. every *-review skill) → glob target. Two or more owners that share no name pattern → one exact overlay per owner, listed together in the Carrier Choice question. No owner, or the rule applies across unrelated tasks → the lesson is NOT skill-specific; use the generic Routing Table. — why: a guessed owner puts the rule where it never fires.
When any trigger holds:
-
Identify the target skill (or glob family) by its exact name, with the evidence that matched it.
-
Treat the lesson as a candidate extension of that skill's project protocol.
-
Compare carriers before recommending (BLOCKING). The overlay is a candidate, not the default. Check it against the same carriers the generic route uses: the Reference Doc Catalog and Routing Table (resolved under the reference-docs root, default
docs/project-reference), anddocs/project-config.json(FACT vs RULE). Recommend the reference doc when its Read Trigger already fires for this kind of task and the rule is not about the skill's own steps (a T4 lesson about integration tests usually belongs inintegration-test-reference.md); recommend the overlay when the rule changes what the skill itself does. — why: a project-reference doc is read by every agent doing that kind of work, while an overlay reaches only runs of that one skill. -
Carrier Choice question (BLOCKING).
ask user question toolwith the recommended option FIRST, labelled(Recommended), each option naming its concrete target path:- Skill overlay for
<skill>via/project-skill-protocol— anexactoverlay applies on every run of that skill; agloboverlay applies unless anexactoverlay for the same skill exists, because the most specific tier wins - Overlay + reference doc — only when the lesson also carries a project-wide rule beyond the skill; name the doc path
- Reference doc only — name the path, e.g.
integration-test-reference.mdorlessons.mdunder the reference-docs root - Project config field — when the lesson is a machine-readable FACT (see FACT vs RULE)
- Root
CLAUDE.mdproject note +sync-codex— only when the lesson also passes the Project Root Context Route candidate test (C1–C5) despite being skill-related; each question holds 2–4 options, so drop the weakest
State a one-line reason for the recommendation. When the Prevention Depth Assessment applies, ask it as a SECOND question in the same
ask user question toolcall (each question holds 2–4 options), so the user answers once. — why: the user owns where a persistent rule lives; a silent carrier choice is the main way lessons land where no future run reads them. - Skill overlay for
-
MUST ATTENTION On an overlay choice, call
/project-skill-protocol add ...for a new overlay or/project-skill-protocol update <exact-name> ...only after exact-name resolution identifies an existing overlay (run itslistfirst when unsure). -
MUST ATTENTION Let
/project-skill-protocolperform its own mode resolution, target/scope resolution, additive-only screen, target-collision and contradiction handling, proposal/user-confirmation gate and two-write contract. Do not write overlay bodies or index rows directly from Learn. -
On a Reference doc only or Project config field pick, continue with Routing Decision Process steps 9–10 (append to the doc, or route the config value through
/project-config). On Overlay + reference doc, do both. Do not save the candidate only tolessons.mdor another generic prose carrier unless the user picked that option.
If no trigger holds, continue with the generic Routing Table — the carrier confirmation there still offers the options with a recommendation.
Project Root Context Route (CLAUDE.md) (BLOCKING)
The root CLAUDE.md is loaded into EVERY session automatically, so a line there reaches every task with no read step — and costs tokens in every session. It is the right carrier for a short, broad, project-specific rule or context note, and the wrong one for anything detailed. Evaluate this route for every lesson that passed the Triage Gate, alongside the FACT-vs-RULE classification and (when a T1–T4 trigger holds) the skill-specific route.
Candidate test — ALL five must hold, otherwise use today's routing:
| # | Condition | Fails when → fall back to |
|---|---|---|
| C1 | Broad — applies to most tasks in this project, not one file type, phase or skill | one area → its reference doc; one skill → overlay |
| C2 | Short — states as ≤ 3 lines / ≤ ~300 characters, one rule or fact per entry | detailed, example-heavy or lookup-style → a project reference doc |
| C3 | Project-specific — a convention, architecture constraint, naming rule, domain term, or tool quirk of THIS project | universal framework rule → the Static Protocol Lesson route (shared protocols, framework maintainers) — never a CLAUDE.md note |
| C4 | No better carrier — no reference doc whose Read Trigger already fires for this work, no skill overlay, no docs/project-config.json field (a FACT such as a path or run-command is config data; the generator renders it into CLAUDE.md) |
that carrier |
| C5 | Headroom — CLAUDE.md exists and stays ≤ 32768 bytes after the edit (the generator's ROOT_OVERFLOW threshold in generate-claude-md.cjs), and the ## Project Rules & Context section stays ≤ ~2 KiB / ≤ ~12 entries |
a project reference doc (or condense the section first — never add beyond budget) |
Which destination fits:
| The lesson is… | Destination | Why |
|---|---|---|
| Broad + short + project-specific rule, convention or context with no schema field | root CLAUDE.md → ## Project Rules & Context, then sync-codex |
always in context, AGENTS.md follows |
| Machine-readable project fact the config models (path, run-command, module map, tooling) | docs/project-config.json via /project-config |
every skill reads it first; generators render it into the root |
| Detailed, niche or lookup-style rule, pattern, anti-pattern or checklist for one kind of work | matching project reference doc (Read Trigger) | read only when that work starts |
| Rule bound to one skill's own steps | skill overlay via /project-skill-protocol |
fires exactly when that skill runs |
| General catch-all lesson that is not broad or short enough for the root | lessons.md |
dated catch-all, budgeted |
| Universal framework rule (any project, silent failure, high recurrence) | NOT a project note — Static Protocol Lesson promotion to the shared protocols, reviewed by framework maintainers | project notes must not carry framework rules |
Durable home (write ONLY here): a hand-owned ## Project Rules & Context section placed outside every <!-- SECTION:key --> fence and every CK:* managed block. ai-context-refresh --mode update rewrites only fence bodies and keeps everything outside them verbatim (updateMarkedSections in generate-claude-md.cjs), and the Codex projection is a heading whitelist (AGENTS_PROJECTION_HEADINGS in sync-context-workflows.mjs) that includes this heading. A note inside a fence is overwritten by the next regeneration; a note under a heading the whitelist omits never reaches AGENTS.md. If the section is absent, create it (heading + bullets) immediately after the ## Doc Lookup — What to Read When section, so it projects early into AGENTS.md and reads before the generated rules. No CLAUDE.md yet → not a candidate: run /ai-context-refresh first or route elsewhere. A path-scoped rule that the project already renders from contextGroups[].rules belongs in config via /project-config (regenerated by ai-context-refresh --mode update), not in this section.
Procedure when C1–C5 hold:
Read .claude/skills/shared/protocols/context-engineering-principles.md when drafting a root-context entry; apply its Instruction-file audit before the existing confirmation/write gates. This does not waive C1–C5 or consent.
- Measure — read
CLAUDE.mdbyte size (node -e "console.log(require('fs').statSync('CLAUDE.md').size)", platform-neutral) and the section's current size; C5 fails → say so and fall back. - Draft — one generic bullet, ≤ 3 lines, no incident nouns (Lesson Quality Gate; the project-convention exception keeps the convention's own terms). Check the section for an existing entry on the same rule — update it instead of adding a duplicate.
- Confirm (BLOCKING) —
ask user question toolwith the recommended option first, labelled(Recommended). Show the exact proposed line, the target section, andsize before → after / 32768. Options: Root CLAUDE.md project note (+ sync-codex) · Reference doc (name the path) · lessons.md · Skill overlay / config field when one applies (2–4 options; drop the weakest). A rejected or unanswered question writes nothing. - Write — Edit only the hand-owned section; never touch a fence, a
CK:*block, or generated text. - Sync (after the final CLAUDE.md edit) — when
AGENTS.mdor.codex/exists, runnode .claude/skills/sync-codex/scripts/run-codex-sync.mjs --skip=claude-md(the same root-source handoffai-context-refreshuses; Windows/macOS/Linux neutral). If the runner fails, keep the task open, report the failing stage and the recovery command, and do not claim the mirrors are current. No Codex mirrors in the project → record "no mirrors" and skip. - Verify, read-only — (a) re-measure
CLAUDE.mdbytes ≤ 32768; (b) the new line lies outside every<!-- SECTION:… -->fence (fence open/close lines above it balance), which is what guaranteesupdatepreserves it; (c) the line appears inAGENTS.md; (d)git status --short AGENTS.md .codex .agents .opencodelists the mirrors that changed — report them, never stage or commit.
Routing Table
Route to the most relevant file based on lesson content. Every bare *.md filename in the Route to column resolves inside the reference-docs root (default docs/project-reference; a docsRoots.projectReference.path entry in docs/project-config.json overrides the path):
| If lesson is about... | Route to | Section hint |
|---|---|---|
| Code review rules, anti-patterns, review checklists, YAGNI/KISS/DRY, naming conventions, review process | code-review-rules.md |
Add to most relevant section (anti-patterns, rules, checklists) |
| Backend/hook patterns: modules, CQRS, repositories, entities, validation, message bus, background jobs, migrations, configured persistence | backend-patterns-reference.md |
Add to relevant section or Anti-Patterns section |
| Frontend patterns: components, state stores, forms, API services, styling conventions, directives, pipes | frontend-patterns-reference.md |
Add to relevant section or Anti-Patterns section |
| Integration/unit tests: test base classes, fixtures, test helpers, test patterns, assertions, test runners | integration-test-reference.md |
Add to relevant section |
| Performance/load/stress/soak/capacity tests: harness reuse, workload/data, resource and SLO budgets, telemetry, evidence and quality gates | performance-test-reference.md |
Preserve project preferences; link executable owners and existing harness guides |
| E2E tests: Playwright, Cypress, Selenium, page objects, E2E config, browser automation, visual regression | e2e-test-reference.md |
Add to relevant section |
| Domain entities, data models, DTOs, aggregates, entity relationships, cross-service data sync, ER diagrams | domain-entities-reference.md |
Add to Entity Catalog or Relationships section |
| Project structure, directory organization, module boundaries, tech stack choices, service architecture | project-structure-reference.md |
Add to relevant architecture section |
| Styling conventions selected by project config, including CSS/preprocessor rules, tokens, theming, and responsive design | Configured styling reference | Add to the relevant styling section or route it to the document owner |
| Design system, design tokens, component library, UI kit conventions, Figma-to-code patterns | design-system/README.md |
Add to relevant design section |
| Feature documentation, doc templates, doc structure conventions, app-to-service doc mapping | feature-spec-reference.md |
Add to relevant conventions section |
| Documentation indexing, doc organization, doc-to-code relationships, doc lookup patterns | docs-index-reference.md |
Add to relevant section |
| Project FACTS the config models: source/module paths, globs, service or app maps, framework + search keywords, test / E2E / integration run-commands, system startup or health-check commands, doc roots, design-system or styling locations, tooling choices | docs/project-config.json via /project-config |
Existing schema field, exact name from --describe — NEVER an invented key |
| Broad + short (≤ 3 lines) project rule, convention or context that passes all five conditions of the Project Root Context Route | root CLAUDE.md ## Project Rules & Context, then sync-codex |
Bullet in the hand-owned section; user confirmation first |
| General lessons, workflow tips, tooling, AI behavior, project conventions, anything not matching above | lessons.md |
Append as dated list entry |
Prevention Depth Assessment (MANDATORY before saving)
Before saving any lesson, critically evaluate whether a doc update alone is sufficient or a deeper prevention mechanism is needed:
| Prevention Layer | When to use | Example |
|---|---|---|
| Doc update only | Team convention or rule needed only when doing that kind of work (the lesson already passed the Value gate) | "Always use fluent validation API" → backend-patterns-reference.md |
Project config field (docs/project-config.json) |
The lesson is a machine-readable project FACT every skill should ground on before acting | "Integration tests need the system started first" → integrationTestVerify.startupScript / systemCheckCommand via /project-config |
Root project note (CLAUDE.md ## Project Rules & Context) |
A short, broad, project-specific rule or context note every task benefits from (Root Context Route C1–C5) | "Every new module is registered in the module registry first" → root CLAUDE.md + sync-codex |
Prompt rule (development-rules.md) |
Rule that ALL agents must follow on every task | "Grep after bulk edits" → .claude/docs/development-rules.md |
Static protocol lesson (sync-inline-versions.md) |
Universal AI mistake, high recurrence, silent failure, any project | "Trace every consumer before and after a change" → .claude/skills/shared/sync-inline-versions.md |
Hook (.claude/hooks/) |
Automated enforcement, must never be forgotten | "Marker strings must match across producer and consumer" → a shared constants module + consistency test |
Test (.claude/hooks/tests/) |
Regression prevention, verifiable invariant | "All hooks import from shared module" → test in test-all-hooks.cjs |
Skill update (.claude/skills/) |
Workflow step that should always include this check | "Review changes must check doc staleness" → skill SKILL.md update |
Decision flow:
- Capture the lesson
- Ask: "Could this mistake recur if the AI forgets this lesson?" If yes → needs more than a doc update
- Ask: "Can this be caught automatically by a test or hook?" If yes → recommend hook/test
- Evaluate Static Protocol Lesson promotion (see below)
- Present options to user with
ask user question tool— recommended option first, labelled(Recommended), with a one-line reason; on the skill-specific route, ask them as the second question of the Carrier Choiceask user question toolcall instead of asking twice:- "Doc update only" — save to the best-fit reference file (default for most lessons)
- "Doc + prompt rule" — also add to
development-rules.mdso all agents see it - "Doc + Static Protocol Lesson" — also add to shared protocol lessons (see criteria below)
- "Full prevention" — plan a hook, test, or shared module to enforce it automatically
- Execute the chosen option. For "Full prevention", create a plan via
/planinstead of just saving.
Static Protocol Lesson Promotion (MANDATORY evaluation)
After generalizing a lesson, evaluate whether it qualifies as a Static Protocol Lesson in .claude/skills/shared/sync-inline-versions.md. Static protocol lessons live in that canonical file and reach every session through the universal hook (the universal group of protocol-groups.json); the root CLAUDE.md and AGENTS.md carry none of them.
Qualification criteria (ALL must be true):
- Universal — Applies to ANY AI coding project, not just this codebase
- High recurrence — AI agents make this mistake repeatedly across sessions without the reminder
- Silent failure — The mistake produces no error/warning; it silently degrades output quality
Use this skill
Connect your agent to the Skill Store MCP server and ask for it by ref: duc01226/learn-90178782399.
Details
- Publisher
- duc01226
- Category
- AI & Agents › Memory & context
- License
- MIT
- Updated
- 2026-10-18
References
More from duc01226
- Template Skill [Category] Use when defining the standard skill description pattern.
- Ai Context Refresh [Documentation] Use when generating, smart-merging or refactoring the root AI context (CLAUDE.md,…
- Ai Engineering Review [Code Quality] Use when a workflow step or the user asks for AI code or plan review: LLM calls, p…
- Architecture [Architecture] Use when a workflow step or the user asks for architecture design, compliance revi…