Context Management & Reliability
Map for domain D5: how to keep long-running and multi-agent Claude systems accurate, affordable, and robust. Covers context-window sizing, context decay and its fixes (compaction, scratchpads, curation), cost optimisation (caching + batching), compliance (ZDR), overflow behaviour, and reliability patterns (error propagation, confidence-based human review). Weight: ~15% of the scored exam.
Concepts
- Context Windows By Model — 1M (Opus 4.8 / Sonnet 5 / Fable 5, Sonnet 4.6) vs 200k (Haiku 4.5, Sonnet 4.5); what counts toward the window.
- Context Rot — accuracy/recall degrade as tokens grow → curate quality, not just quantity.
- Lost In The Middle — attention strongest at start + end; keep critical constraints in the system prompt.
- Context Awareness — `<budget:token_budget>` + `<system_warning>` injected on Sonnet 5/4.6/4.5 & Haiku 4.5; Opus uses task budgets.
- Server-side Compaction — beta auto-compaction (Opus 4.8/4.7/4.6, Sonnet 5/4.6) + `/compact` + structured summaries.
- Progressive Summarisation Risk — re-summarising summaries compounds detail loss; keep active issue verbatim.
- Scratchpad Pattern — dense `Scratchpad.md` of findings beats raw history in 30+ min sessions.
- Context Engineering — curating/maintaining the optimal token set across turns; prompt engineering is a subset; context = finite "attention budget."
- System Prompt Altitude — the "right altitude"/Goldilocks zone: not too brittle (over-specific), not too vague (over-general).
- Just-in-Time Retrieval — load data on demand via lightweight identifiers (file paths, queries, links) vs pre-loading everything; hybrid strategies.
- Structured Note-Taking — agent writes notes persisted outside the context window and pulls them back later (e.g. `NOTES.md`, to-do list).
- Context Editing — beta `context-management-2025-06-27`, `clear_tool_uses_20250919`; clears oldest tool results (`trigger` 100k / `keep` 3 defaults).
- Memory Tool — `memory_20250818` (GA, no beta header); file-based `/memories`, six client-side commands; pairs with context editing + compaction.
- Prompt Caching — ephemeral only; read 0.1×, write 1.25× (5m) / 2× (1h); min 1024/2048/4096/512 tokens; ≤4 breakpoints; 20-block lookback.
- Caching Plus Batching — stack 50% batch discount + cache; use the **1-hour** TTL with batches.
- ZDR Eligibility — caching qualifies; MCP connector and Batches do **not**.
- Model Lineup And Pricing — IDs/context/price; Opus 4.8 $5/$25, Sonnet 5 $3/$15 (intro $2/$10), Haiku 4.5 $1/$5. ⚠ verify (2026-07-08).
- model_context_window_exceeded behaviour — 400 "prompt is too long" (input overflow) vs graceful stop on 4.5+ (output overflow).
- Error Propagation In Multi-Agent Systems — local recovery, then propagate structured context + partial results.
- Stratified Sampling And Confidence Scores — field-level confidence, >90% auto vs human queue, stratified auditing.
- Tool Context Pruning