Rubric
Contents — domains, guide and mocks

Context in large codebase exploration

CCAR-F 5.412 min read · checked 21 September 2026

Task statementManage context effectively in large codebase exploration

Keeping exploration out of the main context

Main sessionholds the task, plan and summaries
  • Explore: billingreads 40 files → 1 summary
  • Explore: authreads 25 files → 1 summary
  • Explore: jobsreads 30 files → 1 summary
  • NOTES.mdfindings written to disk
Each subagent reads dozens of files in its own context window. Only its summary comes back, so the main session stays focused on the decision.

Why exploration is where context runs out

Claude Code’s best-practices guide opens with the constraint behind almost all of its advice: the context window fills up fast, and performance degrades as it fills. The window holds every message, every file Claude reads and every command output. A single debugging session or codebase exploration can consume tens of thousands of tokens, and as the window gets full Claude may start “forgetting” earlier instructions or making more mistakes. In practice that looks like answers that drift from the specific classes and call paths found an hour ago toward generic statements about how such systems usually work.

The guide names the failure directly as infinite exploration: asking Claude to “investigate” something without scope, so it reads hundreds of files and fills the context. The fix it gives has two halves — scope the investigation narrowly, or hand it to subagents so the exploration does not consume the main context.

Find first, then read

Anthropic’s context-engineering post describes Claude Code as a hybrid: a small amount of context is loaded up front (CLAUDE.md), and the rest is retrieved just in time with tools such as glob and grep, holding lightweight references like file paths and loading content only when needed. For exploration that means a deliberate order. Use Glob to find files by name pattern and Grep to find where a symbol is defined and used; then Read the few files those searches point to, following imports from the entry point rather than opening every file in the directory. (Choosing between the built-in tools is covered in 2.5.)

Two ways to answer “how are refunds processed?”

Read everything

  • Read all 60 files in payments/
  • Context fills with unrelated code
  • Early findings get compacted away
  • Answer drifts toward generalities

Find, then read

  • Grep for def refund and its callers
  • Read the handler and two services
  • Follow imports only where needed
  • Record the call chain in notes

Delegate broad searches to subagents

When a question genuinely needs wide reading — “which services write to the orders table?” — delegate it. A subagent runs in its own context window; its intermediate file reads and tool results stay there, and only its final message returns to the main session. The best-practices guide suggests prompts of the form “use subagents to investigate X”, precisely so research does not crowd out the implementation work that follows.

Claude Code ships a built-in Explore subagent for this: read-only (write and edit are denied), aimed at file discovery and code search, and invoked with a thoroughness level — quick, medium or very thorough — to match the question. Custom subagents in .claude/agents/ work the same way when you want a specific prompt, tool set or model. Remember that a subagent starts fresh: put the file paths, symbols and constraints it needs in the delegation prompt (subagent context passing is covered in 1.3).

Scoping an investigation

Unscopedtext

Investigate how the payments
system works.

Scoped and delegatedtext

Use subagents to find every code
path that issues a refund.
Start from api/refunds.py and
grep for callers of
RefundService.create.
Return: entry points, the call
chain for each, and any path
that skips fraud_check().
File paths and line numbers
only; no code excerpts.
The scoped version names the question, the starting points and the shape of the answer — and keeps the reading out of the main session.

Write findings down so they survive

Long explorations will eventually compact. Claude Code summarises the conversation and reloads a few things from disk — project-root CLAUDE.md and unscoped rules, auto memory, the plan written in plan mode, and up to five recently modified files — but individual discoveries made along the way exist only in the summary. Anthropic’s context-engineering post recommends structured note-taking for exactly this: have the agent keep a notes file of key findings (entry points, call chains, decisions, open questions) outside the context window, and reread it when needed. After compaction or in a new session, the file is still there.

CLAUDE.md lines that protect exploration worktext
# Exploration
- Record findings in NOTES.md as you go: file paths,
  call chains, decisions, open questions.
- Use subagents for any search likely to read more
  than ~10 files; ask them for paths and line numbers.

# Compaction
- When compacting, always preserve the list of files
  modified, the test command, and open questions.

The last instruction uses a documented technique: the best-practices guide suggests customising compaction in CLAUDE.md with lines such as always preserving the list of modified files and test commands. You can also compact deliberately with a focus — /compact focus on the refund call chain — before the automatic pass guesses what matters, or summarise just part of the conversation from the /rewind menu.

Know when to reset

