CertSafari
    Anthropic Claude Certified Architect – Foundations (CCAR-F)· Lessons

    Domain 5 · Lesson 28/30

    Context Rot, /compact and Scratchpad Files in Long Codebase Sessions

    Manage context effectively in large codebase exploration

    8 min read
    2.5% of exam
    4 sources
    Published 4 Oct 2026
    Docs as of 30 Sep 2026

    What you will be able to do

    • Recognise the signs of context degradation in a long exploration session and explain where it comes from
    • Use /compact, including focused instructions, and predict what survives compaction
    • Keep key findings in scratchpad files so they outlast summarisation and context resets

    Key concept

    Context as a finite attention budget — Every token in the context window competes for the model's attention. As exploration output piles up, recall of specific earlier details gets less precise, so you have to decide what stays in context, what gets summarised and what moves to disk.

    1.Why long exploration sessions degrade

    Large codebase exploration fills context faster than almost any other task. Every file read, grep result and directory listing stays in the conversation. Anthropic calls the resulting effect context rot: as the token count grows, the model gets worse at accurately recalling what is already in its context. The cause is architectural. In a transformer, every token attends to every other token, which gives n² pairwise relationships. Models also see fewer long sequences than short ones during training. The result is not a sudden failure: models "remain highly capable at longer contexts but may show reduced precision for information retrieval and long-range reasoning."

    The exam describes what this looks like in practice. Late in an extended session, the agent starts giving inconsistent answers. Instead of naming the specific classes it found earlier, it falls back on "typical patterns". Those earlier findings are technically still in context, but they are buried under thousands of tokens of later discovery output. Claude Code's best-practices guide gives the same warning about long sessions. It names a matching anti-pattern, the *infinite exploration*: you ask Claude to investigate something without scoping it, and it "reads hundreds of files, filling the context."

    Checkpoint 1 of 5· Check yourself

    Three hours into mapping a payments codebase, the agent answers a question about refunds by describing how refund services "are usually structured" and never names the RefundOrchestrator class it found in the first hour. What is the most likely cause?

    Sources12

    2.Reclaiming space with /compact

    The first remedy is compaction. When a conversation nears the context limit, the model summarises it and starts a new context window from that summary. In Claude Code, running /compact replaces the conversation with a structured summary. Claude Code also does this automatically. When it does, Claude summarises what matters most, including code patterns, file states and key decisions, and drops redundant tool output. That makes compaction a good fit for exploration sessions, where most of the bulk is raw discovery output you no longer need verbatim.

    The automatic pass has to guess what matters, and it can guess wrong. Anthropic warns that overly aggressive compaction can lose subtle details whose importance only shows up later. You have two ways to steer it:

    - Focused compaction. Run /compact with instructions, such as /compact focus on the auth bug fix. The summary then keeps what you chose, not what the automatic pass guessed was important. - Standing instructions in CLAUDE.md. For example: "When compacting, always preserve the full list of modified files and any test commands."

    You can also summarise only part of the conversation. Run /rewind, pick a message, and choose *Summarize from here* or *Summarize up to here*. To make automatic compaction start earlier, use /autocompact with a token count.

    Not everything after compaction comes from the summary. Several mechanisms reload from disk:

    What happens to each context mechanism after compaction in Claude Code
    MechanismAfter compaction
    Project-root CLAUDE.md and unscoped rulesRe-injected from disk
    Auto memoryRe-injected from disk
    The plan Claude wrote in plan modeRe-injected from disk
    Files Claude read or editedClaude Code re-reads up to five, most recently modified first
    Background commands and background subagentsKeep running; Claude is reminded which are still running
    Context that hooks added earlierSummarized with the rest of the conversation

    Checkpoint 2 of 5· Match them up

    Match each item to what happens to it when the conversation is compacted

    Tap a term, then the definition that fits it.

    Checkpoint 3 of 5· Check yourself

    You are about to start a long new exploration task. The current context is full of grep output from a finished debugging detour, but you need the exact retry-timeout value that detour uncovered. Which /compact usage best fits?

    Sources31

    3.Scratchpad files: findings that outlive the context window

    The compaction table shows a pattern: whatever lives in a file comes back intact, and whatever lives only in the conversation gets summarised. Structured note-taking, or agentic memory, builds on that. The agent regularly writes notes to storage outside the context window and reads them back when it needs them. Anthropic gives two examples: Claude Code keeping a to-do list, and a custom agent maintaining a NOTES.md file. Either lets an agent track progress and dependencies that "would otherwise be lost across dozens of tool calls."

    In codebase exploration, the scratchpad holds the specifics that context rot tends to blur: exact class names, file paths, configuration values and confirmed call chains. When the agent answers a later question, it rereads the scratchpad before it reasons. The answer then rests on the recorded finding, not on a degraded memory of a tool result from hours ago. The same approach works over much longer runs. In Anthropic's Pokémon example, Claude kept notes across thousands of game steps, and after each context reset it read its own notes and picked up where it left off. On the Claude Developer Platform, the memory tool provides this as a file-based system for storing and consulting information outside the context window across sessions.

    Scratchpads and compaction work together. To free space without losing an exact value, first write the value to a notes file, then compact. The file survives the reset whether or not the summary keeps the value. Anthropic matches each technique to a different kind of task:

    Choosing a long-horizon context technique by task shape
    TechniqueBest fit
    CompactionTasks requiring extensive back-and-forth, where conversational flow matters
    Note-taking (scratchpad / memory)Iterative development with clear milestones
    Multi-agent (sub-agent) architecturesComplex research and analysis where parallel exploration pays dividends

    Checkpoint 4 of 5· Exam question

    An architect has been running a single Claude Code session for several hours exploring a large monorepo. Early on, the agent correctly identified that OrderService extends a custom TransactionalBase class with a distinctive retry mechanism. Hours later, asked about OrderService again, the agent describes it as 'typically extending a standard base controller with default error handling,' ignoring its earlier finding. What should the architect do going forward to prevent this?

    Checkpoint 5 of 5· Check yourself

    Why record a key finding in a scratchpad file instead of relying on compaction to carry it forward?

    Sources32

    Exam traps

    Each one states something that sounds right. Open it to see what is actually true.

    1. 1.Running /compact keeps every important detail, so you never need to steer it.Why is that wrong?

      Compaction is a lossy summary. Subtle details can be dropped, so use /compact with instructions or CLAUDE.md compaction rules to protect what matters.

      Covered in Reclaiming space with /compact

    2. 2.Compaction alone is enough to carry work across many context windows.Why is that wrong?

      Anthropic found compaction insufficient for multi-window work, because summaries don't always hand the next context clear instructions. Persisted notes and progress files fill that gap.

      Covered in Scratchpad files: findings that outlive the context window

    Sources

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “Long sessions with irrelevant context can reduce performance.”
      ↩︎ Why long exploration sessions degrade
      “Claude reads hundreds of files, filling the context.”
      ↩︎ Why long exploration sessions degrade
      “When compacting, always preserve the full list of modified files and any test commands”
      ↩︎ Reclaiming space with /compact
    2. 2.
      “models remain highly capable at longer contexts but may show reduced precision for information retrieval and long-range reasoning”
      ↩︎ Why long exploration sessions degrade
      “the agent regularly writes notes persisted to memory outside of the context window.”
      ↩︎ Scratchpad files: findings that outlive the context window
      “After context resets, the agent reads its own notes and continues multi-hour training sequences or dungeon explorations.”
      ↩︎ Scratchpad files: findings that outlive the context window
      “Context, therefore, must be treated as a finite resource with diminishing marginal returns.”
      ↩︎ Key concept
      “overly aggressive compaction can result in the loss of subtle but critical context whose importance only becomes apparent later.”
      ↩︎ Exam trap 1
      “These factors create a performance gradient rather than a hard cliff”
      ↩︎ Prediction
      “overly aggressive compaction can result in the loss of subtle but critical context whose importance only becomes apparent later.”
      ↩︎ Checkpoint
    3. 3.
      “you run /compact, which replaces the conversation with a structured summary.”
      ↩︎ Reclaiming space with /compact
      “run /compact with instructions, like /compact focus on the auth bug fix, before starting a long new task.”
      ↩︎ Reclaiming space with /compact
      “Files Claude read or edited | Claude Code re-reads up to five, most recently modified first”
      ↩︎ Checkpoint
      “The summary keeps what you choose instead of what the automatic pass guesses is important.”
      ↩︎ Checkpoint

    Also cited

    Continue to page 2 of 2

    Subagent Delegation, Phase Summaries and Crash Recovery for Codebase Exploration

    Spotted a mistake, or was something unclear? Tell us.