context-window-hygiene
Use when a conversation is getting long and the agent seems to be forgetting earlier instructions, before adding MCP servers or rules files, when deciding whether to clear or compact the chat, or when context window budget feels tight. Covers lost-in-the-middle, clear-vs-compact, and lean-context hygiene.
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 0
- Forks
- 1
01 前言 Front Matter
- name
- context-window-hygiene
- triggers
- [ "user", "model" ]
- description
- Use when a conversation is getting long and the agent seems to be forgetting earlier instructions, before adding MCP servers or rules files, when deciding whether to clear or compact the chat, or when context window budget feels tight. Covers lost-in-the-middle, clear-vs-compact, and lean-context hygiene.
03 SKILL.md 正文
Context Window Hygiene
Core Facts
- 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 limit set by the model provider.
- Hard limit. Each model has a fixed token ceiling (e.g. 200k, 2M). Hit it and the provider errors, or output stops mid-generation.
- Smart zone vs dumb zone. AI-coding workflow guides observe that output quality drops once the active context passes roughly ~100k tokens, regardless of the model's total window. Stay in the smart zone by sizing tasks so the working context stays well below that marker.
- Bigger window ≠ better retrieval. A 10M-token window that cannot find the needle is worse than a 200k window that can. Evaluate retrieval quality, not just size. (Llama 4 Scout: 10M window, severe lost-in-the-middle.)
- Lost in the middle. In long contexts the attention mechanism deprioritizes information in the middle of the conversation. Start (primacy) and end (recency) dominate. Middle detail has weak impact.
When to Use
- Conversation is long and the agent is drifting or ignoring early rules.
- Deciding whether to
clearorcompact. - About to add an MCP server, a large rules file, or paste a huge document.
- Choosing a model by context size.
When NOT to Use
- Context is small and focused - direct work is cheaper.
- You need dense access to early detail - use
context-foldinginstead.
Clear vs Compact
| Action | What it does | When |
|---|---|---|
clear |
Wipes history, blank slate | Default. Task is done or unrelated to prior chat. |
compact |
Summarizes history into a small message | Preserve the vibes/intent of the current task while freeing space. Costs tokens + time to generate the summary. |
Default to clear. Use compact only when continuing the same task and
losing the thread would hurt. Compaction drops detail - it preserves intent,
not facts. If dense access to early context is needed, use context-folding
(offload to file, grep/read on demand) instead of compacting.
Critique of compaction: summaries leave "sediment" (lossy residue that still
occupies attention) and are a worse default than a clean /clear once the
session enters the dumb zone. Treat /compact as an escape hatch, not a
hygiene default.
Lean Context Rules
- Clear chats between unrelated tasks. Refreshes memory, removes lost-in-the-middle noise. A fresh thread outperforms a bloated one.
- Keep rules files small.
.devin/global_rules.md/.devin/rules/*.md/ cursor rules / claude rules are loaded into every conversation. A 25k-token rules file is 12% of a 200k window before you say a word. Compress, modularize into skills, reference instead of inlining. Seewriting-for-agents. - Be paranoid about MCP servers. Each server injects every tool
definition into the system prompt. Two servers can eat a third of the
window before the first message. Audit before adding - use
mcp-context-audit. Keep tool count per server under 10-15. - Don't paste huge documents into chat. Write to a file with
write, thenreadwith offset/limit orgrepto pull only what's needed. This iscontext-foldingat its simplest. - Prefer subagents for parallel exploration. Each subagent has its own
window; only the synthesis returns to the root. 50-100x context savings.
See
dispatching-parallel-agents. - Watch the budget. Run
context-budget.py(SessionStart hook) to see the token cost of.devin/global_rules.md+ loaded rules before working. - Guard against context overflow. If a
tokens-limitor equivalent guard is available, use it. If the active context approaches the threshold, stop the current task,clearorcompact, and restart with a leaner context. Loops without a bound are a cost and correctness risk.
Anti-Patterns
- Keeping one long chat for the whole day. Maximizes lost-in-the-middle.
- Adding MCP servers "just in case." Permanent context tax for unused tools.
- Writing giant rules files. Self-defeating: the rules degrade retrieval of everything else in context.
- Pasting a 500k log into chat. Use a file + grep.
- Compacting when you need the original detail. Compaction is lossy.
- Running unbounded loops. Every iteration burns tokens; cap retries and stop when the context threshold is reached.
Model Selection Heuristic
| Need | Pick |
|---|---|
| Long chat, simple retrieval | Large window with good needle-in-haystack benchmarks |
| Precision on early rules | Smaller window, clear often |
| Huge document analysis | context-folding on any model; don't rely on window size alone |
Source
Distilled from AI-coding workflow guides on context-window hygiene and compaction trade-offs.
Key claims verified against primary sources:
- Lost-in-the-middle: Liu et al. (arXiv:2307.03172).
- Window limits are provider-set and hard: models.dev model cards.
- Compaction is lossy by design: see
context-foldingcomparison table.
If the user asks for current context-window limits or model benchmarks, invoke research to fetch the latest model cards and papers.
04 同仓库更多 Skills
montador-de-ideias
Use when assembling, expanding, or elevating a raw project idea or initial prompt into an ultra-detailed, first-principles dossier and compiled master prompt with journalistic OSINT market research, Tech Lead and Staff Architect justifications, atomic and modular hardening/optimization, and high-impact contact surfaces.
git-github-adaptive-engineering
Use when any task touches git history, GitHub issues/PRs/releases/CI, repo governance, or branch and merge decisions. Runs the Fase Zero situational-awareness battery, picks one of five delivery flows via the adaptive decision engine, and enforces commit/PR information-density standards. Orchestrates the gh, git-workflows, github-actions, pr, and debug/finish skills.
adaptive-agenda-calendar-routine-engine
Use when planning or executing work across hours, days, weeks, or sprints. Turns the calendar into a strict time-blocked agenda (HH:MM-HH:MM blocks carrying a routine profile, expected inputs, and a handoff output artifact), runs the 5-stage cognitive flow (Radar and Hunt -> Triage plus Steve Jobs conception -> workbench manifest -> >=32-cycle loop -> Close plus Open-Minded Scrum), and unfolds macro calendar milestones into micro agenda blocks through extensions/gcal/wrapper.py.
demo
Use when demonstrating a skill in a fixture project.
duplicate-skill
Use when testing duplicate skill name detection.
duplicate-skill
Use when testing duplicate skill name detection.