liveBook · Manning

Context management

As explained in Context Engineering

Context management is the shaping of context through selecting, writing, compressing, and isolating information before model consumption.

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
context management v6

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

How Context Engineering covers it

How deep it goes
Defines four complementary operations and their resource constraints, then illustrates implementations in coding agents.
Examples
Illustrates context editing and memory in Claude, project instructions and compaction in OpenCode, and repository maps in Aider.
What you can do after
Operate and configure OpenCode context inputs using instruction sources and targeted file inclusion.
How it connects
Connects context management to retrieval, memory, context orchestration, and multi-agent systems.

Also explained in

Compare how 3 books explain context management →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Context Engineering. The section links point to the parts of the book it draws on.