agentleFS
fusebase-devfusebase-dev/fusebase-flow/.agents/skills/token-economy/SKILL.md

token-economy

Skill9 starsChanged 28 days agoMITView on GitHub

Use when implementing, debugging, or running long tool-using work sessions, or when the operator asks about "token waste", "session cost", "why is this so expensive", or runs "/token-waste-audit" — delivers FR-26's execution-time economy rules (scoped reads, no re-reads of unchanged in-context files, two-strike retry rule, targeted edits) with their quality guards, plus the measurement path. Do NOT use for app-decomposition token economy (product-apps-decomposition owns that), verification polling economics (smoke-testing § Verification cost discipline owns that), doc budgets (documentation-budget owns that), or to justify skipping needed reads / thinning verification — quality outranks tokens.

4 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

1 rule. 0 are common, 1 is distinctive, and 0 are 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.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Every request re-reads the agent's whole context, so cost grows with context × requests.

    line 59

“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 Economy (FR-26)

Guardrail first (the rule's first clause)

Quality outranks tokens. These rules eliminate REDUNDANT consumption only — never skip a needed first-read, never thin verification, never truncate reasoning. On any conflict, the correctness/safety floor wins (same floor language as FR-21: ceremony drops, safety never). Citing FR-26 to avoid a read or a verification step inverts the rule.

Rules (each with its quality guard)

RuleGuard / carve-outCanonical home (if pointer)
TE-01 · Read-scoped — read the slice that answers the question (offset/limit, grep→targeted read), not the whole file for one factScoped reads are FACT-FINDING; before an EDIT, read enough surrounding context to hold the file's invariants — never grep-and-edit blind—
TE-02 · No re-reads of unchanged in-context files — a file already in context is not read againRe-read REQUIRED after invalidation events: your own Edit/Write, hooks/formatters, parallel/delegated agents, git operations, a failed Edit match, context compaction. Uncertain whether it changed → re-read is the CORRECT spend—
TE-03 · Generated/vendored restraint — never read large generated, vendored, lock, build, cache, or compiled outputsUnless the generated artifact is itself the subject of the task. Shared definition of generated/vendored = policies/module-size.yml: exempt_globs—
TE-04 · Pre-cached identifiers — never re-derive IDs the handoff already carries; verify (one quick read), don't re-discoverStale-looking ID → verify, then surface; don't silently re-derivePOINTER → templates/handoff-implement.md § Pre-cached identifiers
TE-05 · Two-strike rule — the same failing approach is not attempted a third time"Same approach" = same action, same inputs, expecting a different result. NOT strikes: FR-10 3/3 reproduction runs, test reruns after a real change, bounded labeled flaky-external retries, a delegate re-dispatch inside the bounded delegate-retry envelope (flow-skills/liveness-discipline) — the approach was never executed. On 2 strikes → diagnose via zoom-out (FR-20) + validation-and-qa (FR-10)—
TE-06 · Targeted edits over whole-file rewrites — patch the changed region; don't regenerate the file. This holds for an FR-18 supersede too: supersede replaces stale semantics, not the file — targeted Edit when most sections are unchangedA full Write is the CORRECT primitive (not waste) for structure/mode/ticket changes or when most sections changed — FR-18 mandates the replaced semantics, never the rewrite toolflow-skills/role-discipline/SKILL.md § Supersede Convention
TE-07 · Pointers over reprints / reference-once — in chat and handoffs cite the artifact path, don't repaste its body; once a large body (big tool result, log, JSON, file region) is in context, later turns refer to it by its retrieval handle (path+window, request ID, report path, test name) instead of re-sending itA fresh first inclusion, or a deliberately re-run command's NEW output, is not a re-send; never drop a decision, ID, or evidence the next step needs. Doc-side rule is FR-23 (pointers over restatement)flow-skills/documentation-budget/SKILL.md
TE-08 · Record-then-read — read durable evidence once after the run instead of agent-side pollingExactly two bounded, labeled exceptions: the first live drive of fresh code, and delegate-PROGRESS polling under the bounded delegate-retry envelope (3 attempts / 5 min / one progress read per interval — a delegate that never started leaves no record to read). A liveness check (one SHA, mtime or byte-count read at the liveness-discipline § Wake interval) reads no evidence and is not pollingPOINTER → flow-skills/smoke-testing/SKILL.md § Verification cost discipline · flow-skills/liveness-discipline/SKILL.md § Bounded delegate-retry envelope
TE-09 · Delegation economics — delegate only when the sub-agent's context floor costs less than the tokens the split saves. Floor: ~40–80k tokens on its first request (platform prompt, tools, skill listing, instructions; p10–p90, 2026-10) plus what it must re-read. A reused worker re-reads nothing but pays its whole context on every request: at ~300k a fresh successor is cheaper once the remaining work exceeds ~30 requests, at ~500k ~13Bounded, disjoint slices only; the reuse bound is task-delegation § Correction ownershipflow-skills/task-delegation/SKILL.md

Context compression discipline

Extends FR-26 to large context and large output — when the input or a tool result is big enough that loading it whole is itself the waste. This is read-time and reasoning-time routing, not a budget: it slices and points to large artifacts and keeps compressed context honest. It never authorizes skipping a needed read or thinning verification — the Guardrail still governs.

RuleGuard / what it must never become
TE-10 · Content-route before consuming — classify a large input (code, log, JSON, test output, diff, markdown, prose, transcript, generated/vendored output, binary/asset metadata) before deciding how much of it to readRouting decides depth, never whether to verify; an authoritative artifact still gets read in full when the task needs its invariants
TE-11 · Extract before reasoning — for large logs, test output, JSON, traces, transcripts, and search results, pull the relevant slice or a summary first instead of loading the whole body into reasoning contextThe slice is for triage; if it is ambiguous or the decision is load-bearing, widen it or open the source
TE-12 · Preserve the retrieval path — every summary or compressed note carries a handle to reopen the original: source path, command, report path, line/window pointer, request ID, or test nameA note with no retrieval handle is a dead end — you must always be able to get back to ground truth
TE-13 · Original-before-edit — before editing code, changing product logic, approving acceptance criteria, deciding security / billing / permissions / client-data, or closing verification, reopen and read the authoritative sourceA summary may point you AT the change; it never substitutes for reading the file you are about to edit or approve
TE-14 · Summary is not authority — compressed/summarized context is for exploration and triageNEVER the sole basis for implementation, security, permissions, billing, migrations, compliance, public API contracts, client-data access, or acceptance criteria — those decide against the original
TE-15 · Stable context floor — don't rewrite always-on rules, agent files, command files, handoffs, or governance docs just to improve phrasingA small, stable instruction surface is cheaper every session than a "better-worded" one; governance edits are explicit, reviewed, diff-based tickets — never an optimization side effect
TE-16 · Cross-agent dedupe — handoffs between PO, AI Developer, Architect, Deploy, QA, and other roles carry decisions, IDs, paths, and pointers, not duplicated full artifactsDedupe never drops a decision or an ID the next role needs; every pointer must resolve
TE-17 · Large-output hygiene (anticipate, then narrow) — when a command's output is plausibly large or unbounded (full logs, whole-tree listings, unfiltered queries/dumps), scope the FIRST invocation — limit/offset, tail, grep/jq, targeted test, shorter traceback, or write-to-report-then-read — rather than running it wide and narrowing only on the rerunScoping serves the question; never scope so tight that needed evidence is excluded, and an estimated size is never a hard cap or a reason to skip a needed read
TE-18 · Compression is not verification — never use compression/summarization to skip reproduction, skip smoke tests, thin acceptance evidence, or hide uncertaintyQuality outranks tokens — on any conflict the correctness/safety floor wins, exactly as in the Guardrail

Generated/vendored restraint and reference-once live in the Rules table as TE-03 / TE-07 — one canonical row each.

Residency and cache lifetime

Every request re-reads the agent's whole context, so cost grows with context × requests; a context idle past its cache lifetime is re-written in full on the next request. Like § Context compression discipline this is routing, not a budget — the Guardrail governs.

RuleGuard / what it must never become
TE-19 · Bounded residency — plan each delegated slice to finish in about 50 tool calls or fewer (sub-agent context passes ~300k near 50 tool uses and ~500k near 65–90; three consumer runs, 2026-10); split larger work into sequential task groups, each a fresh worker that resumes from records (task-delegation successor contract); the main session offers rotation at milestones (FR-17)A size is a plan-time split and a rotation point, never truncation: a worker past it finishes its slice and the NEXT group starts fresh. Never split below one coherent, independently verifiable task. Sizing applies to work already eligible for delegation (task-delegation §§1–4) — it is never a reason to delegate
TE-20 · Wait under the cache TTL — a waiting agent wakes on events (a bounded watcher that exits on progress, completion or stall) or checks at most every 4 min: sub-agents run on a 5-min cache TTL (main sessions: 1h on a Claude Code subscription, 5 min elsewhere). A check re-reads the cached context at the model's cache-read rate (Opus 5.5 0.05×; Opus 5, Sonnet 5, Haiku 4.5 0.1×; Fable 5.1 0.025× of input — rate card in hooks/local/token_waste_audit/costing.py); letting it expire re-writes all of it at 1.25× (2× on 1h)Liveness first: never stretch an interval past the stall bound to save tokens (FR-27). A wait expected beyond the break-even (where 4-min checks out-cost one 5-min-TTL re-write: 4 min × 1.25 ÷ read rate — ~100 min at 0.05×, ~50 min at 0.1×, ~200 min at 0.025×) → record-then-read (TE-08) or BLOCKED-AT-<gate>; liveness checks continue by watcher; never one sleep longer than the TTL at large context — wait on a file with bounded_wait (hooks/local/lib/bounded-run.sh; 230 s cap, tool timeout ≥240 s). Canonical intervals and watcher: liveness-discipline § Wake interval
TE-21 · Image residency — an image read into context is re-sent on every later request of that agent: compare screenshots by script (pixel/DOM diff → text report) and read only the captures it flags, once each unless re-captured; crop to the region in question; one bounded agent per screen group (TE-19)The script narrows WHICH images are viewed, never replaces viewing one the verdict rests on; smoke PASS evidence rules are unchanged (smoke-testing)

Fusebase-CLI grounding — known large-output surfaces (TE-17 instances)

Pre-identified so the FIRST invocation is scoped — not the rerun. /token-waste-audit's large-output class flags results ≥20k chars from these surfaces; cite the TE ID in fixes.

SurfaceCharacteristic sizeScope the FIRST invocation
fusebase remote-logs runtime <appId>up to 300 entries × long lines (default 100)--tail 50 first; add --type system / --container <name> when the symptom names a layer; widen only if the slice misses the event
fusebase remote-logs build <appId>full cloud build logfetch once, read tail-first for the failing step; grep the captured output rather than re-fetching
Local dev logs <app-dir>/logs/dev-<timestamp>/ (dev-debug-logs)one file per source, whole sessionpick the ONE file the symptom maps to per the dev-debug-logs routing table, grep→targeted read; never cat the whole session dir
MCP dashboard payloads (getDashboardViewData, schema/prompt dumps — fusebase-dashboards)full row sets / whole schemapass filters + limits in the call; prompts_search with narrow groups; never pull all rows to answer a one-row question
Gate MCP discovery / org user listing (fusebase-gate)full org/contract listingsscope to the user/contract in question; record-then-read (TE-08) for repeated checks

Guard: scoping serves the question — never exclude the evidence the diagnosis needs (TE-17's guard governs). Surface names/flags track the vendored CLI provider skills; on a FuseBase CLI refresh, re-check this table against remote-logs / dev-debug-logs / fusebase-dashboards / fusebase-gate skills.

Measure it

Claude Code measurementContract
Invocation/token-waste-audit (.claude/commands/token-waste-audit.md) or python hooks/local/token-waste-audit.py [--last N] [--dir PATH] [--main-only]; stdlib-only
Scope--last N selects top-level sessions by modification time; each brings <sid>/subagents/agent-*.jsonl and <sid>/subagents/workflows/wf_*/agent-*.jsonl; journal.jsonl excluded. --main-only reproduces the old main-session scope
TotalsLast usage per requestId; main row + sub-agent aggregate (agents, workflows, requests, output, cache read/creation); top-10 agents by cache read, with workflow id; findings run per transcript and name the originating agent
Cost attribution (first)Main/sub-agent × cache read, cache write 5m/1h, uncached input, output; each request uses its message.model and the dated rate table in hooks/local/token_waste_audit/costing.py. List-price estimate (rates as of 2026-10); subscription billing differs. Unknown/<synthetic> models remain in tokens, excluded from USD with an unpriced-request line; unsplit creation priced at 5m
Context residencyContext = cache read + cache creation + input per request; peak/average/requests + compactions (compact_boundary only); top-10 transcripts by cache-read cost. One session-level context-residency signal when transcripts peaking ≥500k hold ≥50% of session cache-read cost; maps to TE-19 (bounded task groups) and FR-17 rotation
Cache rewrite / polling costcache-rewrite: start-to-start gap in the same transcript > explicit creation TTL (1h if its split >0, otherwise 5m if >0; unknown skipped) and creation ≥100k; maps to TE-20. Full count/tokens/USD split main/sub-agents. One line per session, Sub-agent rewrites at 5-60 min gaps: 5m-TTL rewrites after ≤60 min, each capped at the prefix cached before the gap (prior request's read + creation, less its own read; new-turn tokens are written under either TTL), ÷ all sub-agent cache writes, beside the 1h-TTL break-even 0.75/(2 - r) (r = the model's cache-read ÷ input; ~38.5% at 0.05×, ~39.5% at 0.1×, ~38.0% at 0.025×; counts the reads that replace avoided writes), or a cost-weighted 1h-vs-5m USD comparison when several priced models mix; a lower bound (rewrites <100k excluded). Polling: requests issuing the repeated command after the first issue (wakes), context sum × each request's cache-read rate. A request starts at its preceding user/tool_result line, else its first streamed line
Advisor callsserver_tool_use blocks named advisor counted; usage.iterations entries of type advisor_message (top-level usage omits them) kept once per request, priced at the iteration's own model and added as an advisor row per scope in Cost attribution and its totals; unknown model → unpriced line. Wait = call line → its advisor_tool_result line (observed on one transcript shape)
Wall time§ Wall time (FR-27 lens; candidates, not verdicts): tool_use → tool_result spans ≥10 min; Bash/PowerShell = stall candidate (FR-27, liveness-discipline), Task/Agent/advisor = delegation wait, other tools = tool wait; top 10 per class per session; never a hang verdict
Ranking / session capLive rows sorted by USD (unpriced last), each marked observed (recorded usage × list price: cache-rewrite, context-residency) or estimated (payload chars ÷ 4, context × cache-read rate); text/image payload estimates use request input rates, rewrite payload estimates use output rates. Estimates overlap and are not avoidable-spend totals. large-output, repeat-output, cache-rewrite: top 10 each across main + agents per session, with "N more suppressed (session cap)"; other classes retained in full
Text findingsIdentical-window Reads ≥3×; polling-shaped Bash repeats; large rewrites of pre-existing paths; large-output ≥20k text chars from output-producing built-in/MCP tools (write tools excluded); repeat-output identical large text bodies ≥2×; top-10 text results
ImagesSeparate image count and token estimate: PNG IHDR / JPEG SOFn dimensions, long edge scaled to ≤1568 px, ≈width×height/750; unknown dimensions = 1600. Base64 excluded from text sizes, large-output and repeat-output
image-rereadIdentical image bytes ≥2× in one transcript → TE-21/TE-02 candidate; same path with changed bytes = re-capture, not image re-read
Privacy / interpretationNo message/thinking/tool-result text, image data or hook output in reports; attachment lines excluded. Paths keep head…tail; commands keep head truncation. Candidates MAY indicate the cited TE rule; report header lists false positives. context-residency / cache-rewrite are cost signals, not proof that the work was unnecessary
Outputstate/audit/token-waste-audit-<date>.md (gitignored)
Operator lever (Claude Code; documented, not defaulted)WhenNote
Continue from the handoff in a fresh sessionreturning after more than ~1 h awaythe first request after the main session's 1h TTL re-writes its whole context anyway; a fresh session writes only the floor + handoff (FR-17 rotation)
autoCompactWindow / CLAUDE_CODE_AUTO_COMPACT_WINDOW (100k–1M; the env var takes a plain integer such as 500000)the main transcript's row in § Context residency peaks ≥500kcompacts earlier — a compaction point, never a cap on the work; effect on sub-agents unverified
Main-session wake interval up to 15 mincache-rewrite rows show the main session on 1h; the operator says so in chatsub-agents stay at ≤4 min (liveness-discipline § Wake interval)
1h cache TTL for sub-agents (subagentPromptCacheTtl: 1h; Claude Code v2.1.242+; covers Agent-tool sub-agents and Workflow agents)waits already wake by watcher, bounded_wait or ≤4-min checks (TE-20), and the audit's Sub-agent rewrites at 5-60 min gaps line still puts R of W sub-agent cache-write tokens above about 38-40% (R/W > 0.75/(2-r))every write then costs 2× instead of 1.25×, and each avoided re-write is read at r (the model's cache-read ÷ input), so it pays only when 1.25W > 2(W - R) + rR; with mixed models the line's cost-weighted 1h-vs-5m comparison decides; fix waits first; check intervals stay ≤4 min (TE-20 guard)
  • Auto-classification is labeled, never silent (--probe-command CMD adds this ticket's documented gate probes, repeatable). Two conjunctive rules only: growing-source-tail (same full read key and monotonic growth or all-differing digests and no contradictory event — an intervening write to that path, a compaction between the reads, or an error-shaped result keeps it live; a size-difference-only re-read stays live) and possible-FR-10-triple (exactly-3 runs are labeled; dismissed only when the command is probe-shaped — a test runner, --dry-run, or a health/status/version verb — because three failed retries and three polls are count-identical to a reproduction triple; the count is runs since the last write, not truly consecutive). Every dismissal prints the rule that fired and its evidence, and is counted in a section separate from live findings. The run names one of four terminal states in words — candidates found · all auto-classified · no candidates above thresholds · no transcripts/parse failure. Silence is never proof of cleanliness.
  • Other surfaces (Codex / Cursor / Copilot / Gemini): transcript metrics are unavailable — say so explicitly ("transcript metrics unavailable on this surface") and degrade to the repo-side summary the parser also produces: largest tracked source files, docs/tmp/handoff.md size, optional bash hooks/local/check-module-size.sh --all. Never fabricate transcript numbers.

Growth rule

A waste pattern that recurs across audits and matches no row above → add one rule row (with its quality guard and the next free TE-xx ID — IDs are append-only, never renumbered: audit reports and problem-catalog entries cite them) via skill-authoring. This includes recurring large-output / large-context patterns surfaced by the large-output audit class — add the row clean-room and dependency-free (never reach for a third-party compression tool). Project-specific waste patterns stay in project docs/skills, not here unless they generalize across Flow use cases.

Anti-patterns

  • Citing FR-26 to skip a needed first-read, a reproduction run, or a verification step — that inverts the guardrail; the correctness/safety floor wins.
  • Treating audit findings as verdicts. They are candidates: a warranted FR-18 full-Write supersede (structure/mode/ticket change, or most sections changed), mirror regeneration, and deliberate FR-10 reproduction look identical to waste in the metrics.
  • Hard token budgets, caps, or gates on token counts — a budget gate trains truncation (intelligence damage); FR-26 is deliberately write-time discipline + retrospective audit only.
  • Grep-and-edit blind: editing a file whose invariants you never read because "scoped reads are cheaper".
  • Treating a summary as the source of truth for a final edit or an approval — the original is reopened first (§ Context compression discipline).
  • Compressing away the evidence verification needs — reproduction runs, smoke output, acceptance evidence, or a stated uncertainty.
  • Using token economy as an excuse to avoid opening the authoritative file before deciding.
  • Adding a third-party compression dependency to Flow core — FR-26 economy is behavioral discipline + a deterministic stdlib audit, not a tool to install.
  • Copying a third-party compression implementation, prompt, or doc into Flow — canonical Flow content is clean-room original.
  • Rewriting always-on / governance files for cosmetic phrasing under the banner of "optimization" — governance edits are explicit, reviewed, diff-based.

Clean-room note

Original Fusebase Flow content. Designed after reviewing public AI coding workflow patterns; no third-party code, prompts, skill files, or hook scripts are copied. See docs/source-map.md.

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.