Large codebase context: CCAR-F task statement 5.4
CCAR-F · Context Management & Reliability (15% of the exam)
Task statement 5.4 sits in Context Management & Reliability, 15% of the CCAR-F exam. It tests how to keep a long exploration of a large codebase accurate as the context fills: delegate searching to subagents, write findings to files, compact with instructions, and resume cleanly after a crash.
What the official guide covers
The Claude Certified Architect Foundations exam guide (version 1.0, effective July 2026) lists this under task statement 5.4, "Manage context effectively in large codebase exploration":
| Knowledge of | Skills in |
|---|---|
| Context degradation in long sessions: answers become inconsistent and refer to "typical patterns" instead of the specific classes found earlier | Spawning subagents for specific questions ("find all test files", "trace refund flow dependencies") while the main agent keeps the overall picture |
| Scratchpad files keep key findings across context boundaries | Having agents keep scratchpad files of key findings and consult them for later questions |
| Subagents isolate verbose exploration output while the main agent coordinates | Summarising one phase's findings before spawning subagents for the next phase, and putting that summary in their initial context |
| Structured state for crash recovery: each agent exports state to a known location and the coordinator loads a manifest on resume | Designing crash recovery with state exports (manifests) that the coordinator loads and injects into agent prompts |
Using /compact to reduce context during long exploration sessions full of verbose discovery output |
What fills the context
In Claude Code, the context window holds the whole conversation: every message, every file Claude reads and every command output. One exploration can use tens of thousands of tokens. Claude Code's documentation warns that performance degrades as the context fills, and Claude may start to forget earlier instructions or make more mistakes.
The guide names the symptom to look for: Claude stops naming the InvoiceLedger class it found an hour ago and starts describing "a typical service layer". Answers to the same question begin to differ. Run /context to see what is using the space.
Subagents keep exploration out of the main context
A subagent runs in its own context window with its own system prompt and tools. It can read 40 files, and only its summary returns to the main conversation.
| Option | Where | Notes |
|---|---|---|
| Built-in Explore subagent | Claude Code | Read-only (Write and Edit denied). Claude picks a thoroughness level: quick, medium or very thorough. Skips CLAUDE.md to stay fast |
| Custom subagent file | .claude/agents/ (project) or ~/.claude/agents/ (personal) | Frontmatter sets name, description, tools and optionally model |
AgentDefinition | Agent SDK, agents option | The main agent calls subagents through the Agent tool, so include "Agent" in allowed_tools. Older SDK versions, and the exam guide, call it Task |
A project subagent for tracing flows might look like this:
---
name: flow-tracer
description: Traces how a request moves through the codebase. Use for questions like "trace the refund flow" or "which modules call PaymentGateway".
tools: Read, Grep, Glob
---
Trace only the flow you are asked about. Return at most 30 lines:
- entry points as file:line
- classes and functions in call order
- external services touched
- questions you could not answer
Do not paste whole files.
One rule catches many candidates: a subagent does not see the parent conversation. Its context starts with its own system prompt, its tools, usually the project CLAUDE.md, and the prompt written for that call. The parent's history, tool results and loaded skills do not come with it (list skills in the subagent's skills field if it needs them). So when phase 2 depends on what phase 1 found, summarise phase 1 and put that summary in each phase 2 prompt.
Two details sit on either side of that rule:
- Explore and Plan skip CLAUDE.md. A project rule such as "never read files under
vendor/" is not in their context. When project constraints must apply, use a custom subagent or the general-purpose one. - A fork is the exception. Claude Code can also start a fork, a subagent that inherits the whole conversation so far (
/subtaskstarts one). Its tool calls still stay out of your context, but it gives up the clean start. Use a fork for a side task that needs everything said so far; use a normal subagent when a clean, focused context is the point.
Scratchpad files
A scratchpad is a plain file where the agent writes what it has confirmed: class names, file paths, decisions, open questions. Before answering a later question, the agent reads it again. The file survives /compact, /clear and a new session, because it lives on disk, not in the context. Anthropic's context engineering guidance calls this structured note-taking, for example an agent keeping a NOTES.md file.
/compact and /clear
/compact Focus on the refund flow findingssummarises the session and tells Claude what to keep. Use it when the task continues but the context is full of discovery output.- A "Compact instructions" section in CLAUDE.md sets what every compaction keeps, such as "always keep the list of files changed and the test commands".
- Claude Code also compacts automatically as the context approaches its limit.
/clearstarts fresh. Use it between unrelated tasks, not in the middle of one.
Rewind: summarise part of the session, or drop a dead end
/compact compresses everything. The rewind menu (/rewind, or Esc twice on an empty prompt) works on part of the session. Pick an earlier prompt, then choose:
| Option | Use it when |
|---|---|
| Summarize from here | A long debugging detour after that point is filling the context; your setup and instructions before it stay word for word |
| Summarize up to here | A long setup phase before that point can be compressed; the recent work stays intact |
| Restore conversation | Claude went down a wrong path; drop that stretch of conversation and try again |
| Restore code, or code and conversation | The edits from the wrong path should go too |
As with /compact, you can type what the summary should focus on. Restoring code covers edits made with Claude's file editing tools, not files changed through Bash commands, and usually not edits a subagent made.
Put findings back after every compaction
A scratchpad only helps if Claude reads it. After every compaction, manual or automatic, a SessionStart hook whose matcher is compact runs, and any plain text it prints joins Claude's context. Point it at the findings file:
{
"hooks": {
"SessionStart": [
{
"matcher": "compact",
"hooks": [
{ "type": "command", "command": "cat \"${CLAUDE_PROJECT_DIR}\"/FINDINGS.md" }
]
}
]
}
}
Now the confirmed class names and file paths come back after every summary, whether or not Claude remembers to check the file. The compaction events also have their own hooks (PreCompact, PostCompact), but SessionStart with compact is the one whose output goes back into the conversation.
Crash recovery with a manifest
For a long multi-agent run, each agent writes its state to a known place, and the coordinator reads a manifest when it restarts.
import json
from pathlib import Path
STATE_DIR = Path(".agent-state")
MANIFEST = STATE_DIR / "manifest.json"
def load_manifest() -> dict:
return json.loads(MANIFEST.read_text()) if MANIFEST.exists() else {}
def save_state(agent: str, status: str, findings: list[str], next_step: str) -> None:
STATE_DIR.mkdir(exist_ok=True)
state = {"status": status, "findings": findings, "next_step": next_step}
(STATE_DIR / f"{agent}.json").write_text(json.dumps(state, indent=2))
manifest = load_manifest()
manifest[agent] = {"status": status, "state_file": f"{agent}.json"}
MANIFEST.write_text(json.dumps(manifest, indent=2))
def resume_prompt(agent: str, task: str) -> str:
entry = load_manifest().get(agent)
if entry is None or entry["status"] == "done":
return task
state = json.loads((STATE_DIR / entry["state_file"]).read_text())
found = "\n".join(f"- {f}" for f in state["findings"])
return f"{task}\n\nYou are resuming earlier work. Confirmed so far:\n{found}\nContinue from: {state['next_step']}"
Each agent calls save_state after every finding it confirms. On restart, the coordinator skips agents marked done and builds each unfinished agent's prompt with resume_prompt, so no agent starts from nothing.
Which technique fits
| Situation | Choose | Why |
|---|---|---|
| A question needs many files read ("find all test files") | Subagent (Explore or custom) | Verbose output stays out of the main context |
| Answers drift to generic patterns after a long session | Scratchpad file, then /compact with instructions | Findings are kept on disk and in the summary |
| Phase 2 subagents repeat phase 1 mistakes | Summarise phase 1 into each phase 2 prompt | Subagents do not inherit the parent's history |
| Moving to an unrelated task | /clear | Old context only adds noise |
| A long multi-agent run may crash | State files plus a manifest loaded on resume | Work restarts from the last confirmed point |
| A debugging detour mid-session filled the context | Rewind, then Summarize from here | Compresses the detour, keeps earlier instructions intact |
| Findings vanish after automatic compaction | SessionStart hook with the compact matcher prints the findings file | Re-injects them every time, by code |
| An Explore search ignored a project rule | General-purpose or custom subagent | Explore and Plan do not load CLAUDE.md |
Rules that decide exam answers
- Delegate discovery, keep coordination. Subagents answer narrow questions; the main agent holds the overall picture.
- Subagents start without the parent's history. Pass findings in the prompt. Options that assume the subagent "already knows" are wrong.
- Files outlast context, hooks bring them back. A scratchpad or state file survives compaction, clearing and crashes; a
SessionStarthook with thecompactmatcher puts it back in context without relying on Claude to look. - Compact with instructions mid-task, clear between tasks. Naming what to keep is what makes
/compactsafe. - A bigger context window does not stop degradation. Pasting more code in makes it worse.
Where it appears in the exam
Context Management & Reliability is a primary domain in four of the six exam scenarios: Customer Support Resolution Agent, Code Generation with Claude Code, Multi-Agent Research System and Structured Data Extraction. Codebase exploration questions fit the Code Generation with Claude Code scenario. Manifests and phase summaries also fit the multi-agent research scenario. The guide's preparation exercises 1, 3 and 4 list Domain 5 among the domains they reinforce.
Two sample questions
These are original Timo practice questions. They are not official exam questions.
Build exercise
- Open a repository with tens of thousands of lines in Claude Code. Ask it to explain three different flows in one session and check
/contextafter each. - Add the
flow-tracersubagent above and repeat with "use the flow-tracer subagent". Compare the main context usage. - Ask Claude to keep
FINDINGS.mdas it goes, add a "Compact instructions" section to CLAUDE.md, run/compact, then ask a question that needs an early finding. - In an Agent SDK script, add
save_stateandresume_prompt, stop the process halfway through, restart it and check that each agent resumes from its last step.
Practise this topic
- Claude Certified Architect practice exam: free, 20 questions, no sign-up
- Claude Certified Architect hub
- CCAR-F study guide: all topics
- Previous topic: 5.3 Error propagation
- Next topic: 5.5 Human review and confidence
Sources
- Claude Certified Architect Foundations Exam Guide, version 1.0, effective July 2026 (Anthropic), task statement 5.4
- Claude Code documentation: Create custom subagents
- Claude Code documentation: Checkpointing
- Claude Code documentation: Hooks reference
- Anthropic: Effective context engineering for AI agents
By Amotion AI