rulemolt

Learn from failures without an ever-growing rules file. Use when a test or command failed again, the user says "remember this" or "don't do that again", in a postmortem, and before starting work in an area that broke before. Fix the cause first; record, search and retire lessons.

Qu'est-ce que rulemolt ?

rulemolt is a Claude Code agent skill that learn from failures without an ever-growing rules file. Use when a test or command failed again, the user says "remember this" or "don't do that again", in a postmortem, and before starting work in an area that broke before. Fix the cause first; record, search and retire lessons.

Compatible avec✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ianlyoo/rulemolt/tree/HEAD

Installed? Explore more Productivité et collaboration skills: steipete/gemini, steipete/gh-issues, steipete/skill-creator · View all 6 →

Demander à votre IA préférée

Ouvre une nouvelle conversation avec cette compétence d'agent déjà préchargée.

Documentation

Que fait rulemolt ?

A coding agent that writes every mistake into a rules file ends up with a file nobody reads. This loop puts the knowledge where it works: a fix you can make now goes into code, tests and checks; a lesson holds only a cause you cannot fix yet, or knowledge no code can hold; lessons are looked up at the moment of work and retire when their fix lands.

Terms used below:

  • lesson: one dated entry: what happened, why, evidence, the files it concerns (areas), and a home or no-home.
  • home (--home LAYER:FILE): the layer and file where the lesson's fix will live, e.g. code:src/invoices/render.py.
  • no-home (--no-home REASON): the lesson is knowledge no code, test, config or check can hold.
  • fix commit: the commit that put the fix into the home. link attaches it to the lesson.
  • tidy: retires every lesson whose fix commit is in HEAD. retire takes a lesson out of search; unretire brings it back when its failure recurs. Nothing is deleted, and undo reverses any of these.

The store is scripts/lessons.py (Python 3.9+, standard library only). It keeps .lessons/lessons.jsonl and .lessons/actions.jsonl at the top of the current git repository. Run it from inside the repository (outside one it says so and uses ./.lessons; --store DIR picks another folder). Set the script path once and call it through python3, which works the same in bash and zsh:

L=~/.claude/skills/rulemolt/scripts/lessons.py   # or <project>/.claude/skills/rulemolt/scripts/lessons.py
python3 "$L" search --path src/app.py app

Keep python3 out of the variable: zsh does not split $L into words, so L="python3 …"; $L add fails there. If each command runs in a fresh shell, set L= on the same line or write the full path. Every command has --help, and takes --json before the command name for machine-readable output.

1. Before working in an area: search

Before you edit files in an area, or when a task names a component ("the CSV exporter", "date parsing"), run:

python3 "$L" search --path src/export/csv.py csv exporter

Pass each file you expect to touch with its own --path, plus a few words for the component. Read every hit, and say in your reply which lesson applies and what you will do because of it (or that none applies). Do this before the first edit, not after a test fails. If you did not search, say so; do not report a search you did not run.

Why: a lesson nobody retrieves at the moment of work is useless. Searching is the step agents skip, because nothing forces it; tying it to "before the first edit in an area" is what makes the store pay for itself.

2. When something fails or repeats: fix the cause now

When a test or command fails, or a mistake happens a second time, find the layer that let it happen and change that layer: the code, a test that would have caught it, a config value, a lint or CI check, or the instructions file (CLAUDE.md, AGENTS.md, a skill) when the mistake was a wrong instruction. Change the design that produced the failure instead of adding a guard, retry, sleep or special case at the spot where it showed.

The fix carries the knowledge: the code change, a regression test that fails without it, and a commit message that says why. If the reason is not obvious from the code, put it in the code: a one-line comment beside the fix, or a test name or docstring that states the case (test_average_of_empty_list_is_none).

Keep the rules files for wrong instructions only. When code, a test or a check already holds the fix, add nothing to CLAUDE.md, AGENTS.md or any rules file: a second copy of the fix as prose is the ever-growing file this skill exists to avoid.

Usually no lesson is needed after this step. Go to step 3 only if the cause cannot be fixed now, or if part of the knowledge cannot live in code at all.

Why: a guard at the symptom hides the next failure of the same cause, and a fix in the right layer works for every future agent and person without anyone having to remember it.

3. Record a lesson only for what step 2 could not hold

There are two cases:

(a) A cause you cannot fix now (out of scope, needs a decision, blocked on another change). Record it with the home its fix will live in and no fix commit. Until the fix lands, this is what the next agent finds by search before touching that area.

python3 "$L" add --what "invoice totals print with the server's locale; a German host rendered 1.234,50 for 1234.50" \
  --why "render.py formats with locale.format_string. Fix: format with the customer's locale; blocked on the billing team choosing where that setting lives" \
  --evidence "LC_ALL=de_DE.UTF-8 python3 -m invoices.render sample.json -> 'Total: 1.234,50'" \
  --area src/invoices/render.py --area "tests/test_render*.py" \
  --home code:src/invoices/render.py

When the fix lands, link its commit (step 4) and tidy retires the lesson (step 5).

