agentleFS
jthiruveedulajthiruveedula/agentkit/skills/token-saver/SKILL.md

token-saver

Skill0 starsChanged 2 months agoMITView on GitHub

Cuts input-token burn: search before read, line ranges, diff-first, batched calls, no re-reads, terse output. Use when a session burns context, reads feel wasteful, or a task spans many files/logs/shell output.

26 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

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

  • 0

    Common

    Most of the 21 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 4

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Size before you read: Run scripts/estimate.py on candidate files.

    line 18
  2. Very specific:

    Search before read: Never full-file-read to *find* something.

    line 29
  3. Very specific:

    Diff-first: Before reading both versions of a changed file, run git diff --stat then git diff -- <file>.

    line 46
  4. Very specific:

    Measure the session, not just the read: Run scripts/session_audit.py to see real spend from Claude Code transcripts.

    line 72
  5. Distinctive:

    One read, one purpose: If you're reading to find X, stop at X.

    line 86
  6. Distinctive:

    Don't finish the file "in case".

    line 87

“Common” is measured: kept by at least 6 in 10 of the 21 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 Saver

Input tokens are spent mostly on reads, not writes. This skill makes reads surgical: locate first, read only what you need, never read the same bytes twice, and keep outputs small. See reference/patterns.md for before/after command examples and scripts/estimate.py to size a file before you touch it.

Procedure

  1. Size before you read. Run scripts/estimate.py on candidate files. It reports lines/bytes/estimated tokens and a read strategy:

    python3 scripts/estimate.py src/app.py logs/server.log --budget 8000

    Pass --json for machine-readable output. With --budget, it warns when a full read would blow the budget. Default heuristic: tokens ≈ chars/4.

  2. Search before read. Never full-file-read to find something. Locate with rg, then read only the matched ranges:

    rg -n "def handle_submit" src/
    sed -n '120,160p' src/app.py        # read only the match window

    For unknown codebases, start with structure, not content: rg -n "^class |^def |^function " beats reading three files.

  3. Head/tail + targeted ranges. For logs: head/tail (errors live at the end, schemas at the start). For code: read imports and signatures first (sed -n '1,40p'), then bodies only where needed. When a read tool supports offset/limit, use it — never open a >400-line file whole.
  4. Diff-first. Before reading both versions of a changed file, run git diff --stat then git diff -- <file>. The diff is the relevant content; reading the pre-image separately doubles cost.
  5. Batch independent calls. Independent reads/searches go in one block. Never do sequential round-trips for things that don't depend on each other:

    # bad:  three round-trips
    read A -> read B -> read C
    # good: one block
    { read A; read B; read C; }
  6. Don't re-read. Record conclusions and path:line refs in session notes, not file contents. Re-read the narrow range only after an edit. If a long output must be referenced again, save it to /tmp and grep the file instead of re-running the command.
  7. Compact outputs. Request terse output from tools (--quiet, --format=short, jq to select fields, | head -n). Produce terse responses: short confirmations, no echo of tool output back to the user, no redundant summaries of what you just did.
  8. Measure the session, not just the read. Run scripts/session_audit.py to see real spend from Claude Code transcripts. Long sessions re-read their whole context every turn — in practice a handful of 300+ turn sessions hold nearly all cache-read tokens. /clear between unrelated tasks; split long work into subagents.

Rules

  • Locate, then read. A grep that costs 50 tokens beats a read that costs 5,000. No exceptions for "just checking".
  • Budget before bulk. Any read estimated >25% of remaining context gets a strategy change (range, grep, or summary), not a bigger read.
  • One read, one purpose. If you're reading to find X, stop at X. Don't finish the file "in case".
  • Logs are tail-first. tail -n 100 before anything else; wc -l decides if the middle matters.
  • Output diet in responses. Terse by default: confirm actions in one line, show only deltas, link files instead of pasting them.

Token economy

One-off need? Skip the skill: python3 scripts/estimate.py --budget <n> <files>. Jump to the one matching section of reference/patterns.md. This skill is the canonical read/search/output reference other skills point at.

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.