﻿# How Claude Code finds the file that matters

Use Claude Code file search and selective reads to trace a behavioral question through a repository without front-loading every source file into context.

Author: Retrivium editorial team
Updated: 2026-11-03
Canonical URL: https://retrivium.ai/journal/learn-claude-selective-file-reading/
Language: en

The important question in repository exploration is usually behavioral: where a value changes, which code owns an interface or why an input fails. Claude Code can gather the answer through successive searches and reads. A compact investigation is effective when each new read follows from a concrete question raised by the previous observation.

## Search for a stable entry point

For a hypothetical duplicate-row export bug, an error label, route name or exported function can provide a starting point. Search results locate candidate files but do not yet establish the execution path. Inspect the relevant definition and identify what calls it. This avoids confusing similarly named test helpers with production behavior or treating a string match in documentation as proof of the implementation.

## Read the surrounding contract

A single line rarely explains the meaning of an exported value. Read the function signature, nearby transformation and relevant type. In the export example, a collection may already be grouped before it reaches the formatter. Without that contract, the agent might add deduplication in the wrong layer and hide a caller defect. A focused surrounding read provides enough semantics without requiring the entire module history.

## Follow data rather than filenames

Trace the value from input through transformation to output. If duplicate rows appear only after a merge, inspect how the merge key is constructed. A similarly named formatter file may be irrelevant. This dependency-oriented approach makes each read explainable: it either identifies the origin of a value, the rule that transforms it or the consumer whose assumption creates the visible failure.

## Check tests as evidence about expected behavior

Existing tests can reveal intended treatment of empty collections, ordering and repeated keys. They are useful evidence, but a missing case does not automatically authorize a new product rule. For the export bug, compare tests with the documented output contract and the reported input. The goal is to discover the supported behavior before editing, not to infer that every untested behavior is acceptable.

## Stop expanding when the explanation is testable

Once the input, responsible transformation and affected output are connected, create or run a focused reproduction. Its outcome can confirm or reject the current hypothesis. Further repository reading should answer a remaining uncertainty, such as another consumer of the same merge function. This gives exploration a natural stopping point and leaves room for the observations that establish whether the eventual repair actually works.

## Documentation and further study

- [How Claude Code works](https://code.claude.com/docs/en/how-claude-code-works).

- [Extend Claude Code](https://code.claude.com/docs/en/features-overview).

- [Best practices for Claude Code](https://code.claude.com/docs/en/best-practices).

Related engineering guides: [Reproducible inference stacks: preserving a GPU pilot’s result](/journal/software-stack-reproducibility/); [Choose a local AI stack: desktop chat, shared UI or coding agent](/journal/local-ai-app-stack-selection/).
