MemoryLake
Back to all articles
NewsNovember 17, 2026·13 min read

Can Claude Code and Codex Become Self-Improving? What Microsoft's TokenEconomizer Learns From Past Sessions, When It Drops a Fact, and Where It Keeps What It Learns (2026)

You open Claude Code in the same repository for the fourth day in a row. Within the first few minutes, it tries pytest, finds it isn't on the path, and switches to python -m pytest, the same detour it took on Monday, Tuesday, and Wednesday. In another window, Codex is doing something similar in a different project: rereading the build script to work out a step it worked out yesterday.

That pattern is the starting point of a project Microsoft Research wrote about on November 16. The blog post puts it plainly: "Developers use AI coding agents in the same codebases day after day, yet agents often start each session from scratch: rediscovering familiar facts, loading unused tools, and repeating unsuccessful approaches."

The project is TokenEconomizer, an open-source plugin from UC Berkeley, Microsoft Research, and Microsoft Security. Microsoft's announcement leads with what it saves in cost. This guide looks at the part that matters if you're asking whether Claude Code or Codex can become self-improving: what the plugin learns from your past sessions, the rule that decides when a learned fact is trusted, when that fact gets dropped, where everything is kept, and what it doesn't learn at all.

What TokenEconomizer is

Microsoft's description: "TokenEconomizer is an open-source plugin that learns from an agent’s past sessions in a repository to reduce waste in future sessions, without modifying the agent or its underlying model." It's a plugin, not a feature of Claude Code or Codex. Neither Anthropic nor OpenAI ships it. You add it to the agent you already use, and the agent itself stays the same. The project's README says it is a plugin for Claude Code, Codex, the GitHub Copilot CLI, and Pi, with experimental support for several other agents.

It learns per repository. The unit of learning is the codebase you keep returning to. The blog explains the reasoning with its own measurements: repeated actions within one repository were far more common than matches against another repository's history. Experience from one project mostly helps that project.

So the honest answer to the headline question is narrow. Claude Code and Codex don't retrain themselves. A plugin like this one can watch what happens in your sessions and change what the next session starts with.

What it learns: three kinds of lessons

The blog describes three mechanisms. Each one turns past sessions into a different kind of lesson.

Micro-skills: facts about how the repository works. The README describes these as things "Sessions keep rediscovering", such as "a build step that must run first, the spelling of a command that works here", an environment variable a command needs, or where generated files live. The blog calls them repository-specific knowledge in one-line notes.

Tool pruning: which tools this repository never needs. Every loaded tool's description is sent with every request. If the history shows a tool going unused, the plugin leaves it out of later sessions through the agent's own settings. Core tools for running commands and editing files are always kept.

Failure-loop intervention: when a turn is stuck. When the agent keeps hitting the same failure, a judge model decides whether it's really stuck. If so, the agent gets a short note suggesting a different approach.

Only the first of these is memory in the everyday sense, a fact carried from one session into the next. The other two are lessons about behavior. All three come from the same source: after each session, as the blog puts it, "TokenEconomizer reads the session’s log and updates what it knows about the repository."

The rule that decides when a fact is trusted

This is the part of the design most worth borrowing, whether or not you install anything.

A fact isn't added the first time it shows up. The README states the threshold: "A fact is stated at the start of each session once three sessions have confirmed it, and dropped when later sessions contradict it."

The facts come from two places, according to the README: "failures that repeat across sessions", and a model that reviews recent sessions every few sessions and proposes facts. A proposal on its own isn't enough. It has to be confirmed by repeated evidence before it reaches the agent's starting context. Until then, it sits in a list of facts that are still forming.

The blog describes the same gate in its own words: notes "are added to the agent’s starting context only after several sessions have confirmed the pattern, and retires the note if later evidence contradicts it."

Why does this matter? Because the obvious way to build a self-improving agent is to let it write down whatever it concludes at the end of a session. That approach has a known weakness: one lucky guess, or one wrong conclusion, becomes a standing instruction for every future session. A threshold of repeated confirmation is a direct answer to that. One session can't create a fact by itself.

The README lists this as a design principle: "Facts form only from repeated evidence, tools are removed only after going unused, and the loop guard leaves alone a turn that is still making progress."

When a fact gets dropped

The other half of the rule is just as important. A learned fact isn't permanent.

If later sessions contradict a fact, it's dropped. If your team moves from one test runner to another, the old command stops being confirmed and starts failing, and the plugin retires the note. Nothing in the README suggests the fact sits there forever because it was once true.

The same reversibility applies to the other mechanisms. The README's principle is "Keep every action reversible", and it spells out what that means: "A fact that later sessions contradict is dropped, removed tools can be given back, and the loop guard only redirects and tells you: stopping a turn is your call."

