Context budget
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.From its SKILL.md
npx -y skills add trac3r00/agent-guards --skill context-budgetAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 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 file declares
Copied from the file, not written here
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, 819 tokens by cl100k_base, 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
- 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.
- Run the audit.
Usespython scripts/context_budget.py \ ~/.agent/system_prompt.md ~/.agent/skills ~/.agent/memory \ --budget 40000 --top 15tiktoken(cl100k) when installed, else a calibrated chars/4 fallback — never hard-fails on a fresh box. - 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.
- Set a budget and wire it into CI. The tool exits non-zero over budget:
Now "the agent got fatter" fails the build instead of silently costing money.# .github/workflows/context-budget.yml - run: python scripts/context_budget.py PATHS --budget 40000 - 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
What ships with it: 1 file
6.3 KB alongside SKILL.md, 1 of them executable
scripts/
- context_budget.pyruns6.3 KB
Gives 0 of the 12 instructions most memory context skills give in 819 tokens
Counted across 754 of the 1,056 authors here whose files we hold, read 2026-09-06
- Preserve existing content structurein 15 of 754, across 9 files
- Front-load the leading wordin 14 of 754, across 10 files
- Update existing entries instead of duplicatingin 14 of 754, across 7 files
- Keep CLAUDE.md under one hundred linesin 14 of 754, across 12 files
- Read CLAUDE.md at the project rootin 14 of 754
- Keep each meaning in a single source of truthin 12 of 754, across 8 files
- Redact sensitive information before committingin 11 of 754, across 4 files
- Scan for all CLAUDE.md filesin 11 of 754, across 7 files
- Use frontmatter for metadata on filesin 10 of 754, across 3 files
- Repeat user interactions 10 timesin 10 of 754, across 4 files
- Write the CLAUDE.md file into the target folderin 10 of 754, across 8 files
- Use memlab to process snapshotsin 9 of 754, across 3 files
Said here and by no other author read
- Enumerate files that load every turn
- Run the audit script with paths and budget
- Read the ranking top down
- Set a budget and wire it into CI
- Trim the top and re-measure
Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once. Length counted with cl100k_base; the agent that loads this file may tokenize it differently.