agentleFS
KasperChenGHKasperChenGH/token-diet/skills/SKILL.md

token-diet

Skill1 starsChanged 5 months agoMITView on GitHub

Use when an agentic or multi-agent workflow burns excessive tokens — usage limits hit repeatedly, high cache read/write volume, subagents spending most of their budget re-reading files, every session re-establishing the same context, or an LLM recomputing deterministic results. Also use before designing any recurring multi-agent pipeline (CI agents, review bots, research loops, support triage, data workflows).

4 other projects use a version of this.

Adopted by

Most recently taken up by

  • Other versions4 projects use a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 4

    1. Kulaxyz/token-diet★ 470same name
    2. VDADev2022/token-diet★ 4same name
    3. arroyoarellanoangela/token-diet★ 0same name
    4. uniqaiapp/token-diet★ 0same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

The file

We split this skill into the rules it gives an agent

2 rules. 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 4 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    After one cycle on the new architecture, compare actuals to estimates.

    line 39
  2. Very specific:

    Test/build/log output dumped whole into context instead of filtered to the relevant lines

    line 49

“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Token Diet

Overview

Most token waste in agentic systems is structural, not stylistic. Shorter prompts and cheaper models are the last 20%; the first 80% comes from removing agents, sessions, turns, and LLM-work that shouldn't exist. Work the levers in order — each level shrinks the next.

Core principle: optimize the architecture before the artifacts.

Applies to any recurring agent workflow: PR-review fleets, CI fix-bots, research/analysis loops, support triage, content pipelines, data-quality agents.

Step 0 — Measure before touching anything

Don't trust intuition. Sum real usage from wherever your stack records it (API responses carry usage per call; Claude Code stores per-message usage in ~/.claude/projects/<project>/*.jsonl; most frameworks log equivalents). Split by: output, cache writes, cache reads, per agent and per session. Compute each agent's useful-work ratio = reasoning+output ÷ total tokens. An agent at 10% is reading, not thinking.

Mechanics you're optimizing:

  • Cache reads = context size × turn count, re-sent every turn (~0.1× price). Two cuts: fewer turns (batch independent tool calls into one message) and smaller context.
  • Cache writes = new context first cached (~1.25× price, ≈12× dearer per token than reads). Scales with spawn count — every new agent/session re-caches its files.
  • Output = full price. Scales with narrative habits and LLM-recomputed analysis.

The levers, in order of leverage

#LeverThe questionTypical saving
1Delete agentsDoes each subagent buy parallelism, isolation, or model-arbitrage worth more than its establishment tax (system prompt + tools + shared files ≈ 20–40k per spawn)? If not, do the work inline — or not at all. Make spawning conditional on measurable triggers (reviewers only when code changed; analysts only when results exceed what one pass can hold; never "for thoroughness").40–60%
2Merge sessionsCan N sessions per cycle (plan→execute→summarize; triage→fix→report) become ONE that ends by writing state and staging the next cycle? Carry state in files/tickets/DB — never in conversation. Fresh sessions per cycle are also your contamination guarantee.25–40% of the rest
3Evict computeIs any long-running command (builds, test suites, training, batch jobs) running inside a session, with the agent babysitting it? Move it to a driver (shell script, CI step, cron) between sessions: zero tokens, no timeouts, no died-while-waiting failures. (Read-path corollary: readgate denies redundant within-session re-reads of unchanged files — the read-path twin of the Lever 8 output filter.)all compute-adjacent tokens
4Scripts compute, LLM judgesIs the LLM doing arithmetic, diffing, threshold checks, pass/fail verdicts, format conversion, report assembly? Write a deterministic kernel that emits conclusions; the LLM reads conclusions and judges only the surprises and the next decision. Bonus: eliminates LLM math/judgment drift.30–50% of analysis tokens + correctness
5Tier the knowledgeAre agents re-reading static reference material every run (style guides, domain docs, API references, runbooks)? Three tiers: a living doc (<100 lines, always loaded: rules, current state, open items — replace, don't append), digests (~2k distillations per pack, each section carrying a Source: pointer), archive (full files, pulled only when a specific claim needs depth).50–80k per agent per run
6Trim the always-loadedWhat loads into EVERY agent (project instructions file, entry-point commands, tool surface)? Cut to essentials; depth goes to on-demand reference files. Each autonomous entry point gets a self-contained contract — prose mode-overrides layered on shared instructions WILL eventually be misread by an autonomous agent.2–5k × every spawn
7Model arbitrageReserve the big model for where judgment lives (strategy, synthesis, ambiguous calls). Route mechanical work — focused reviews, extraction, bulk edits, data crunching — to a small model. token-diet route makes this concrete: a deterministic rule table classifies a task into a tier, routing down only when confident and escalating high-stakes/ambiguous work to the top tier. Also: delegate a big-context agent's mechanical multi-turn work to ONE small-model agent.3–5× on the delegated share
8Filter tool outputAre verbose command outputs (test suites, build logs, git status, listings, large file reads, MCP server responses) dumped whole into context, then re-sent every turn as cache reads? Filter at the source: a PostToolUse hook that compresses stdout per command kind (failures-only for tests, single-line confirms for git, head+tail+count for listings, structural crush for JSON/MCP, signatures-only for big reads).often the largest cache-read source

The fix command can scaffold exactly this as a disabled Bash PostToolUse hook; you enable and smoke-test it. token-diet measures whether you need it before you wire it in.

Step N — Re-measure and review

After one cycle on the new architecture, compare actuals to estimates. Then run an adversarial consistency review with an independent agent: every architectural change leaves stale instruction copies in files it didn't touch — hunt contradictions across all entry points before trusting the system unattended.

Red flags — wrong order of operations

  • You started with prompt wording or model choice (start with the agent census)
  • A subagent exists "for thoroughness", with no parallelism/isolation/arbitrage justification
  • Sessions wait on multi-minute commands
  • The LLM computes anything a 100-line script could
  • Reference packs are re-read verbatim every cycle ("it might need the detail")
  • State carries across cycles via conversation history or summaries instead of files
  • You "saved tokens" without measuring before AND after
  • Test/build/log output dumped whole into context instead of filtered to the relevant lines

Common mistakes

MistakeFix
Optimizing file sizes while keeping ceremonial agentsLever 1 first — census, then diet
Treating cache reads as a file-size problemReads = context × turns; batching tool calls cuts them as much as smaller files
Digests written, but agents still load full packs "to be safe"The contract: digest by default, full file ONLY when a named claim needs depth — and digests carry Source: pointers to make that cheap
Merging sessions by letting one conversation grow foreverOne fresh session per cycle; files are the memory, not the transcript
Treating spawn overhead as pure wasteIt's the price of isolation — pay it exactly where isolation, parallelism, or arbitrage is worth it
Skipping the consistency review after restructuringStale contracts in untouched files are how autonomous agents go off-script

Real-world impact (one measured case)

A 23-round autonomous research loop (Claude Code, Opus + Sonnet): ~1.1M tokens/round → ~100–180k/round (≈85%) while reliability improved — subagent useful-work ratio rose from ~9% to ~40%, and moving verdict math into a script kernel eliminated two recorded LLM-judgment errors. The same levers transfer to any recurring agent pipeline; the loop's domain contributed nothing to the savings — the architecture did.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.