For pruned tools, the README's description is short: "One command brings it back."

For stuck turns, the plugin's limit is explicit. After a redirect, if the turn is still stuck, the README says TokenEconomizer tells you how to stop it, and "it never stops a turn itself."

So the learning loop has a brake at each end. Facts need repeated confirmation to get in, and contradiction to get out. The tool list can be restored. A stuck turn stays your decision.

Where it keeps what it learns

The README answers this directly: "What it learns stays on your machine, in ~/.tokeneconomizer."

The blog repeats the point: the plugin "keeps what it learns on the developer’s machine". It also notes that the plugin requires no API key of its own.

That has a few practical consequences:

  • It's per machine. A teammate working in the same repository on their own laptop starts with their own copy, built from their own sessions.
  • It's per repository. What it learns in one codebase is kept for that codebase.
  • It works through what the agent already reads. According to the README, "Facts enter the context at session start, and tools are removed through the agent's own settings, so nothing depends on the agent learning a new tool."

The model calls the plugin makes, such as the fact proposer and the judge, also run through your own agent. The README says they run "on the same plan or login", and their cost is included in the plugin's reports.

You can look at what it has learned. The plugin's commands include status, which shows what it learned and did in the repository, and microskills, which lists "the facts it injects, and those still forming". In Claude Code the commands are typed with a /tokeneconomizer: prefix, and in Codex with $tokeneconomizer:.

What's on by default, and what isn't

This matters if you expect the memory part to start working right away.

Tool pruning and the loop guard are on by default. Micro-skills, the part that learns facts, isn't. The README explains why: "Micro-skills is off by default, because its proposer adds model calls and how much it saves depends on the repository and the work you do there."

You turn it on per repository, or for every repository, with the plugin's config command. There's also a lighter mode that learns facts only from repeated failures, without model calls.

On Claude Code there's one more option. The README says: "On Claude Code, the plugin can also learn from a repository's earlier sessions, read from Claude Code's own logs oldest first and without any model call. This is off by default". It only reads that history before the plugin has learned from any session in the repository, so it's meant to be turned on right after you install.

What it doesn't learn

Reading the README closely, the boundaries are clear.

It doesn't learn why. A micro-skill is a one-line fact: run this step first, use this command spelling. The reasoning behind a design choice, a conversation about which approach to take, or a decision your team made last month isn't the kind of thing the mechanism is built to capture.

It doesn't learn from one session. The confirmation threshold means a lesson you learned the hard way today won't reach tomorrow's session from this plugin. It needs to repeat.

It doesn't share across tools by itself. The commands and storage are per machine. If you use Claude Code for one task and Codex for another in the same repository, how the two hosts share what's learned isn't something the README describes in detail, so it's safer not to assume they see the same facts.

It doesn't replace your instruction files. Facts are stated at session start alongside whatever the agent already loads, such as CLAUDE.md or AGENTS.md. Those files remain where your team's agreed conventions belong.

Claude Code also has its own built-in memory that the agent writes for itself. We covered how that works in our guide to what Claude Code auto memory is.

Which versions it was tested on

The README lists tested version ranges for each agent: Claude Code 2.1.300 to 2.1.310, and Codex 0.153.1 to 0.164.0. It adds that "newer versions have not been tested yet."

Both agents have shipped releases past those ranges. That doesn't mean the plugin fails on them, only that its authors haven't listed them as tested. If you try it on a newer release, check status after a few sessions to confirm it's recording what you expect.

For Codex specifically, plugin hooks need to be trusted before they run, and the README says the hooks take effect from your next Codex session.

What the research found about learning over time

The blog reports that cost fell in every repository tested while task success stayed broadly stable. The more interesting finding for this guide is the shape of the curve: "Savings grow as experience accumulates."

Early sessions in a repository can cost more while the plugin learns. In the blog's Claude Code results, every repository became cheaper than the default by the sixth task. That's what you'd expect from a design that waits for repeated evidence: it trades a slow start for fewer wrong lessons.

The researchers also found that a fixed strategy didn't work everywhere. Three other open-source plugins they tested, each built around a fixed cost-saving approach, helped in some repositories and not others. Their conclusion was that cost control has to adapt to the repository, which is why everything is learned per codebase.

Anthropic has written about the same tension from the other side. Its guidance for always-on agents says memory should hold only what an agent can't easily look up again, which we covered in our guide to what always-on agents are.

What people try first

Expecting the agent to learn by itself. Claude Code and Codex don't retrain on your sessions. Learning across sessions comes from memory features and plugins like this one.

Turning everything on and waiting for facts. Micro-skills is off by default. Check config before concluding nothing was learned.

Writing down every conclusion after each session. That's the approach the confirmation threshold is designed to avoid.