If the fix will live outside this repository (a shared CI template, another service, a vendor setting), write that place as the home (--home ci:infra-templates/ci/python.yml). Tidy cannot see a commit there, so do not link one; once the outside fix is confirmed, retire ID --reason "fixed in infra-templates 3f2a9c1".

(b) Knowledge no code or check can hold: a manual step, an external system's behaviour, a person's process. Record it with --no-home and the reason. Tidy never retires these for lack of use.

python3 "$L" add --what "the payments sandbox resets every Sunday 00:00 UTC; test accounts vanish" \
  --why "the provider's schedule, not ours; recreate test accounts with scripts/seed_sandbox.sh on Mondays" \
  --evidence "provider status page; three failed Monday CI runs" \
  --area "tests/integration/payments/" --no-home "external system behaviour we cannot change"

Flags: exactly one of --home LAYER:FILE (code:, test:, config:, ci:, instructions: …) or --no-home REASON; --area repeated once per path or glob.

Skip the lesson for anything the fix in step 2 already holds: a bug now caught by its test, a missing import the linter now flags, a one-off environment hiccup. The test or check is the memory.

A good lesson and a bad one

Good (case a: specific, has evidence, names where the fix will live, fix not landed yet):

what: CSV export writes no header row when the result set is empty; a customer import failed on it. why: the writer emits the header lazily on the first row. Fix: write the header before iterating. Until then, callers that may export zero rows must not rely on a header. evidence: pytest tests/test_export.py::test_empty_has_header fails ('' != 'id,name\r\n'). areas: src/export/csv.py, tests/test_export.py · home: code:src/export/csv.py · fix_commit: none yet

Good (case b): what: release notes must be approved by the support lead before tagging · no-home: "a person's sign-off; no check can stand in for it".

Bad (a rule with no cause, no evidence, no place to check it):

what: Be careful with CSV files. why: They can break.

The bad one cannot be searched for usefully, cannot be checked, and can never be retired.

4. The fix landed: link the fix commit

When the fix for a lesson with a home is committed, name that commit:

python3 "$L" link L3 --fix-commit 3f2a9c1

Why: the commit is the proof that the knowledge moved out of the lesson store into the code. It is also what lets tidy retire the lesson automatically.

5. Tidy: retire what has landed

Run tidy after merging fixes, at the end of a session, or on a schedule:

python3 "$L" tidy --dry-run              # what would retire
python3 "$L" tidy --check "pytest -q"    # retire lessons whose fix commit is in HEAD, only if the check passes

A lesson retires when its fix commit is an ancestor of HEAD and, if a check is set (--check, or check in .lessons/config.json), the check exits 0. With no check, ancestry is the only gate, so look at each linked fix before you run tidy without one. A fix has landed when its commit changes the home and something would fail without it: its test or a check. A test that asserts nothing, or a value that no code reads, has not landed; reject it before tidy with unlink ID --reason "the test asserts nothing". The commit moves to failed_fixes and the lesson waits for a new link; no recurrence is counted. Tidy prints each retirement with its action id (A4: retired L3: ...) or nothing changed, plus lessons that wait for a link. No-home lessons are never retired for lack of use; retire one only by judgment (retire ID --reason TEXT).

Why: once the fix is in the code, the lesson is redundant; keeping it makes the live set grow until search returns noise.

6. Near-duplicates: group, then judge

python3 "$L" groups               # proposes groups by word and area overlap
python3 "$L" merge L2 L5 --what "..." --reason "same root cause"

The script only proposes groups. Merge after reading them: two lessons with similar words can have different causes.

7. Recurrence: unretire

If a failure that a retired lesson describes happens again, find it with search --all and bring it back:

python3 "$L" unretire L3 --reason "test_created_at failed again on 2026-03-02 after the date refactor"

The lesson becomes live, its old fix commit is recorded under failed_fixes, and tidy will not retire it again until you link a new fix commit. Then go back to step 2: the fix did not hold, so the layer you chose was wrong or incomplete.

Undo

link, unlink, merge, retire, unretire and tidy's retirements are each one action in .lessons/actions.jsonl holding the values they replaced, and each prints its action id. python3 "$L" show L3 lists a lesson's actions; python3 "$L" undo A7 puts one back (newer actions on the same lessons must be undone first).

Command summary

Usage lines as --help prints them:

WhenCommand
before the first edit in an areasearch [--path FILE] [--limit N] [--all] [WORD ...]
a cause you cannot fix now, or knowledge no code can holdadd --what TEXT --why TEXT --evidence TEXT --area PATH (--home LAYER:FILE | --no-home REASON) [--fix-commit SHA]
the fix is committedlink --fix-commit SHA ID
the linked commit does not hold the fixunlink --reason TEXT ID
after merging, end of session, scheduletidy [--check CMD] [--dry-run]
the store feels repetitivegroups [--min-overlap X], then merge [--what TEXT] [--why TEXT] [--reason TEXT] KEEP ABSORB [ABSORB ...]
a retired failure is backsearch --all ..., then unretire --reason TEXT ID
a change was wrongshow ID, then undo ACTION_ID

--path and --area take one value each; repeat the flag for more (--area a.py --area b.py).

Skills associés