Published on , Aurélien Vandaële

How to make Claude Code self-improving: my postmortem and retro loop

Claude Code does not improve on its own: every session starts from a fresh context, and only files carry over from one session to the next. To make it improve, I set up a loop. Every failure becomes a written entry, with its cause and the step responsible, then a retro command reads those entries and proposes one precise change to an agent, a skill, a hook or a script. I approve, the change is applied, the entry is marked “absorbed”. On the previous version of my chain, 28 entries out of 30 were.

Why Claude Code makes the same mistake again

The Claude Code documentation says it plainly: every session begins with an empty context window. Two mechanisms carry knowledge across sessions, the CLAUDE.md file you write and auto memory, where Claude notes your corrections. Everything you explained in the thread of a conversation goes away with it.

With a chain of several agents, it gets worse. A failure does not always come from the model: it often comes from a brief that is too thin, a script that checks the wrong thing, or an agent missing a rule. Fixing the result in the conversation changes none of those files. The same failure comes back on the next run.

One example from my ledger: several subagents started a command in the background, then ended their turn saying they were waiting for the result. For a subagent, ending its turn means being done. Nothing was produced. Four occurrences, about 600,000 tokens lost, before the rule was written into every agent file.

The loop: one entry per failure, one retro that changes the chain

My chain runs in a Claude Code plugin, and the plugin holds the whole loop. Three moments trigger an entry:

  • Automatically, when a task is still blocked after two review rounds. The chain stops, writes the entry and tells me. Why two rounds and not three is in the article on code review by an agent.
  • On demand, after several failed fixes on the same problem.
  • When the chain itself misbehaves: an agent that returns nothing, a command that never ends, a tool that surprises. Those entries go into a separate folder, so they are not mixed up with a project's bugs.

Every entry has the same shape: the symptom, the root cause (the real one, not the symptom rephrased), the fix, the follow-up actions, and a mandatory Responsible field naming the agent, skill or script at fault. That field is what shows that one step fails often.

Then /pipeline:retro reads the open entries, the outcome of each task and the costs. It groups by responsible step, and keeps a pattern only if it recurs or blocked a task. For each pattern, it proposes one change, in a named file. It changes nothing without my approval. Once a proposal is accepted, it applies it, runs the plugin's tests, then adds Status: absorbed to the entry with the file changed. Entries are never deleted: the ledger is also a history.

A written rule or an enforced guard

The retro has one instruction that matters more than the others: when the failure is mechanical, prefer an enforced guard (hook, script) over one more sentence in a prompt. The Claude Code documentation makes the same point: CLAUDE.md is context, not enforced configuration, and to block an action whatever the model decides, you need a hook.

Two real entries show the difference:

  • A fix agent added an AI co-author line to its commits, although the project forbids it. The instruction already existed in plain words. The absorbed fix is a verification script, run after every agent commit, that rejects that kind of line. There is nothing left to forget.
  • Tests that checked nothing. In a single run, five tests went green while the defect they were meant to catch was still there: one test compared the code against the very constant it was supposed to check, another asserted the absence of a component that did not exist yet. All five were found by the reviewer reintroducing the defect, none by the test suite. I go through these five shapes in the post on unit tests written by Claude Code. Here no script was possible: the absorbed rule is a sentence in the skill of the test-writing agent, “a test must fail if the behaviour it claims is broken or removed”.

The hooks in my chain follow the same logic: whatever a command can check does not depend on the model's goodwill. I cover them in the article on hooks.

What did not work

  • A fix that is too narrow does not last a day. One entry: the test-writing agent handed over a file with lint errors, which blocked the coding agent. Fix: run the linter on its files. The same day, same block, this time on a type error. The rule had to be written at the level of the category, “run the full fast check, lint and types”, not of the day's example.
  • “Absorbed” does not mean “solved forever”. An old entry about two sessions committing to the same branch had been absorbed since August. In October the problem came back in another form: another session swept into its own commit the fix an agent had staged. The verification script saw nothing, because it did not check the commit title. New entry, new follow-up.
  • Some causes stay unknown. A review agent returned an empty answer twice in a row. Never reproduced. The entry honestly says “unknown cause” and only proposes a workaround: validate the answer and retry once.
  • The loop is only worth it if the retro runs. Six entries for blocked tasks are still open across my projects, with their rules proposed but not yet applied. In one series of tasks, the second entry notes “same lesson as the first”, written the day before: a task too wide for a single review cycle. Until the retro runs, the lesson sits in a file nobody reads.

How to start without a plugin

You do not need my whole chain to start. A folder of entries and a habit are enough:

# 0001 · <short title>
- Date: 2026-11-20
- Responsible: <agent, skill, hook or script at fault>

## Symptom
## Root cause
## Fix
## Follow-up actions
  • When Claude Code gets the same thing wrong twice, ask it to write an entry with this template, root cause included, instead of fixing it in the conversation.
  • Once a week, ask it to read the open entries, group them by responsible step, and propose one change per pattern in a precise file: CLAUDE.md, a subagent in .claude/agents/, a skill or a hook.
  • Prefer a hook or a script as soon as the failure can be checked mechanically. Keep the sentence in a prompt for what needs judgment.
  • Mark each handled entry with the file changed, and never delete it. The day the problem comes back, you will know what was already tried. What belongs in CLAUDE.md, and what does not, is in my best practices for that file.

Article written with the help of AI, from my daily practice and my projects.

The whole notebook