context-management
Context Management
Concept of the skill
Context management is the live-session discipline for deciding what evidence enters the agent's active working set, what gets carried only as a handle, what gets distilled, what gets dropped, and what must be preserved so a compacted, restarted, or successor session can continue without re-deriving the decision trail. It treats the context window as finite reasoning attention — not free storage — that degrades through context rot (attention dilution and recall loss as the window fills) and context pollution (irrelevant tool traces, stale logs, and disproven assumptions left active) even while well within the technical token limit.
Coverage
The working discipline that controls what enters, stays in, and exits an active agent session. Intake triage that sorts every candidate context source into four buckets (must-have / useful soon / durable background / noise) before any large file, transcript, tool result, or external page is read. The active-context contract: task, active question, hypothesis, loaded evidence, rejected paths, next verification, and handoff location. The six-step context-management loop: state the active question in one sentence, name the minimum evidence needed to prove or disprove it, load the cheapest source first (index → search → narrow slice), collapse confirmed facts and completed branches into a checkpoint and re-cite it near the recency end when the window has grown long, drop stale or disproven assumptions from the active thread while preserving rejected-path markers, and re-check whether the question changed before reading more.
Working-set shaping rules: what to keep active, what to carry only as an identifier, what to summarize, and what to push out (including raw tool results, subagent reports, and the model's own exposed reasoning traces). The "carry handles until you need payloads" rule for just-in-time loading. The L1–L4 memory-hierarchy analogy for attention cost versus retrieval cost. Stable-prefix ordering for prompt caching: keep durable system / tool / skill / reference material ahead of volatile per-turn conversation, fresh tool results, timestamps, and user-specific payloads when the runtime exposes prompt assembly order. Evidence capsules that preserve source, claim, status, implication, and re-open condition after raw material is dropped, and observation masking for large tool outputs. Distillation patterns for logs, whole files, tool results, exposed reasoning traces, subagent reports, completed debugging branches, long conversations, and multi-page docs. Drift detection signals (re-reading the same source, fix ideas changing every turn, unbounded search, forgotten proofs, repeated paraphrases, contradicted plans, superseded tool results), the four live-window pathologies (poisoning / distraction / confusion / clash), the reset rule for changing active questions, and the reset-threshold signal for when a clean restart beats more distillation. Runtime primitives that support the discipline — compaction, prompt caching / prefix reuse, tool-result or reasoning-block clearing / context editing, session trimming or summarization, memory or progress files, subagents, programmatic tool filtering — with the boundary that none of them replaces agent judgment. The compaction-ready handoff format with its required fields (task / question / hypothesis / proven facts / rejected paths / next step), high-recall-first then precision-tightened writing, durable checkpoint placement, and the under-thirty-seconds resume test. The selective-rebuild recipe for recovery after the thread is lost. A vocabulary bridge that maps this skill's home-grown terms to the industry-standard names (compaction, structured note-taking / agentic memory, just-in-time / progressive-disclosure retrieval, prompt caching, tool-result clearing, observation masking, context isolation) so the discipline travels across vendor docs and runtimes, with an outbound source trail recording the provenance of every web-derived concept carried in.
Philosophy of the skill
Context management is the practical layer between having the right information available somewhere in the workspace and having it active in the agent at the right moment. The goal is not to load more context — it is to keep the smallest working set (the minimal effective context) that still lets the agent act correctly. Without this discipline, agents speculate from stale assumptions, re-read sources they already processed, and lose the decision trail at the moment of compaction. Every context slot occupied by noise is a slot unavailable for the evidence that would actually resolve the current question.
The small-working-set rule is empirical, not aesthetic — it is grounded in how the models behave. Long-context research and current vendor guidance converge on the same operational fact: a larger context window increases what can fit, but it does not make every fitted token equally useful. As input grows, recall and accuracy tend to degrade — non-uniformly, position-dependent, and worse when distractors are present — rather than as a clean monotonic "every fact gets harder" rule. This is now named context rot, observed across the current generation of frontier models, not as a quirk of one vendor. It has three compounding mechanisms: the lost-in-the-middle effect (models attend well to the start and end of context but poorly to the middle), attention dilution (every added token competes for a fixed attention budget), and distractor interference (content semantically similar to the question but irrelevant actively misleads). The practical consequence: a large, mostly-noise window can reason worse than a much smaller window that is all signal. A million-token window is capacity, not permission to flood the session; you cannot reliably prompt your way out of it and a bigger window does not fix it. The smallest high-signal working set is the most durable lever, and it is the lever this skill operates. Treat context as scarce attention, not storage.
The hardest part is not what to load. It is what to drop. Disproven hypotheses, raw logs after the key pattern is extracted, full files after the needed lines are identified, old plans after the question changed, tool outputs after their conclusions are captured, and exposed scratch reasoning after its decisions are captured all continue to steer reasoning until they are deliberately removed or demoted. The working set is what the agent is actively reasoning over, not everything it has ever seen.