Context Management & Reliability/Reliability & Provenance
Intermediate10 min

Large Codebase Exploration & Context

Strategies for navigating large codebases with Claude: subagent delegation for isolated exploration, scratchpad files for persisting findings, crash recovery manifests, and the /compact pattern for reducing context mid-session.

Quick Reference

  • Context degradation in extended sessions causes Claude to reference 'typical patterns' instead of specific file names and line numbers
  • Scratchpad files persist findings across context boundaries -- write key discoveries to a file before they scroll out of context
  • Subagent delegation isolates verbose exploration: spawn a focused subagent for each investigation, collect structured results
  • The /compact command reduces context by summarizing the conversation history, freeing tokens for new exploration
  • Crash recovery manifests record the current state of a multi-step task so work can resume after a context reset or crash
  • Never load an entire large file into context -- read only the relevant sections (specific functions, classes, or line ranges)
  • Use grep/search tools before read tools: find what you need first, then read only that section
  • Summarize key findings BEFORE spawning the next phase of subagents -- this prevents the coordinator from losing track
  • For codebases over 100K lines, always start with directory structure and README before diving into specific files
  • A 'findings ledger' in the scratchpad prevents re-exploring files you've already analyzed

Context Degradation in Extended Sessions

When Claude works on a large codebase in a long session, a predictable failure mode emerges: context degradation. Early in the session, Claude references specific file paths, function names, and line numbers. As the session grows and the context window fills, Claude starts referencing 'the authentication module' instead of 'src/auth/middleware.ts line 47', or 'the typical pattern used in the codebase' instead of the actual code. This is not Claude being lazy -- it is the lost-in-the-middle effect from the previous article manifesting in code exploration.

Signs of context degradation

Watch for these signals that Claude's context is degrading: (1) references become vague ('the main file' instead of a path), (2) Claude re-reads files it already explored, (3) suggestions contradict findings from earlier in the session, (4) Claude asks questions that were already answered. When you see these, it's time to use /compact or spawn a fresh subagent.

Session phaseTypical behaviorContext usageMitigation
Early (0-20% context)Specific file paths, exact function signatures, precise line numbersLow -- plenty of roomNone needed
Mid (20-60% context)Still specific but may forget details from early explorationModerate -- tool results accumulatingWrite key findings to scratchpad
Late (60-80% context)Vague references, may re-explore files, occasional contradictionsHigh -- most capacity usedUse /compact, spawn subagents for new tasks
Critical (80%+ context)Significant accuracy loss, hallucinated file paths, circular explorationNear limitMust /compact or start fresh session with manifest