DEV Community

Cover image for Coding agents relearn your repo every session, and you pay for it
Reno Lu
Reno Lu

Posted on

Coding agents relearn your repo every session, and you pay for it

If you run a coding agent in the same repository every day, you pay for the same discoveries over and over. It finds out again that pytest is missing and python -m pytest works, it loads tool definitions it never calls, and it repeats the same failing command. TokenEconomizer, a plugin from UC Berkeley, Microsoft Research and Microsoft Security, learns from the sessions you have already run and cuts that repeated waste in the ones that follow.

The team reports 18.4% to 30.9% lower mean cost on SWE-Bench tasks across five agent and model combinations, cheaper in all 30 repository and combination cells, with Pass@1 up in 4 of the 5. It does this without touching the agent's model, weights or code.

Three ways to stop paying twice

Each mechanism has a setting, shown here with its default, and each can be turned off.

Micro-skills remember facts about the repository: a build step that must run first, the spelling of a command that works here, an environment variable a command needs, where generated files live. Facts come from failures that repeat across sessions, and from a model that reviews recent sessions every 3 sessions and proposes facts. A fact is stated at the start of a session only once three sessions have confirmed it, and it is dropped when a later session contradicts it.

Tool pruning stops loading tools that go unused, since every loaded tool's definition is sent with every request. A tool unused over 10 prompts spread across at least 2 sessions, or over 5 sessions of any length, is left out of the next sessions through the agent's own settings. One command brings it back.

The loop guard watches for a turn that keeps hitting the same failures. A judge model checks whether the turn is stuck. If it is at least 0.7 sure, the agent gets a short redirect note, at most once per turn. If the turn is still stuck after that, the plugin tells you how to stop it. It never stops a turn itself.

The design choices I would copy

Four principles sit behind the mechanisms, and I would borrow them even without installing the plugin.

Everything goes through what the agent already reads. Facts enter the context at session start and tools are removed through the agent's own settings, so the agent never has to learn a new tool.

Cost is counted the way it is billed. Most tokens in a session are cached re-reads, so the plugin computes cost with cache pricing and includes its own model calls. Those calls, the fact proposer and the judge, run through your own agent on the same plan or login, and their cost shows up in its reports.

To protect task success, facts need repeated evidence, tools go only after going unused, and the loop guard leaves a turn alone while it is still making progress.

Each action can also be undone: contradicted facts are dropped, pruned tools come back with one command, and stopping a stuck turn stays your decision.

If any part of the plugin breaks, your session carries on as if it were not installed. What it learns stays on your machine in ~/.tokeneconomizer, and it needs no API key and never handles credentials.

Where the numbers come from

The paper ran 277 SWE-Bench tasks from six repositories. Each task ran as its own session, and each repository's tasks ran in order starting with nothing learned. Within each repository and combination, cost fell by 5% to 40%. The team also reports 16% to 21% lower cost on Web-Bench, and 6% to 20% on two security-auditing benchmarks where every task is in a new repository. Pass@1 was not uniformly better: Claude Code with Opus 4.8 saved 30.9% but lost 1.0 points. The experiments/ folder reruns the SWE-Bench and Web-Bench runs.

Installing it

It supports Claude Code, Codex, the GitHub Copilot CLI and Pi, with experimental support for several others. You need Python 3.10+. For Claude Code:

git clone https://github.com/microsoft/TokenEconomizer.git
claude plugin marketplace add "$PWD/TokenEconomizer"
claude plugin install tokeneconomizer@tokeneconomizer
Enter fullscreen mode Exit fullscreen mode

Leave the clone in place, start claude in a repository you use often, and run /tokeneconomizer:status. Micro-skills and tool pruning need several sessions of history before they act, so I would judge it after a week in one repository.


Curated by Agent Palisade — practical AI for small and mid-sized businesses.

Top comments (1)

Collapse
 
kamalmosadegh profile image
Kamal Mosadegh •

The design choice I would copy first is the one you buried in the middle: everything goes through what the agent already reads, and every learned fact is reversible. That is what separates a memory system from a prompt that slowly rots. A fact learned from one broken session — say, "pytest is missing" when the real fact is "the venv was not activated, so python -m pytest works" — is worse than no memory at all, because the agent will confidently repeat the wrong fix. Requiring repeated evidence before a fact sticks, and dropping contradicted facts, is the minimum bar for trusting anything the plugin remembers.

The number I would want before adopting it is not the 18.4% to 30.9% mean-cost range on SWE-Bench, useful as that is, but the cost on a fixed task in my own repo over ten sessions — because micro-skills and tool pruning need several sessions of history before they act, the first few sessions are the control group and the honest comparison only starts after that. If Pass@1 holds while the re-read tokens fall, the saving is real; if the agent just does less exploration, the saving is a quality cut wearing a cost costume. The loop guard is the part with the clearest payoff in my own agent work: a turn that repeats the same failing command is the most expensive failure mode there is, and a judge that stops it after two identical failures pays for itself in a single afternoon.