agentleFS
Lesile-YinLesile-Yin/agent-skills/skills/token-warden/SKILL.md

token-warden

Skill2 starsChanged 3 months agoMITView on GitHub

Token budget guardian for agent sessions. Models token consumption in four independent layers (context reading, tool/command output, conversation output, code generation), routes each layer to its most efficient tool or behavior, and enforces anti-pattern rules. Use in long coding sessions, large-repo work, or whenever the user asks to save tokens/cost, or a session starts hitting context limits.

The file

We split this skill into the rules it gives an agent

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

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When invoked, first state which layer(s) dominate the current task, then apply the routing table to those layers.

    line 27
  2. Distinctive:

    When context feels heavy (~70% of window), announce a checkpoint: compress the working state into ≤ 20 bullets (decisions, paths, next …

    line 60

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “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 Warden

Tokens are spent in four independent layers. Optimizing one layer does nothing for the other three — and most "save tokens" advice only touches one. This skill audits all four and applies the cheapest adequate tool per layer.

The four-layer model

LayerWhat burns tokensSymptom of waste
R — ReadingFiles, search results, docs pulled into contextFull-file reads to find one symbol
T — Tool outputCommand stdout, test logs, build outputRaw 5k-line logs pasted into context
C — ConversationThe agent's prose, explanations, summariesPreamble, restating, apology loops
G — GenerationCode written/rewrittenWhole-file rewrites for 3-line fixes

When invoked, first state which layer(s) dominate the current task, then apply the routing table to those layers. Do not ceremony for a task that is small.

Routing table

Full rules and fallbacks: references/routing-rules.md.

LayerFirst choiceFallback if unavailable
RSymbol/semantic lookup (LSP-style) for "where is X defined/used"Targeted read with line range; grep only for text patterns
RGrep with -n and tight pattern for occurrencesGlob to narrow files first, then read ranges
TPipe to filters inside the command (head, grep, jq, tail -n)Run, then read only the saved output range
T--quiet/--silent flags; machine-readable output parsed, not quotedSummarize output; never paste > 50 lines verbatim
CTerse mode: no preamble, no restating, no apologyStructured bullets over prose; tables over lists of pairs
GMinimal-diff edits (change only touched lines)Full rewrite only when > 50% of the file changes

Anti-patterns (hard rules)

  1. Never two readers at once — one lookup mechanism per question. Running grep and full-file read for the same symbol doubles layer R.
  2. Never read to summarize — if the goal is a one-line answer, read only enough to produce that line.
  3. Never paste, filter — command output enters context only after a filter or an explicit "I need the raw log" from the user.
  4. Never rewrite to fix — a localized bug gets a localized edit.
  5. Never re-read what context already holds — check the conversation before re-fetching a file.

Budget protocol (long sessions)

  • At session start or on request, estimate the task's layer profile with scripts/estimate_tokens.py (heuristic, zero deps; uses tiktoken if installed).
  • When context feels heavy (~70% of window), announce a checkpoint: compress the working state into ≤ 20 bullets (decisions, paths, next step), then continue from the checkpoint instead of carrying raw history.
  • Report savings only when measured: before/after estimates on the same task slice. Never invent percentages.

Output contract

Announce routing in one line when non-obvious, e.g. token-warden: R→grep+range-read, T→jq filter, G→minimal-diff. Then do the work. The skill itself must never add more tokens than it saves — if applying it would cost more than the waste it prevents, skip it and say so.

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.