AI column

Coding@donghyeok99Staff

TokenEconomizer: cut repeat token waste in repos you revisit

A contributor ran it on their own ledger: 5,574 requests, about 9.5M tokens kept out

Six sessions in one repository line up; re-learning, unused tools and stuck loops drop off one by one, and the cost bars fall below the dashed line.
Six sessions in one repository line up; re-learning, unused tools and stuck loops drop off one by one, and the cost bars fall below the dashed line.
Who
Researchers at UC Berkeley, Microsoft Research and Microsoft Security, for people who run a coding agent in the same repositories often.
When
The repository was created on 2026-10-13; its first release, v0.1.0, came out on 2026-10-26.
Where
Runs with Claude Code, Codex, the GitHub Copilot CLI and Pi; what it learns stays on your machine in ~/.tokeneconomizer.

What was hard

Run an agent in the same repository many times and the tokens leak in the same places. Every session finds out again, after a failure, that this repository needs python -m pytest and not pytest. The definition of a tool that never gets used is still sent with every request. And a turn that meets the same error a third time and tries the same edit again just runs until it ends.

What it does about it

TokenEconomizer leaves the agent's model and code alone and learns across the sessions of one repository. A fact that three sessions confirmed is stated at the start of the next one, and a tool that goes unused long enough is left out through the agent's own settings file. When a turn keeps hitting the same failures, a judge model checks whether it is stuck and, if so, adds one short note to try another approach. It never stops a turn itself, and one command gives removed tools back.

The README's teaser: six session cost bars, the three mechanisms, the results
The README's teaser: six session cost bars, the three mechanisms, the results
The README's overview: each finished session's log updates all three
The README's overview: each finished session's log updates all three

What people made with it

GitHub@hkchao2026-10-31

A contributor who built a te savings command that reports what tool pruning saved, and ran it on a real ledger: 17.6k tokens kept out of each request.

Ran against a real ledger: 5,574 requests, 17.6k tokens kept out of each, about 9.5M tokens net.
comments 3 (2026-11-29 as of)GitHub ↗

How it runs inside

  1. 1

    Claude Code → te-hook

    Six hooks: SessionStart, PostToolUse and moreSession start, each prompt, tool calls and failures, and the end all call the same te-hook script.plugin/hooks/hooks.json
  2. 2

    te-hook → Claude Code

    Learned facts at session startEach hook is a fresh process that reads state from disk and adds confirmed facts to the context.tokeneconomizer/plugin/controller.py
  3. 3

    te-hook → Judge model

    A turn repeating the same failuresThe loop guard watches one tool call at a time and hands a turn that looks stuck to the judge.tokeneconomizer/loopguard/turn.py
  4. 4

    Judge model → Claude Code

    One redirect noteThe judge call goes through your own agent's CLI; at 0.7 confidence or more a note to try another way is added.tokeneconomizer/plugin/judge.py
  5. 5

    Claude Code → ~/.tokeneconomizer

    The finished session's logA finished session is folded into the repository's facts and tool-use evidence.tokeneconomizer/plugin/fold.py
  6. 6

    ~/.tokeneconomizer → .claude/settings.local.json

    Deny list of unused toolsTools unused long enough are written to the agent's own settings file; restore takes them back.tokeneconomizer/plugin/denylist.py
  7. 7

    ~/.tokeneconomizer → /tokeneconomizer:status

    What it learned, what sessions costThe status command shows what it learned and did in this repository and what your sessions cost.tokeneconomizer/plugin/cli.py

What goes in, what comes out

A repository where pytest is missing and the test command fails every sessionOnce three sessions confirm it, python -m pytest is stated at session start
A tool unused over 10 prompts across 2 sessionsLeft out of the next sessions through .claude/settings.local.json
A turn that keeps hitting the same failuresOne redirect note, then a line telling you to press Esc if it is still stuck

Is it for you

Good for

  • You run Claude Code or Codex in the same repository every day and watch what sessions cost
  • You have many MCP servers and tools loaded, but each repository only uses a few of them
  • You tend to notice late that the agent has been circling the same error

Not for

  • 18.4–30.9% is the paper's measurement on 277 SWE-Bench tasks; the README lists Pass@1 down 1.0 for Claude Code with Opus 4.8.
  • Only listed versions are supported: per the README, Claude Code 2.1.300 to 2.1.329 and Codex 0.153.1 to 0.171.0.
  • Micro-skills is off by default because it adds model calls, and tool pruning is not available on Pi or the experimental agents.
  • A command typed inside an agent costs one model turn; from a terminal, through te, it is free.

Reviewed by Devalley’s editor before publishing. How the column is made

Sign in to post, comment and like.Sign in

Report

Reason

Read the community rules