Codebase Exploration
Delegate exploration
Exploring a large codebase fills context with file reads. Delegate it: a subagent reads files in its own context window and reports a summary, so only the findings return (Domain 1.3). Common workflows recommends asking for a subagent for investigations such as "how does our auth system handle token refresh".
Anthropic's prompting guide also warns that newer models can over-delegate: do not spawn subagents for something a direct grep answers faster (verified). Delegate when work is parallel, isolated or large.
Explore broad, then narrow
Start with high-level questions (overview, architecture patterns, key data models, how a feature is handled), then drill into specific areas. Find files, then ask how they interact, then trace the flow end to end. Use domain language from the project.
Keep state outside the context (verified, from the long-horizon guidance)
For work spanning many steps or context windows:
- keep progress notes in a file (free text) and structured state (for example
tests.json) in a structured format; - use git as a log and checkpoint mechanism;
- start fresh sessions with a prescriptive routine (read progress notes, check
git log, run a baseline test) since current models are good at rediscovering state from the filesystem; - consider a fresh context window instead of compaction when state is on disk.
Memory and compaction in Claude Code
CLAUDE.mdloads each session; auto memory stores Claude's own notes. Instructions can seem lost after/compact: put durable instructions in CLAUDE.md, not only in the conversation.- Subagents get their own context; skills load their body only when used.
Targeted reads (design guidance)
Use Glob and Grep to find the few relevant files before reading; read ranges, not whole large files; reference files with @path only when they fit the Read limit (25,000 tokens by default; text over 256 KB is not included) (2.5).
Exam traps
- Reading every file in the main context.
- Spawning a subagent for a single grep.
- Keeping all state only in the conversation across context resets.
- Diving into specifics before getting an overview.
- Assuming a summary preserved exact file paths or line numbers.
References
- Common workflows — checked Oct 16, 2026
- Prompting best practices — checked Oct 16, 2026
- How Claude remembers your project — checked Oct 16, 2026
Check your understanding
A 2,000-file repo question about token refresh. Best approach?Show answerHide answer
Answer
Delegate investigation to a subagent and read its summary.A multi-day refactor spans several sessions. Where does state live?Show answerHide answer
Answer
Progress notes, structured state files and git, read at the start of each session.When is a subagent the wrong choice?Show answerHide answer
Answer
When a direct grep or a single-file read answers the question.