agentleFS
gg2762gg2762/Claude-Code-Skill-Architecture-and-Token-Management/skills/context-budget/SKILL.md

context-budget

Skill2 starsChanged 5 months agoMITView on GitHub

Use to audit and reduce a Claude Code agent's context. Invoke when the user mentions context optimization, token budget, "why is my agent slow/sloppy", bloated CLAUDE.md, memory cleanup, context rot, or wants to know how much is loaded every turn. Measures always-on vs on-demand context, classifies knowledge as story/rule/procedure, and recommends what to relocate, gate, or cut.

54 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use agent-payment-x402, openclaw-persona-forge and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • TironFoxSkill

    agent-payment-x402

    Add x402 payment execution to AI agents — per-task budgets, spending controls, and non-custodial wallets via MCP tools. Use when agents need to pay for APIs, services, or other agents.

    Also in 6 projects that use this

  • TironFoxSkill

    openclaw-persona-forge

    为 OpenClaw AI Agent 锻造完整的龙虾灵魂方案。根据用户偏好或随机抽卡, 输出身份定位、灵魂描述(SOUL.md)、角色化底线规则、名字和头像生图提示词。 如当前环境提供已审核的生图 skill,可自动生成统一风格头像图片。 当用户需要创建、设计或定制 OpenClaw 龙虾灵魂时使用。 不适用于:微调已有 SOUL.md、非 OpenClaw 平台的角色设计、纯工具型无性格 Agent。 触发词:龙虾灵魂、虾魂、OpenClaw 灵魂、养虾灵魂、龙虾角色、龙虾定位、 龙虾剧本杀角色、龙虾游戏角色、龙虾 NPC、龙虾性格、龙虾背景故事、 lobster soul、lobster character、抽卡、随机龙虾、龙虾 SOUL、gacha。

    Also in 5 projects that use this

  • loulanyueSkill

    nuxt4-patterns

    Nuxt 4 app patterns for hydration safety, performance, route rules, lazy loading, and SSR-safe data fetching with useFetch and useAsyncData.

    Also in 9 projects that use this

  • renepfSkill

    orch-pipeline

    Shared orchestration engine for the orch-* skill family. Defines the gated Research-Plan-TDD-Review-Commit pipeline, the size classifier, the agent map, and the two human gates that the orch-* operation skills delegate to. Not usually invoked directly.

    Also in 4 projects that use this

  • Exploration-labsSkill

    token-budget-advisor

    Proactive token budget assessment and task chunking strategy. Use this skill when queries involve multiple large file uploads, requests for comprehensive multi-document analysis, complex multi-step workflows with heavy research (10+ tool calls), phrases like "complete analysis", "full audit", "thorough review", "deep dive", or tasks combining extensive research with large output artifacts. This skill helps assess token consumption risk early and recommend chunking strategies before beginning work.

    Also in 11 projects that use this

  • loulanyueSkill

    santa-method

    Multi-agent adversarial verification with convergence loop. Two independent review agents must both pass before output ships.

    Also in 8 projects that use this

The file

We split this skill into the rules it gives an agent

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

  • 0

    Common

    Most of the 50 edited versions we read keep these.

  • 2

    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:

    Keep large reference docs out of the index — they should be path-read on demand, not auto-recalled.

    line 46
  2. Distinctive:

    Verify the index has no broken links and no dangling path references after any move.

    line 47

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

Context Budget

A meta-skill for keeping a Claude Code setup lean. The goal is not "less knowledge" — it's getting the right context in front of the agent at the right time.

Core model: two load tiers

TierWhat loadsWhenCost
Always-onaccount + project CLAUDE.md, the memory index (MEMORY.md), and every skill's frontmatter/descriptionEvery turnPermanent tax — protect this budget
On-demanda skill's full body, nested skill files, individual memory filesOnly when invoked / recalledCheap — load freely

The waste is almost always concentrated in the always-on tier. Most setups carry a large always-on CLAUDE.md that is mostly derivable-from-code or historical changelog.

Step 1 — Measure

Run the report:

bash scripts/context-report.sh /path/to/project   # defaults to $PWD

It prints always-on vs on-demand totals (words + approximate tokens) and the always-on share of the stack. Treat the always-on number as the metric to drive down.

Step 2 — Classify every piece of knowledge

For anything you're tempted to keep always-on, decide what it is:

  • Story — a one-time retrospective ("we tried X, it broke"). Keep in an archive/log. Useless as a live instruction. Loads on demand only.
  • Rule — a durable prescription ("always do X"). Make it a short, indexed memory so it auto-recalls.
  • Procedure — a repeatable checklist ("when touching Y, run these steps"). Wire it into the relevant skill so it fires at the moment of work — not a hope-it-gets-read doc.

Most teams write everything as stories and never convert them. That's why documented lessons keep getting violated.

Step 3 — The always-on admission test

A line earns always-on space only if all three hold:

  1. Not derivable from code (the agent can read package.json, migrations, configs).
  2. Broad (relevant across many tasks, not one narrow domain).
  3. Stable (a durable rule, not a dated changelog entry). Fail any → relocate to an on-demand reference doc or a skill.

Step 4 — Gate recurring failures

If a class of bug keeps recurring, the fix is almost never "write it down again" — it's already written somewhere. Convert it into a preflight checklist inside the skill that does the risky work, with an explicit "before you mark this done, run these checks" gate. Passive knowledge → active gate.

Step 5 — Memory hygiene

  • One canonical memory dir per project (Claude Code keys it by working directory). Split dirs fragment recall.
  • Keep large reference docs out of the index — they should be path-read on demand, not auto-recalled.
  • Verify the index has no broken links and no dangling path references after any move.

What this does NOT do

  • It does not shrink your knowledge base — it relocates load from always-on to on-demand. The total stack stays roughly the same; the per-turn tax drops.
  • Token counts are approximate (words × 1.33). For exact figures, use a real tokenizer.
  • The loading model is Claude-Code-specific; the method (tiers, story/rule/procedure, gating) transfers to other agents.

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.