context-hygiene
Skill0 starsChanged 4 months agoMITView on GitHub
Use when context is growing large or the agent forgets earlier instructions, when deciding clear vs compact, when processing documents/logs >50k tokens, when monitoring token cost or limiting subagent fan-out, when choosing a reasoning effort level, or when reducing token/compute/MCP costs. Covers lost-in-the-middle, context folding (RLM), cost guards, and difficulty-matched effort.
2 other projects use a version of this.
Adopted by
Most recently taken up by
- getcargohq/cargo-manifesttheir own version, first seen Sep 1, 2026
- wrg32786/aigent-ostheir own version, first seen Jul 19, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- wrg32786/aigent-os★ 19same name
- getcargohq/cargo-manifest★ 10same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository77 other files it gives its agents.
- AGENTS.mdAGENTS.md
- skills/project-bootstrap/templates/agents.mdAGENTS.md
- a11y-auditSkill
- ai3d-genSkill
- ai-coding-dictionarySkill
- ai-toolsSkill
- api-specSkill
- architecture-diagramsSkill
- architectureSkill
- ask-bundleSkill
- bragSkill
- code-reviewSkill
- computer-useSkill
- context7Skill
- creative-engineeringSkill
- cu-realtimeSkill
- data-analystSkill
- databaseSkill
- debuggingSkill
- deploySkill
- devin-configSkill
- dispatching-parallel-agentsSkill
- dockerSkill
- e2e-testingSkill
- executionSkill
- fact-checkSkill
- finishing-a-development-branchSkill
- gatesSkill
- ghSkill
- git-workflowsSkill
- grillingSkill
- handoffSkill
- humanizerSkill
- i18nSkill
- impeccableSkill
- implement-layaSkill
- intakeSkill
- jiraSkill
- knowledge-modelingSkill
- mcp-governanceSkill
- media-toolsSkill
- memory-managementSkill
- mesh-utilsSkill
- observability-qualitySkill
- obsidian-workflowSkill
- operate-blenderSkill
- operate-godotSkill
- performanceSkill
- planningSkill
- playbookSkill
- project-bootstrapSkill
- project-orchestratorSkill
- prompt-compilerSkill
- prototypeSkill
- researchSkill
- scanSkill
- scheduled-turnsSkill
- scrape-toolsSkill
- securitySkill
- self-improvementSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 4 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 27
If dense access to early detail is needed, fold (below) instead.
- Very specific: line 32
Keep rules files small — they load into *every* conversation.
- Very specific: line 37
Don't paste huge documents — write to file, then read offset/limit or grep.
- Distinctive: line 39
Prefer subagents for parallel exploration — each has its own window.
- Distinctive: line 58
Don't fold preemptively, don't dump whole files into context, don't use for simple retrieval (grep is cheaper).
- Distinctive: line 74
Add caching; shorten prompts.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 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 Hygiene
Context window = input + output tokens the model sees at once. Every system prompt, rules file, MCP tool definition, message, and tool result counts against a hard provider-set limit. Output quality degrades past ~100k active tokens ("dumb zone") regardless of total window — lost-in-the-middle means middle detail has weak impact (arXiv:2307.03172). Bigger window ≠ better retrieval.
Default stance: with SWE-2 (262K) most sessions fit — use context directly. Apply the techniques below only when actually needed.
Clear vs Compact
| Action | What it does | When |
clear | Wipes history | Default. Task done or unrelated to prior chat. |
compact | Summarizes history | Same task continues; losing thread would hurt. Lossy — preserves intent, not facts. |
Compaction leaves "sediment" — treat it as escape hatch, not hygiene default. If dense access to early detail is needed, fold (below) instead.
Lean Context Rules
- Clear chats between unrelated tasks.
- Keep rules files small — they load into every conversation. Modularize
into skills; see
writing-skills. - Be paranoid about MCP servers — each injects every tool definition into
the system prompt. Audit with
mcp-governancebefore adding; keep <10-15 tools/server. - Don't paste huge documents — write to file, then
readoffset/limit orgrep. - Prefer subagents for parallel exploration — each has its own window; only synthesis returns (50-100x savings).
- Watch the budget —
context-budget.py(SessionStart hook). - Guard against overflow — unbounded loops are a cost and correctness risk.
Context Folding (RLM-style, for >50k-token artifacts)
Adapted from Recursive Language Models (arXiv:2512.24601): treat context as a variable in an environment — peek, grep, partition, sub-query — instead of reading it all.
Workflow: offload to file → peek (read offset/limit) → grep to
locate → partition (split -l 500) → sub-query chunks with
researcher subagents → verify returns (Rule 12 spot-checks) →
synthesize.
Depth rule (critical): depth=1 only. Subagents must NOT spawn subagents — depth=2 causes overthinking, 95x slower (arXiv:2603.02615).
Don't fold preemptively, don't dump whole files into context, don't use for simple retrieval (grep is cheaper).
Cost Guard
| Limit | Action |
| 1-3 subagents | Default max; >3 requires explicit user approval (enforced by validate-tool-args.py). |
| Loops/retries | Bound every loop; each iteration multiplies cost. |
| Token maxing | Detect effort disproportionate to task difficulty. |
Cost Optimization Protocol
- Measure current cost (tokens/request, model tier, cache hit rate).
- Audit context usage (
mcp-governancefor MCP tool-definition cost). - Right-size effort (see below); paid models only when explicitly approved.
- Add caching; shorten prompts; prefer file snippets over full reads.
- Re-measure; report tokens/cost before and after with commands used.
Code-formatting minification — scoped caution
Stripping non-semantic whitespace cuts input tokens ~24.5% (arXiv:2508.13666, ICSE'26 — Java 33.7% avg; tool: Deblank). Verified but narrow: measured on FIM completion only. Do NOT minify code in agentic/editing flows —
- SWE-bench agents: input −42% but resolution 50%→38% (arXiv:2606.01326).
- Whitespace-preserving rewrites flip predictions up to 60% (TokDrift, arXiv:2510.14972).
- Python: indentation is syntax → ~6.5% gain; minified files break edit-matching, linters, and review.
- Output stays formatted regardless (−2.9%); "emit unformatted" prompting broke Gemini 67%→11% and is model-fragile.
Valid as a per-project rule only when ALL hold: model reads but never edits the code (analysis/completion/RAG input); brace-delimited language (not Python/YAML); a formatter restores output (Deblank pattern — prettier/CI round-trip, disk unchanged); payload is one-shot, not an editing session.
Effort Calibration
Effort is scarce — match to task difficulty. Maps to data/bundle-models.json:
| Level | model_uid | When |
| Medium | swe-2-medium | Simple tasks, spot fixes, isolated scripts, mechanical refactors. Single test/build verifies. |
| High | swe-2-high | Multi-file tasks with clear dependencies. Default. |
| Max | swe-2-max | Open-ended, long-horizon, architecture, novel debugging, or failure at lower effort. |
Rules:
- Improve the spec before raising effort — information quality substitutes for reasoning budget (arXiv:2608.01347).
- Start minimal, expand on failure (E3: Estimate, Execute, Expand — arXiv:2607.13034; 85% cost cut at equal success on simple edits).
- Never start at Max for a task untried at Medium. But don't starve hard tasks — higher effort lifted first-try success 28%→89% on a hard build (arXiv:2607.02436).
- Prompt wording allocates work — "multiple approaches" multiplies reasoning 2.4-7.4× with no success gain; "max certainty" creates verification loops 18× median cost. State WHAT + acceptance criteria.
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.

