Study guide

6.1 Context, Caching, and Compaction

Claude Certified Architect - Foundations Study Guide Exam

Track your progress as you read

Finished sections get a check mark.

1 Chapter 1: Exam and Ecosystem Overview

1.1 Certification Context 1.2 Study Map

2 Chapter 2: Agentic Architecture and Orchestration

2.1 Workflows vs Agents 2.2 Agentic Loops and the Claude Agent SDK 2.3 Multi-Agent Orchestration and Session Management

3 Chapter 3: Claude Code Configuration and Workflows

3.1 Claude Code Workflows

4 Chapter 4: Tool Design and MCP Integration

4.1 Tool Design and MCP Integration

5 Chapter 5: Prompt Engineering and Structured Output

5.1 Prompt Engineering 5.2 Structured Output and Evaluation

6 Chapter 6: Context Management and Reliability

6.1 Context, Caching, and Compaction 6.2 Model Selection and Reliability

6.1 Context, Caching, and Compaction

Key Takeaways Explain This Topic AI

The context window is a finite budget; place stable instructions and high-value context where Claude weights them most, and prune stale text.

Prompt caching reuses a large, stable prefix (system prompt, documents, tool definitions) across calls to cut cost and latency, but any byte change to the prefix invalidates the cache.

Compaction summarizes earlier history when a long conversation nears the window limit; progressive summarization keeps a rolling summary so old turns can be dropped without losing the thread.

Retrieve facts that change (prices, policy, inventory) at request time and ground answers in them with citations, rather than baking them into a static prompt.

Context management trades against freshness and cost; choose the technique that matches the named failure, not stacking all of them.

Last updated: October 2026

Context Is a Budget

Every model call has a finite context window , and the CCA-F treats it as a budget you spend, not infinite scratch space. Claude weights instructions placed near the start (system prompt) and near the end (most recent turn) more strongly, so put durable rules in the system prompt and the immediate task at the bottom. Remove stale, contradictory, or irrelevant text: leftover instructions silently degrade quality and waste tokens you are paying for.

When a fact can change (prices, inventory, policy), do not bake it into the prompt. Retrieve it from an authoritative source at request time and inject it as grounded context, ideally wrapped in tags with a citation. This is the difference between a system that ages into wrong answers and one that stays correct. The exam's Domain 5 also names managing context during large-codebase exploration — the same budget discipline applies: pull in only the files relevant to the current step, and let subagents read the bulk and return summaries (Chapter 2.3).

Prompt Caching

Prompt caching lets you mark a large, stable prefix — a long system prompt, a fixed document, or a block of tool definitions — so repeated requests reuse it instead of reprocessing every token. Used well it lowers both latency and cost on workloads that re-send the same context across many calls.

The mechanism to understand is the prefix match : the cache key is the exact bytes of the prefix up to a cache_control breakpoint, rendered in the order tools, then system, then messages. Any byte change anywhere in the prefix invalidates everything after it. Consequences you must know:

Keep volatile content (timestamps, per-request IDs, the varying question) after the last breakpoint; a datetime.now() in the system prompt silently breaks caching every request.

Do not change the tool list or switch models mid-conversation — both invalidate the cache.

Caching helps static, repeated context and does nothing for content that changes every request. A cache write costs slightly more than a normal read of the same tokens, so caching pays off only when the prefix is reused enough times to amortize that write.

Verify it worked by checking that cache-read token counts are non-zero across repeated identical-prefix requests; if they are zero, a silent invalidator is changing the prefix.

Compaction and Progressive Summarization

A long conversation eventually approaches the context-window limit. Two related techniques keep it going; distinguish them from caching (which is about cost, not capacity):

Compaction. When history nears the limit, earlier turns are summarized into a compact block that replaces the raw messages, freeing budget while preserving the gist. Server-side compaction does this automatically and returns a compaction block you must carry forward on subsequent requests; if you extract only the text and drop the block, the compaction state is lost.

Progressive summarization. A rolling summary is maintained as the conversation grows: after each chunk of turns, the system updates a running summary and can then drop the oldest raw turns. The agent always carries a current summary plus the most recent turns, so it never needs to hold the entire transcript verbatim. This is the preserving critical information across long conversations idea named in Domain 5.

Context editing / clearing. Distinct from summarizing, this prunes stale tool results or old thinking blocks outright rather than condensing them — useful when old tool output is simply no longer relevant.

The distinction to keep: compaction and summarization condense , context editing clears , and caching reuses . Match the term to the mechanism.

Choosing the Right Context Technique

These techniques solve different problems, so pick the one that matches the named symptom rather than stacking all of them.

Symptom in the scenario Right technique Why

Re-sending a 40-page doc + tool defs every call; high cost/latency Prompt caching the stable prefix Reuses unchanging tokens across calls

A multi-hour chat is about to exceed the window Compaction / progressive summarization Condenses old turns to free budget

  • Old tool outputs clutter context but are irrelevant Context editing / clearing Prunes stale blocks outright
  • A baked-in price is now wrong Retrieval at request time Keeps changing facts current

Cache hit rate is zero despite a stable prompt Remove the silent invalidator (timestamp, unsorted JSON, changing tools) Prefix must be byte-identical to cache

Trade-offs to Keep Straight

Caching vs freshness. Aggressive caching cuts cost but risks serving stale context if the cached prefix should have changed. Cache only what is genuinely stable.

Summarization vs fidelity. Compaction frees budget but loses detail; keep the most recent turns verbatim and summarize only the older history, and make sure the summary preserves decisions and constraints that later turns depend on.

Retrieval vs latency. Pulling fresh context grounds the answer but adds a retrieval round trip and tokens. Retrieve what the step needs, not the whole corpus.

When a question asks you to "improve" a system, identify which axis — cost, capacity, or freshness — is actually failing, then choose the smallest change that addresses that named failure. That disciplined, trade-off-aware reasoning is exactly what the CCA-F's context questions reward.