Everyone who works with a coding agent knows the ritual. The agent does something wrong. You correct it. It apologizes, fixes it, and the next session does the same thing again. So you add a line to CLAUDE.md. A week later you add it again, in capital letters.

One developer described the loop exactly in a bug report against Claude Code:

“Every time a violation occurs, the rule is re-stated, strengthened, and re-documented. The next session violates it again.”
anthropics/claude-code #33603

It is not one tool. On the Codex tracker, a user notes that the agent often self corrects its approach in its COT but never actually preserves the lessons (openai/codex #8368). Cline users report typing Read rules by hand (cline/cline #4423). The industry's answer has been more memory. We think that is the wrong shape for the problem.

Rules files are advisory

A rules file is text in a context window. The model reads it, weighs it against everything else it is reading, and sometimes decides otherwise. Claude Code's own documentation describes CLAUDE.md as context, not enforced configuration, and warns that when instructions conflict the model may pick one arbitrarily (Claude Code docs). After compaction, rules can drop out of view altogether (#6354, #4017).

None of that is a bug a vendor can fully fix. A sentence is a suggestion. If a rule matters, something outside the model has to check it.

Memory is local and single-tool

The other answer is automatic memory: let the agent take notes for itself. Every vendor ships a version now, and every version lives inside one tool on one machine. Claude Code's memory is, in the words of one feature request, individual-only (#38536). Codex memories are off by default, stored per machine, and the docs say to keep required team guidance in AGENTS.md (Codex docs). Cursor removed Memories in version 2.1 (Cursor forum). Copilot's memory is the most careful of the group, checking stored facts against the current branch, and it only works in Copilot, one repository at a time (GitHub docs).

Real teams do not use one tool. Someone runs Claude Code, someone else runs Cursor, and CI runs Codex. A lesson learned in one of them never reaches the others.

More context can make agents worse

It is tempting to fix forgetting with volume: save everything, inject everything. The evidence points the other way. A 2026 evaluation of AGENTS.md files found that context files did not improve task success on average while raising inference cost by over 20% (arXiv 2602.11988). Tools that capture whole sessions push in the same direction: one user of a popular memory plugin reported that Claude Code consumes all my tokens in <10 messages (claude-mem #618).

A memory is something the agent saw. A lesson is something you can prove.

What careful people already do

The developers who get the most out of agents tend to follow a strict, manual discipline. One Hacker News commenter put it this way:

“I only add information to AGENTS.md when the agent has failed at a task… I revert… re-run the task, and see if the output has improved.”
Hacker News, comment 47044313

That is a lesson, not a memory. It starts from a real failure, it is kept only if it changes the outcome, and it is tested by running it again. It works. It also does not survive past one person, one tool and one afternoon.

Scarcheck's answer

Scarcheck automates that discipline and nothing more.

  • Evidence first. A correction becomes a lesson only with something to point at: the commit that fixed it, a test that failed and then passed, or the turn where you corrected the agent. Without it, the lesson stays a draft and never reaches a rules file.
  • A check per lesson. File, grep, any test command (ast-grep and Semgrep are planned), or a guard that blocks an agent's command before it runs. The check has to fail on the commit before the fix and pass on the fix.
  • Every agent. One lesson compiles into CLAUDE.md, AGENTS.md, Cursor, Cline and Copilot rules, inside a fenced block Scarcheck owns. Your own text stays untouched.
  • A short list. Compile runs inside a token budget you set. Lessons that stop catching mistakes expire. Lessons that contradict each other are held back until a person decides.
  1. Correction
    no. this repo uses pnpm. never npm.
    Claude Code session 7f3c turn 12
  2. Evidence
    a41f9e2 fix: use pnpm, drop package-lock.json
    acme/web the commit that fixed the mistake
  3. Check
    file-absent package-lock.json, yarn.lock
    Fails on a41f9e2^Passes on a41f9e2
  4. Lesson
    L-142 Use pnpm. Never npm or yarn in this repo.
    Verified5 rules files 7 repeats caught

DraftNo evidence, no lesson. A correction without a check that passes this test stays a draft and never reaches a rules file.

Figure 1. How one correction in acme/web became lesson L-142. Each step has to hold before the next one runs.

In the terminal, the whole path is one command, plus one to write the rules files:

~/acme/web - zsh
$ scar learn --from-commit a41f9e2
✓ Rule   Use pnpm. Never npm or yarn in this repo.
✓ Check  file-absent package-lock.json, yarn.lock
  verifying against history
  ✗ a41f9e2^  check fails, as it should
  ✓ a41f9e2   check passes
Lesson L-142 verified.
$ scar compile
✓ 5 rules files updated  budget 1,212 / 1,500 tokens

When an agent repeats the mistake, it does not get a lecture in a rules file it may not read. The command is blocked before it runs, with the lesson and the fix: pnpm add dayjs, not npm install dayjs.

What we will not build

We are not building a memory layer. Scarcheck does not record your sessions to replay later, it does not store your source code, and it does not grow a context file forever. Lessons are plain Markdown in .scarcheck/ in your repository. You can review them in a pull request, edit them by hand, and remove Scarcheck without losing a single one. Share them the way you share code: commit them.

Teach it once

The goal is deliberately boring: the mistake you corrected on Monday does not come back on Friday, in any agent, on any machine. If that is the problem you have, the CLI is free and open source: build it from GitHub, run scar init, correct your agent the next time it slips, and watch whether the lesson holds.

Sources

  1. anthropics/claude-code #33603: CLAUDE.md hard rules consistently ignored
  2. openai/codex #8368: lessons not preserved across sessions
  3. cline/cline #4423: rules not read without a prompt
  4. Claude Code documentation: memory
  5. anthropics/claude-code #6354 and #4017: CLAUDE.md ignored after compaction
  6. anthropics/claude-code #38536: shared team memory request
  7. Codex documentation: memories
  8. Cursor forum: "Are my memories gone?"
  9. GitHub Docs: Copilot Memory
  10. arXiv 2602.11988, "Evaluating AGENTS.md"
  11. thedotmack/claude-mem #618: token use with session capture
  12. Hacker News, comment 47044313
Filed under Essays