What you need to know
Context is a budget. As it fills with old tool output and abandoned ideas, the instructions and decisions that matter carry less weight, and behavior drifts well before the window is full.
Signs
- Re-reading files or re-running searches already done.
- Contradicting a constraint set early in the session.
- Following a pattern that was rejected an hour ago.
- Slower replies and rising cost per turn.
/context in Claude Code (or token counts in your own harness) shows what fills the window.
Techniques
| Technique | What it does | Use when |
|---|---|---|
| Tool-output pruning (context editing) | Removes old tool results, keeps the conversation | Stale logs, dumps or file contents crowd the context |
| Compaction | Replaces history with a summary | Continuing the same long task; tell it what to keep |
| Subagent isolation | Bulky side work happens in a separate context; only findings return | Research, large reviews, reading many pages |
| Persistent notes | Decisions, constraints and progress live in a file or the system prompt | Anything that must survive compaction or sessions |
| Response shaping | Tools return only relevant rows and fields, with paging | Prevent bloat at the source |
| Fresh session | Start clean, carrying a short summary if needed | The task changes, or accumulated context misleads |
Choosing between compact and clear
- Same task, still needed: compact (with "keep the approved pattern and the failing tests").
- New, unrelated task: clear or start a new session.
- Drift from conflicting material: compact with instructions to drop the rejected option, and record the decision where it persists.
Re-fetch, do not guess
When old tool results are cleared, the agent can call the tool again. Design for that (or keep key values in state); never let it guess a cleared value.
In the exam
Items describe a long-running session or agent that has drifted or slowed, and ask which technique restores intended behavior or when to start fresh. Match the cause to the technique. Distractors raise the window or max_tokens, repeat instructions in every message, compact constantly, or never compact at all.
Check your understanding
A debugging agent's context is 85% stale stack traces; its hypothesis still matters. What first?
Show answer
Answer: A. Remove what is stale and keep the reasoning state.
After compaction, an agent forgets a naming convention the user gave early. Fix?
Show answer
Answer: C. Compaction can drop early details; standing rules need a persistent home.
A feature is done and an unrelated bug fix is next. How to begin?
Show answer
Answer: D. Unrelated history only adds noise to the new task.
Apply it: Keep Bluestem's underwriting agent on track
Bluestem's underwriting agent reads up to 40 documents per application. By the end, its context holds every document's full text and every credit-bureau response; memos start missing a rule the underwriter gave at the start ("exclude intercompany transfers from revenue"), and it sometimes re-reads documents.
- Redesign the reading step so bulk stays out of the main context.
- Protect the underwriter's rule.
- Decide what to prune and when.
Done when: the main context holds decisions and findings, not raw documents.
Show model answer
1. A reading subagent per document type (bank statements, tax returns, invoices) with read-only tools, each returning structured findings (period, revenue, flags) instead of text.
2. Store underwriter instructions in a notes file that the harness injects into the system prompt for that application; record them as "rules for this application" so compaction cannot drop them.
3. Clear credit-bureau responses once their key figures are in the findings; compact at about 60% context use with "keep rules, findings and open questions"; the agent can re-run a lookup if it needs a cleared value.