Which move keeps the context useful?

What is happening in the session?
  • Need to find something
    Glob/Grep, then Readtargeted, just in time
  • Question needs wide reading
    Delegate to subagentExplore or custom
  • Same task, context filling
    /compact with focusnotes file already saved
  • Switching to unrelated work
    /clearstart from notes or a spec

The guide’s other named failure patterns are both about stale context. The kitchen sink session mixes unrelated tasks until the context is full of irrelevant material; the fix is /clear between tasks. Correcting over and over fills the context with failed approaches; after two failed corrections, /clear and write a better prompt using what you learned. For a large feature, the guide suggests a fresh session to execute a written spec, so implementation starts with clean context. Use /context at any point to see what is using the window.

Traps the wrong answers are built from

Tempting but wrongDo this instead
Reading every file in a module up frontGlob and Grep to locate, then Read only what the search points to.
Unscoped “investigate X” in the main sessionScope the question, or delegate it to subagents that return summaries.
Keeping key discoveries only in the conversationWrite them to a notes or plan file that survives compaction and new sessions.
One long session for several unrelated tasks/clear between tasks; resume from notes or a spec.
Asking subagents for code dumpsAsk for file paths, line numbers and short conclusions.

You should now be able to

  • Explain why exploration fills context fastest and how degradation shows up.
  • Apply just-in-time retrieval: locate with Glob and Grep before reading.
  • Delegate broad searches to Explore or custom subagents with scoped prompts.
  • Keep durable findings in a notes file and customise compaction in CLAUDE.md.
  • Choose between targeted reads, delegation, /compact with focus and /clear.

Practice questions

Original questions written for this lesson, in the exam’s style. Answer first, then open the reasoning — every option is explained, including why the wrong ones are tempting.

  1. Question 1

    An engineer spends two hours in one Claude Code session exploring an unfamiliar logistics codebase. Early on Claude identified the exact classes that calculate shipping rates. Now its answers describe “how rate engines typically work” and contradict details it found earlier.

    What is the most effective way to continue?

    1. AAsk Claude to reread the whole shipping/ directory to refresh its memory.
    2. BSave key findings to a notes file, then /compact or start fresh from it.
    3. CSwitch to a model with a larger context window and keep going.
    4. DAdd “do not generalise; use specific class names” to CLAUDE.md.
    Show answer and reasoning
    1. AIncorrect. Adds more raw content to an already crowded context, which is what caused the drift.
    2. BCorrect. Durable findings survive the reset, and the new context starts small and specific.
    3. CIncorrect. Postpones the limit but not the degradation that comes with a fuller, noisier context.
    4. DIncorrect. An instruction cannot restore details that have been pushed out or summarised away.
  2. Question 2

    Before changing a database column, a team needs to know every service in a 20-service monorepo that reads or writes it. The main Claude Code session will then plan the migration.

    Which approach best manages context?

    1. ARead each service’s data-access layer in the main session, one after another.
    2. BPaste the full schema and all model files into the first prompt.
    3. CAsk Claude to recall from general knowledge which services usually touch such columns.
    4. DDelegate the search to subagents that grep for the column and return paths and usage.
    Show answer and reasoning
    1. AIncorrect. Puts twenty services’ worth of code into the context that has to do the planning.
    2. BIncorrect. Front-loads a large amount of material, most of it irrelevant to the one column.
    3. CIncorrect. Speculation about code it has not opened; nothing is verified.
    4. DCorrect. Wide reading stays in the subagents’ contexts; the main session receives a compact, verified list.
  3. Question 3

    Which statement about Claude Code compaction is accurate?

    1. AEverything read during the session is kept verbatim after compaction.
    2. BCompaction deletes CLAUDE.md, so project rules must be repeated afterwards.
    3. CThe project-root CLAUDE.md reloads, but individual findings exist only in the summary.
    4. DCompaction only runs when you type /compact; it never happens automatically.
    Show answer and reasoning
    1. AIncorrect. Compaction replaces the conversation with a summary; only some items reload from disk.
    2. BIncorrect. Project-root CLAUDE.md is re-injected from disk after compaction.
    3. CCorrect. That is why findings should be written to a notes file before or during long explorations.
    4. DIncorrect. Claude Code compacts automatically as the context approaches its limit.

Sources

Drafted with AI assistance and checked against the sources above; expert review is in progress. Spotted an error? Tell us and it gets fixed, dated and listed on how this is written.