Selecting built-in tools
What this covers
- Choose Grep, Glob, Read, Write, or Edit for the job at hand
- Resolve a non-unique Edit anchor by expanding it or by replacing every match
- Build codebase understanding incrementally rather than reading everything
- Enumerate every name a re-exported function travels under before searching for its callers
- Reach for Bash only when a job needs a process started, not to search or to edit
Key terms
- Glob pattern
- A pattern such as *.ts that selects files by name or path.
Choose the built-in tool for the task
- Grep searches contents — function names, error messages, import statements.
- Glob matches paths — files by name or extension, such as
**/*.test.tsx. - Read and Write handle whole files.
- Edit makes targeted modifications by matching unique text.
Grep and Glob are the pair most often confused. One asks "which files contain this?", the other "which files are named like this?".
Bash sits beside these and does a different job: none of the file tools runs anything, so a test command, a build, or git belongs there. Searching or editing through a shell instead gives up structured results for console text that varies by machine, and a stream-editor rewrite changes every match with nothing to confirm first.
When Edit fails
Edit depends on finding unique anchor text. When the text it is given appears more than once, it can't safely decide which occurrence you meant, and it fails.
That's not a dead end, and it has two fixes. Which one you want is a question about intent, not about the error:
- Expand the anchor. Add surrounding lines until the text matches exactly one place. Use this when one particular occurrence should change.
- Set
replace_all: true. Use this when every occurrence should change, which is the usual case for renaming something.
The same failure and both remedies, against one file:
anchor "const timeout" 3 matches -> fails
anchor "const timeout = 30" 1 match -> that one changes
anchor "const timeout", replace_all: true 3 matches -> all three changeThe second line and the third line answer different questions. Nothing in the failure message tells you which one you meant, because only you know that.
Reaching instead for Read and then Write rewrites a whole file to change one line, and puts every other line at risk of coming back altered. A narrow edit that failed is a reason to aim it better, not a reason to widen it.
Explore incrementally
Reading many files at once fills the context window with information that may not matter. Start from a known entry point and expand only as the investigation requires.
Work forward instead:
- Grep for an entry point — a route, a handler, an error message from a report.
- Read that file.
- Follow its imports, reading only what the trail actually requires.
This process keeps the investigation focused on files connected to the task.
Tracing through wrappers
Usage tracing gets harder when a module re-exports things. Do it in two steps: identify all exported names first, then search for each name across the codebase. Searching only for the original name misses every call that goes through the wrapper.
GrepGlobReadWriteEditreplace_all
Field note — common misconceptions
- MythThat Glob searches file contents
- ActuallyGlob matches paths by name or extension; Grep is the one that searches file contents.
- MythThat reading many files up front builds understanding faster
- ActuallyGrep an entry point, read that file, then follow only the imports the trail requires.
- MythThat a failing Edit means the change cannot be made
- ActuallyExpand the anchor until it matches one place, or set
replace_all: truefor every occurrence.
Guided review
Review this lesson as a study deck
Review the lesson's main ideas in five guided slides, then test yourself with three flashcards.
Open Task 2.5 study deckCross-domain reasoning
Connect this idea
Project settings control coding work
Sessions, built-in tools, project instructions, skills, path rules, and execution mode determine what Claude knows and what it can do during a code change.
- 1.7 · Manage session state, resumption, and forking
- 3.1 · Configure CLAUDE.md files with appropriate hierarchy, scoping, and organization
- 3.2 · Create and configure custom slash commands and skills
- 3.3 · Apply path-specific rules for conditional convention loading
- 3.4 · Determine when to use plan mode vs direct execution
Applied practice
Practice this lesson in a lab
Use a related lab to create a decision, implementation or diagram, evidence record, and review.
- Lab 5 · Design and test an MCP server
Design narrow MCP capabilities for a synthetic note catalog and test every trust boundary.