Context management shapes the information an LLM receives for a model call. It assembles and maintains a relevant working context from instructions, external knowledge, tools, memory, state, and the user prompt. Context orchestration is distinct: it routes context across steps, agents, tools, and interfaces. section 1.1.2 section 7.0
A model’s context window imposes a hard token ceiling, while an application may set a lower budget to control cost and latency. Extra content can also dilute the salience of critical instructions, evidence, and state. The goal is a task-aligned context that uses these limited resources economically. section 7.1
Four complementary operations shape the working context:
- Selection retrieves, filters, prioritizes, and places task-relevant instructions, evidence, state, and user intent. section 1.1.2 section 7.10
- Writing preserves useful information in files, external stores, or scratchpads so it can be read back when needed. section 7.10
- Compression reduces history through summarization, trimming, or observation masking while retaining task-critical detail. section 7.10
- Isolation separates subtasks, authority levels, tools, or evidence streams into bounded contexts using subagents, state partitioning, or sandboxes. section 7.10
Figure 7.1 Context is managed through four complementary techniques: selection chooses relevant tokens for the active prompt, writing persists state to external storage, compression condenses verbose history, and isolation divides complex tasks across separate context windows
The diagram relates the four operations to their roles in managing the active context window. section 7.1
Managing a coding session
A long coding session can accumulate files, logs, tool outputs, and plans. Claude’s context editing clears stale tool calls and results near token limits; compaction summarizes the interaction while preserving decisions, unresolved bugs, and implementation details. Auto memory keeps reusable information outside the window for later recovery. OpenCode provides another approach: project instructions, targeted file inclusion, automatic compaction, and pruning older tool outputs. section 11.3.8
Framework abstractions can assemble and transform context, but layering templates, retrieval, memory, and tools can obscure the source of a wrong answer. Keep context construction explicit enough to inspect, test, and debug. section 10.3


