Skip to content
Claude Certified Architect – Foundations (CCAR-F) Exam Prep

Lesson 25 of 30 · 7 min

x
25/30

Context Preservation

Video lesson: CCAR-F 25/30: Context Preservation

How the window works

  • Everything counts toward the window: system prompt, every message (including tool results, images, documents), tool definitions, and the model's own output including thinking. With prompt caching, all of input_tokens, cache_read_input_tokens and cache_creation_input_tokens count; caching changes price, not whether tokens count.
  • More context is not automatically better. As tokens grow, accuracy and recall degrade: context rot. Curating what is in context matters as much as capacity.
  • Windows: 1M tokens on the current model families listed in the docs; 200k on some older models. A request can generate up to 128k output tokens.
  • Overflow: if the input alone exceeds the window, the API returns a 400 ("prompt is too long"). On Claude 4.5 and newer, if input plus max_tokens exceeds it, the request is accepted and generation may stop with stop_reason: "model_context_window_exceeded". Estimate with the token counting API.
  • Context awareness (model tracks its remaining budget) exists on some models (for example Sonnet 5, Sonnet 4.6, Haiku 4.5); newer models do not get the injected tags, and task budgets (beta) provide an explicit budget.

Placement inside a prompt

For long inputs (20k+ tokens) put long documents at the top, above the query and instructions; putting the query at the end can improve quality by up to 30% in tests on complex multi-document inputs. Wrap each document in <document> tags with <source> and <document_content> subtags.

Strategies that keep information alive

StrategyWhat it doesNotes (verified unless marked)
Persistent facts block (design guidance)A short block of key facts (ids, decisions, constraints) re-stated at a stable positionProtects critical details from being lost in the middle or in summarisation
Trim tool output (verified)Return only high-signal fields from toolsBloated tool results waste context (2.1)
Context editingServer-side clearing of old tool results (clear_tool_uses_20250919) or thinking blocks (clear_thinking_20251015)Configurable: trigger (for example input tokens), keep (how many tool uses to keep), clear_at_least, exclude_tools. Clearing invalidates the cached prefix, so clear enough to be worth it
CompactionServer-written summary replaces older turnsBeta. On demand (you decide when; header compact-2026-09-04, top-level compaction parameter) or at a token threshold (API decides). You can write your own summarisation prompt and keep recent turns word for word
Memory toolClient-side /memories files Claude reads and writesSurvives resets; see below
SubagentsIsolate exploration in their own contextOnly the final message returns (1.3)

Memory across sessions

The memory tool ({"type": "memory_20250818", "name": "memory"}) is client-side: Claude requests operations (view, create, str_replace, insert, delete, rename) and your application executes them against storage you control. Restrict every path to /memories (path-traversal protection is your job). Use it with compaction: compaction keeps active context small; memory keeps what must survive summarisation. For multi-session work, an initializer session sets up a progress log and checklist; later sessions read them first.

Exam traps

  • "Just use the biggest window." Context rot makes curation necessary.
  • Putting the question before long documents.
  • Relying on a summary to preserve exact ids or numbers with no persistent facts block.
  • Letting tool results accumulate unbounded.
  • Treating the memory tool as server-side storage. You implement and secure it.

References

  1. Context windows — checked Oct 16, 2026
  2. Compaction — checked Oct 16, 2026
  3. Context editing — checked Oct 16, 2026
  4. Memory tool — checked Oct 16, 2026
  5. Prompting best practices — checked Oct 16, 2026

Check your understanding

  • Where do long documents and the question go in a prompt?Show answer

    Answer

    Documents first, query last.
  • Who stores memory-tool files?Show answer

    Answer

    Your application; Claude only requests the operations.
  • Why use clear_at_least with context editing?Show answer

    Answer

    Clearing invalidates the cached prefix; clear enough tokens to justify the cache rewrite.
Previous

Progress is saved in this browser.

Next Lesson