agentleFS
RedtropigRedtropig/harness-anchor/skills/context-budget-discipline/SKILL.md

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.

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
  1. Distinctive:

    Default behaviour: don't preemptively load files.

    line 23
  2. Distinctive:

    When context usage > 70% of model window, mid-session compaction can help.

    line 40
  3. Distinctive:

    Flush before you compress: Before compaction/reset — or when the PostToolUse watermark fires (T1 "Context is filling" = flush now.

    line 44
  4. Very specific:

    If compaction isn't enough → use /session-end to write a rich handoff, then suggest the user start a fresh context (context reset > …

    line 49
  5. Distinctive:

    Don't inherit conversational baggage

    line 54
  6. Distinctive:

    Don't dump their working notes into your context

    line 56
  7. Distinctive:

    If you delegate a noisy task, ask for a SUMMARY back, not a transcript.

    line 58
  8. Distinctive:

    When budget pressure rises:

    line 93
  9. Very specific:

    Stop and write handoff: Run /session-end if features are in flight.

    line 95
  10. Very specific:

    Hard-truncate reads: Prefer head -50, grep -A 5, line range in Read tool — over reading whole files.

    line 96
  11. Distinctive:

    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 …

    line 97
  12. Distinctive:

    When the user asks "how much room do we have?", be honest about the estimate.

    line 109

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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 context

SELECT — 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.md or docs/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

TierBudgetSource
Tier 1 (always loaded)~3000 tokens cap; measured at v0.10.0: generic ≈1160 t, C/C++ ≈1580 tSessionStart hook injection (hard-capped 12000 chars, meta-skill injected slimmed; ${CLAUDE_PLUGIN_ROOT}/scripts/measure-context.sh re-measures both baselines)
System prompt + toolsModel-definedOutside your control
Working contextMost of remaining windowYour 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.

FileHot windowSentinel
progress.mdnewest 20 sections64KB
feature_list.jsonlive features + 10 newest pass32KB
golden-rules.mdprune — never archived8KB
AGENTS.mdkeep it a map (~80 lines)8KB
session-handoff.mdoverwritten each session4KB

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:

  1. Stop and write handoff. Run /session-end if features are in flight.
  2. Hard-truncate reads. Prefer head -50, grep -A 5, line range in Read tool — over reading whole files.
  3. 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.
  4. 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 reference
  • feature-state-keeper — what to write to disk
  • project-indexing — TOC as compressed file index

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.