Codebase Exploration
During big codebase exploration Claude drifts from exact file paths to vague 'typical patterns'. Learn why, and the scratchpad, subagent, and /compact fixes.
When an agent explores a large codebase, it can start losing its grip on earlier findings as the window fills with verbose discovery output. This is not a token-limit problem — it is an attention-quality problem. Specific discoveries get buried under newer listings, and the model quietly drifts from precise references to generic ones.
How degradation shows up
Early on, the agent cites specifics: the OrderRepository class at src/repos/order.ts. Several modules later it hedges: this follows the typical repository pattern. The mechanism is predictable — each step emits verbose output (files, search hits, directory trees), that output accumulates, earlier precise discoveries get pushed down, and the model's attention concentrates on the most recent tokens.
Enlarging the context window does not fix degradation — a larger window simply fills with the same verbose output. The problem is attention quality under noise, not raw capacity.
Scratchpad files
Have the agent maintain a dedicated findings file and consult it for later questions. Record specific class names and file paths, dependency chains, critical issues, and coverage metrics. Treat this as a deliberate strategy from the outset, not a rescue move once things degrade.
# EXPLORATION NOTES
- OrderRepository -> src/repos/order.ts (depends on Db, Cache)
- CRITICAL: raw SQL string-concat in order.ts:88 (injection risk)
- Tests: order.test.ts covers create/read; no update coverage
- Open question: who calls OrderRepository.delete()?Let raw discovery output accumulate unbounded in one context and rely on the model to recall it. Precise paths get buried and drift into vague 'typical pattern' language.
"This follows the typical repository pattern."Externalise state into a scratchpad file the agent updates and consults, so exact class names and paths survive regardless of window pressure.
"OrderRepository -> src/repos/order.ts (raw SQL at order.ts:88)"Subagent delegation
Spawn focused subagents for specific tasks instead of one agent exploring everything. Each subagent runs in isolated context, so its verbose exploration never pollutes the main agent, and it returns a structured summary rather than raw output. The real value here is context isolation, not just parallelism.
Summary injection and /compact
- Summary injection between phases — summarise Phase 1 findings and inject them into the Phase 2 subagent prompt, preventing cold-start duplication and lost architectural understanding.
- The /compact command — Claude Code's
/compactsummarises the conversation to reclaim space while keeping key information. Use it proactively during long sessions, not only at the limit. - Crash recovery via state manifests — persist a JSON manifest (session id, current phase, explored paths, key findings, next steps) so a coordinator can reload and resume from a checkpoint.
{
"sessionId": "explore-2024-06-01",
"phase": "dependency-mapping",
"exploredPaths": ["src/repos", "src/services"],
"keyFindings": ["OrderRepository at src/repos/order.ts"],
"nextSteps": ["map callers of delete()"]
}The core fix for context degradation is to externalise state — scratchpad files, injected summaries, and manifests — so precise discoveries survive. Restarting from scratch throws away hard-won knowledge; delegation and /compact preserve it.
When exam options offer 'increase the context window' vs 'delegate to a subagent', pick delegation — its benefit is isolating verbose output, which directly addresses the attention-quality root cause.
How the exam will try to trick you
The distractors below look right under time pressure — learn the tell.
- The trap
Fix context degradation by increasing the context window.
Correct answerExternalise findings to scratchpad files and delegate verbose work to subagents.
Why: A larger window just fills with the same verbose output — it is an attention-quality problem, not a token limit.
- The trap
The point of subagent delegation is parallel speed.
Correct answerDelegate primarily for context isolation — verbose exploration stays out of the main context.
Why: Isolation prevents degradation; parallel execution is only a secondary bonus.
- The trap
When context degrades, restart the session and explore more efficiently.
Correct answerPersist findings to a scratchpad or state manifest first, then inject them into the new session.
Why: Restarting discards all accumulated knowledge; structured persistence lets you resume.
- The trap
Reach for
/compactonly when the context window is nearly exhausted.Correct answerUse
/compactproactively during long sessions to keep context quality high.Why: Waiting until exhaustion reduces its effectiveness; proactive use prevents degradation.
Key takeaways
- Context degradation is an attention-quality problem, not a token-limit one — a bigger window does not fix it.
- The tell-tale symptom is drift from specific file paths and class names to vague 'typical pattern' language.
- Maintain scratchpad files from the start to persist exact findings, not as a last-minute rescue.
- Delegate focused subagents primarily for context isolation, so verbose exploration stays out of the main context.
- Inject Phase 1 summaries into later phases and use /compact proactively during long sessions.
- Save state manifests so an interrupted exploration can resume from a checkpoint instead of restarting.
Frequently asked questions
Why does Claude start referencing 'typical patterns' instead of specific files during exploration?+
As exploration proceeds, each step adds verbose output that accumulates in context and pushes earlier precise discoveries down. The model's attention gravitates to the most recent tokens, so it loses its grip on the exact class names and file paths it found earlier and falls back on generic descriptions. This is context degradation — an attention-quality issue that a scratchpad file, subagent delegation, or /compact addresses, but a larger context window does not.
How is subagent delegation different from just parallelising work?+
The headline benefit of delegating to subagents is context isolation, not speed. Each subagent explores in its own context and returns only a structured summary, so its verbose file listings and search results never accumulate in the coordinator's window. That keeps the main agent's context clean and its earlier findings intact — parallel execution is a secondary bonus.