agentleFS
trac3r00trac3r00/agent-skills/skills/context-budget/SKILL.md

context-budget

Skill0 starsChanged 3 months agoMITView on GitHub

Audit an AI agent's per-turn context window like a cost center — rank what actually eats tokens (system prompt, skills, memory, tool schemas, gate code) and fail CI when the agent gets fatter. Use when token costs climb on a long-running autonomous agent or you suspect context bloat.

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

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

  • 0

    Common

    Most of the 50 edited versions we read keep these.

  • 3

    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:

    Not for: estimating one user prompt's cost, or counting a single API call.

    line 35
  2. Distinctive:

    Auditing the whole repo: Only files that enter context every turn count.

    line 63
  3. Distinctive:

    Test files and docs you never load are noise here.

    line 64

“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

Measure where an agent's per-turn tokens actually go, then hold the line with a budget.

Overview

Autonomous agents accrete context. One more skill, one more memory note, one more gate module — each cheap alone, together a tax paid on every request. Nobody trims it because there's no ruler. context_budget.py is the ruler: point it at the files loaded into context every turn and it ranks them by token weight, shows each file's share, and returns a non-zero exit code when you blow the budget — so it drops into CI or a pre-commit hook.

Real run against a production agent's gate layer: 214,588 tokens across 83 files, with a single 1,672-line quality gate eating 10.7% of the whole window. You can't fix what you can't see; this makes it visible.

When to use

  • Token/$$ cost is climbing on a long-lived agent and you don't know which part.
  • You want CI to fail the build when the always-loaded context grows past N tokens.
  • You're deciding what to prune and need weights, not vibes.

Not for: estimating one user prompt's cost, or counting a single API call.

The method

  1. Enumerate what loads every turn. System prompt, skills dir, memory files, tool schemas, any gate/middleware code injected into context. These are the paths you audit — not your whole repo.
  2. Run the audit.
    python scripts/context_budget.py \
      ~/.agent/system_prompt.md ~/.agent/skills ~/.agent/memory \
      --budget 40000 --top 15
    Uses tiktoken (cl100k) when installed, else a calibrated chars/4 fallback — never hard-fails on a fresh box.
  3. Read the ranking top-down. The heaviest file is your biggest lever. A 10%-share file is where an hour of trimming pays back on every future request.
  4. Set a budget and wire it into CI. The tool exits non-zero over budget:
    # .github/workflows/context-budget.yml
    - run: python scripts/context_budget.py PATHS --budget 40000
    Now "the agent got fatter" fails the build instead of silently costing money.
  5. Trim the top, re-measure. Move detail to on-demand references, delete stale memory, split a mega-gate. Re-run; the number is the scoreboard.

Anti-patterns

  • Auditing the whole repo. Only files that enter context every turn count. Test files and docs you never load are noise here.
  • Trimming by vibes. Cut the measured top, not the file you happen to dislike.
  • Optimizing away autonomy. For agents that need rich context to act on "just handle it", trim redundancy, not the capability. Weight, then cut carefully.
  • One-and-done. Bloat regrows. The value is the budget in CI, not a single audit.

Example

$ python scripts/context_budget.py ./skills ./memory --budget 20000
   tokens   share  file
    8,928    4.2%  ./skills/deploy/SKILL.md
    5,517    2.6%  ./memory/MEMORY.md
      ...
   34,110  100.0%  TOTAL  (128,402 chars, 41 files)

budget 20,000  [████████████████████████] 171%  → OVER BUDGET
  14,110 tokens over. Heaviest file is 8,928 tok — start there.
$ echo $?
1

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.