agentsclimarketplace

Context budget

Skill trac3r00/agent-guards/skills/context-budget

Agent Guards for long-lived AI agents: context-budget (audit per-turn token weight, fail CI on bloat) + claim-audit (flag unverified factual claims). Standalone tools + CI-ready, Claude Code / Codex / OpenCode compatible.

Install
npx -y skills add trac3r00/agent-guards --skill context-budget

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • 29 days oldThe repository was created 29 days ago. New is not bad, but a brand new repository carrying a familiar-sounding name is the shape a typosquat arrives in, and there has been no time for anyone else to find a problem with it.
  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

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.

The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

3.8 KB, as published. Nobody here has run it

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

Gives 0 of the 12 instructions most memory context skills give

Counted across 674 of the 847 authors here whose files we hold, read 2026-08-06

  • inform the user when setup is completein 21 of 674, across 6 files
  • confirm the draft with the user before writingin 21 of 674, across 6 files
  • update the agent skills block in place if it existsin 21 of 674, across 6 files
  • present findings to the userin 20 of 674, across 5 files
  • write the three docs files from seed templatesin 20 of 674, across 5 files
  • ask the user about each decision one at a timein 19 of 674, across 4 files
  • edit CLAUDE.md if it existsin 18 of 674, across 3 files
  • explore current repo statein 18 of 674, across 3 files
  • do not overwrite user edits to surrounding sectionsin 18 of 674, across 3 files
  • back up the original file before overwritingin 16 of 674, across 8 files
  • keep the memory index under 200 linesin 15 of 674
  • Provide actionable steps and verificationin 13 of 674, across 2 files

Said here and by no other author read

  • enumerate files loaded into context every turn
  • run the token audit script
  • read the token ranking top-down
  • set a token budget
  • wire the token budget check into CI
  • trim the heaviest files

Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.