context-budget-discipline
Skill13 starsChanged 4 months agoMITView on GitHub
Use when sessions run long, adding subagents, fetching large files, or planning context-heavy work. SELECT/WRITE/COMPRESS/ISOLATE discipline.
In this repository14 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- anti-hallucination-gatesSkill
- capturing-golden-rulesSkill
- cpp-build-systemsSkill
- cpp-formattingSkill
- cpp-sanitizersSkill
- cpp-static-analysisSkill
- docs-lookupSkill
- feature-state-keeperSkill
- init-verificationSkill
- project-indexingSkill
- self-correction-loopSkill
- test-coverage-designSkill
- using-harness-anchorSkill
The file
We split this skill into the rules it gives an agent
12 rules. About 0 are common, 9 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈9
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 23
Default behaviour: don't preemptively load files.
- Distinctive: line 40
When context usage > 70% of model window, mid-session compaction can help.
- Distinctive: line 44
Flush before you compress: Before compaction/reset — or when the PostToolUse watermark fires (T1 "Context is filling" = flush now.
- Very specific: line 49
If compaction isn't enough → use /session-end to write a rich handoff, then suggest the user start a fresh context (context reset > …
- Distinctive: line 54
Don't inherit conversational baggage
- Distinctive: line 56
Don't dump their working notes into your context
- Distinctive: line 58
If you delegate a noisy task, ask for a SUMMARY back, not a transcript.
- Distinctive: line 93
When budget pressure rises:
- Very specific: line 95
Stop and write handoff: Run /session-end if features are in flight.
- Very specific: line 96
Hard-truncate reads: Prefer head -50, grep -A 5, line range in Read tool — over reading whole files.
- Distinctive: line 97
Drop tool definitions: If you have many MCP tools loaded and none are relevant to current work, that's overhead — but you can't control …
- Distinctive: line 109
When the user asks "how much room do we have?", be honest about the estimate.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Context Budget Discipline
Context is a finite resource. Every token competes for the model's attention. The "lost-in-the-middle" phenomenon is real — content buried in 50% of the window position is least attended.
This skill applies four operations to keep the budget sane.
The Four Operations
SELECT load context just-in-time, not all-at-once
WRITE persist to disk; let the filesystem remember, not chat
COMPRESS summarize older turns when window fills
ISOLATE delegate so child work doesn't pollute parent contextSELECT — pull, don't push
Default behaviour: don't preemptively load files. Wait until they're needed.
- ❌ "Let me read all 30 .cpp files to understand the project."
- ✅ "I'll consult PROJECT-TOC.md first, then read only the 2 files the task touches."
WRITE — disk is cheap, context is expensive
Anything reusable across turns should live on disk:
- Active feature →
feature_list.json - Decisions / rationale →
progress.mdordocs/decisions/ - "What I just did" →
session-handoff.md
Anti-pattern: re-explaining the same plan/decision in every reply.
COMPRESS — summarize old turns when window pressure rises
When context usage > 70% of model window, mid-session compaction can help. But per Anthropic Nov 2025:
"Compaction preserves continuity, but doesn't give the agent a clean slate. Context anxiety can still persist."
Flush before you compress. Before compaction/reset — or when the PostToolUse watermark fires (T1 "Context is filling" = flush now; T2 "Context is heavily filled" = wrap up via /session-end + fresh session) — write chat-only durable memory to disk first: golden-rule stubs
(capturing-golden-rules), feature status, a milestone progress.md entry. After a compaction,
do NOT backfill memory from the summary: reconstruct from on-disk evidence (git diff, test
output, progress.md) and state uncertainty where evidence is missing.
If compaction isn't enough → use /session-end to write a rich handoff, then suggest the user start a fresh context (context reset > compaction for long runs).
ISOLATE — child work doesn't bleed up
Subagents (/verify, cpp-build-doctor, etc.) run in fresh context. They:
- Don't inherit conversational baggage
- Return a fixed-structure result (diagnosis / evidence / recommendation)
- Don't dump their working notes into your context
If you delegate a noisy task, ask for a SUMMARY back, not a transcript.
Token Budget Reference
| Tier | Budget | Source |
| Tier 1 (always loaded) | ~3000 tokens cap; measured at v0.10.0: generic ≈1160 t, C/C++ ≈1580 t | SessionStart hook injection (hard-capped 12000 chars, meta-skill injected slimmed; ${CLAUDE_PLUGIN_ROOT}/scripts/measure-context.sh re-measures both baselines) |
| System prompt + tools | Model-defined | Outside your control |
| Working context | Most of remaining window | Your edits + reads accumulate here |
State-file budgets
Hot state files carry fixed budgets. The SessionStart banner warns (warn-only) when one is
exceeded; /session-end offers deterministic archival via state-archive.mjs.
| File | Hot window | Sentinel |
progress.md | newest 20 sections | 64KB |
feature_list.json | live features + 10 newest pass | 32KB |
golden-rules.md | prune — never archived | 8KB |
AGENTS.md | keep it a map (~80 lines) | 8KB |
session-handoff.md | overwritten each session | 4KB |
Archives (progress-archive.md, feature_archive.json) are grep-only — never load whole.
When to invoke this skill
- A session has been going for >2 hours
- You notice your replies summarizing already-discussed content (you're losing focus)
- About to read a large file (>500 lines) — ask: do I need ALL of it?
- About to dispatch a subagent — confirm it returns summary, not log
- Context monitor / Claude Code warns about token usage
Practical moves
When budget pressure rises:
- Stop and write handoff. Run
/session-endif features are in flight. - Hard-truncate reads. Prefer
head -50,grep -A 5, line range in Read tool — over reading whole files. - Drop tool definitions. If you have many MCP tools loaded and none are relevant to current work, that's overhead — but you can't control this from inside the session.
- Consider context reset. A fresh session with rich handoff often outperforms continuing a stale one.
Calibrated estimates
You can roughly estimate context use by:
- 1 token ≈ 4 chars (English) or 1-2 chars (Chinese)
- A 200-line code file ≈ 1500-2500 tokens
- A medium SKILL.md ≈ 1000-2000 tokens
- Your own multi-paragraph replies ≈ 200-500 tokens each
When the user asks "how much room do we have?", be honest about the estimate.
Looking up context engineering research
For specific patterns (e.g., compaction algorithms, attention windowing, RAG indexing strategies) — invoke the docs-lookup skill. Pattern names evolve fast in this area; don't rely on memory.
Typical entry query: context engineering 2026 or <specific technique> llm.
Related
using-harness-anchor— Tier 1 injection budget referencefeature-state-keeper— what to write to diskproject-indexing— TOC as compressed file index
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
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.

