Claude Certified Architect

Foundations · CCAR-F

Domain 5 — 15%

Task 5.3

Context Degradation

Recognizing and mitigating context window exhaustion

📘What You Need to Know

Recognizing Context Degradation Symptoms

Context degradation is silent — quality drops gradually before anyone notices. The agent forgets constraints set at the beginning of the session. Responses become less focused and more generic. Tool selection accuracy decreases — wrong tools, wrong parameters. The agent repeats work it already completed, re-reading files and re-running searches.

Without monitoring, you do not notice degradation until damage is done: wrong code committed, incorrect data extracted, customer given wrong information. Recognizing symptoms early is the first mitigation step.

  • •Agent forgets earlier instructions or constraints
  • •Responses become less focused, more generic
  • •Tool selection accuracy decreases
  • •Agent repeats work already completed
  • •Contradicts earlier statements or decisions

The /compact Command

/compact compresses conversation history to reclaim context space while preserving key decisions and constraints. It is the in-session equivalent of progressive summarization — but you control what survives compression by ensuring critical data lives in case facts blocks that are excluded from compaction.

Use /compact when context usage is high but the session should continue — you need the thread of decisions, just with less verbatim history. Pair compaction with case facts blocks so reference data survives even as narrative history compresses.

🔑Key Concept

/compact reclaims space. Case facts blocks protect critical data from compression. Use both together.

Scratchpad Files for Persistent State

Scratchpad files persist important state outside the context window. The agent writes intermediate findings, completed steps, and active constraints to a file. If context degrades or the session is forked, the new session reads the scratchpad and resumes exactly where it left off.

Think of the scratchpad as the agent's notebook — clues, findings, and progress written as you go. If interrupted and resumed tomorrow, the notebook has everything needed to continue without re-exploring from scratch.

# scratchpad.md
## Task: Security audit of payment module
- [DONE] Step 1: Found 3 SQL injection vectors in user.ts
- [DONE] Step 2: Fixed injection in handleLogin()
- [IN PROGRESS] Step 3: Fixing XSS in template.ts line 47
- [TODO] Step 4: Add input validation to payment form
- [TODO] Step 5: Run test suite

## Active Constraints
- Do NOT modify database schema
- All fixes must include unit tests
- PR must pass lint before commit

Subagent Delegation for Context Hygiene

Verbose exploration — reading dozens of files, running wide searches, trial-and-error debugging — consumes context rapidly. Delegate exploration to subagents via the Task tool. The subagent performs verbose work in its own isolated context. Only the synthesized result returns to the coordinator.

This keeps the coordinator's context clean and focused on decisions, not exploration noise. A research subagent reads 20 papers; the coordinator receives a 3-paragraph summary with citations.

  • •Delegate verbose exploration to subagents with isolated context
  • •Only synthesized results return to the coordinator
  • •Coordinator context stays focused on decisions and synthesis
  • •Subagent failures propagate with structured error metadata

Crash Recovery with State Manifests

For complex multi-step operations, save a state manifest tracking completed and pending steps. If the process crashes or context is exhausted, the next run reads the manifest and resumes from the last checkpoint — not from zero.

Manifests complement scratchpads: scratchpads capture findings and decisions; manifests capture step completion status and checkpoints. Together they enable full session recovery after crashes, compaction, or context forking.

💡Tip

Scratchpad = what you found. Manifest = where you are in the process. Use both for long-running tasks.

⚠️Exam Traps

Trap: Ignoring context degradation symptoms and continuing the same session

Why it's wrong: Degraded context produces increasingly unreliable results — wrong tools, forgotten constraints, repeated work.

Correct approach: Use /compact, scratchpad files, or subagent delegation when degradation symptoms appear.

Trap: Using /compact without protecting critical data in case facts blocks

Why it's wrong: Compaction can compress reference data alongside narrative — losing exact values.

Correct approach: Store critical reference data in immutable case facts blocks before compacting history.

Trap: Repeating constraints in every message instead of using scratchpad or case facts

Why it's wrong: Wastes tokens on every turn and still loses constraints when context fills up.

Correct approach: Write constraints to scratchpad or case facts block once; reference persistently.

Trap: Running verbose codebase exploration in the coordinator session

Why it's wrong: Exploration noise fills context and triggers degradation in the decision-making session.

Correct approach: Delegate exploration to subagents; only synthesized results return to coordinator.

✓Concept Check

An agent starts forgetting constraints set at the beginning of a long session and repeats file reads it already completed. What should you do?

🔨Build Exercise

Intermediate35 minutes

Mitigate Context Degradation in Long Sessions

What you'll learn

  • •Recognize context degradation symptoms
  • •Apply /compact, scratchpad, and subagent delegation strategies
  • •Implement crash recovery with state manifests