Assuming a learned fact is permanent. Contradicted facts are dropped, and pruned tools can be restored.

Expecting the plugin to hold decisions. It holds one-line facts about how the repository works, not the reasoning behind choices.

The Fix: Let lessons earn their place

Step 1: Decide what kind of lesson you want to keep

Separate facts about the repository (commands, setup steps) from decisions (why an approach was chosen). They need different homes.

Step 2: Require repeated evidence before a lesson becomes an instruction

Whether a plugin or a person writes it, wait until a lesson has held up more than once before adding it to what every session loads.

Step 3: Give every lesson a way out

When a fact stops being true, remove it. Review learned facts and instruction files on a schedule.

Step 4: Write down the decisions yourself

The reasoning behind a choice won't show up as a repeated failure. Record it on purpose, in words a future session can use.

Setting this up in MemoryLake

TokenEconomizer learns how a repository behaves. The decisions behind your work, such as which approach you chose, which one you ruled out, and why, have to be written down by someone who knows them.

MemoryLake is a memory layer for that kind of project context, such as decisions, conventions, and lessons that have held up, kept in one place you maintain and available to the assistants you connect, such as ChatGPT, Claude Code, and Codex.

You write the entries yourself, in your own words. Nothing is read out of, written to, or deleted from ~/.tokeneconomizer, your session logs, your agent's settings, your CLAUDE.md or AGENTS.md files, or any vendor's store. TokenEconomizer and each agent's own memory work the way their authors describe them.

Step 1: Create an API key

Sign in and generate a key from the dashboard. Store it outside your repositories, like any other credential.

The MemoryLake console showing the API keys screen, where a new key is created and copied for use in an agent
The MemoryLake console showing the API keys screen, where a new key is created and copied for use in an agent

Step 2: Upload your first memories

Start with what you wrote in Step 4 of the fix: decisions from recent sessions and the reasons behind them. One decision per entry, with its date.

The MemoryLake workspace with the first documents uploaded, listing each file as it becomes searchable memory
The MemoryLake workspace with the first documents uploaded, listing each file as it becomes searchable memory

Step 3: Connect your AI & agents

Connect Claude Code, Codex, and the other assistants you use. Each can draw on the same decisions.

The MemoryLake integrations screen listing the AI clients and agent frameworks that can be connected to the memory layer
The MemoryLake integrations screen listing the AI clients and agent frameworks that can be connected to the memory layer

What this changes in practice

The first difference is a cleaner split. Repeated facts about the repository can be learned automatically, and decisions are written by people.

The second is fewer wrong lessons. A decision you record is one you've checked, not one inferred from a single session.

The third is continuity across tools and machines. The reasons behind your work aren't tied to one laptop's plugin data.

Best practices for self-improving coding agents

Learn per repository. The research found experience helped mostly within the same codebase.

Confirm before you trust. A lesson should hold up across sessions before every session loads it.

Keep it reversible. Every learned fact needs a way to be dropped.

Check what's on. Micro-skills is off by default in TokenEconomizer.

Look at what was learned. Use the plugin's microskills command to see injected and forming facts.

Keep conventions in instruction files. CLAUDE.md and AGENTS.md remain the place for agreed rules.

Record decisions on purpose. They won't appear as repeated failures.

Conclusion

Claude Code and Codex don't retrain themselves, but a plugin can change what their next session starts with. Microsoft's TokenEconomizer learns per repository from past session logs: one-line facts, unused tools, and stuck turns. A fact reaches the starting context only after three sessions confirm it, and it's dropped when later sessions contradict it. Everything is kept on your machine in ~/.tokeneconomizer, and the fact-learning part is off by default.

The design is a useful model for any self-improving setup: require repeated evidence, give every lesson a way out, and keep the reasoning behind your decisions somewhere you maintain yourself.

Frequently asked questions

Can Claude Code learn from past sessions?

Claude Code has its own memory features, and plugins such as TokenEconomizer can learn from a repository's past session logs and add confirmed facts at the start of new sessions.

What is TokenEconomizer?

An open-source plugin from UC Berkeley, Microsoft Research, and Microsoft Security that learns from an agent's past sessions in a repository, without modifying the agent or its model.

Does TokenEconomizer work with Codex?

Yes. The README lists Codex as a supported agent, alongside Claude Code.

How does it decide a fact is true?

A fact is stated at session start once three sessions have confirmed it, and dropped when later sessions contradict it.

Where does it store what it learns?

On your machine, in ~/.tokeneconomizer.

Is the learning on by default?

Tool pruning and the loop guard are. Micro-skills, which learns facts, is off by default.

Can it stop my agent?

No. If a turn stays stuck after a redirect, it tells you how to stop it, and it never stops a turn itself.