Skip to content

Pick the built-in tool for codebase work

Choose Grep, Glob, Read, Edit, Write or Bash for a codebase task, fall back to Read plus Write when Edit has no unique anchor, and explore a codebase incrementally from its entry points.

Scenario

An engineer asks the agent you built for Developer Productivity with Claude: "How does the legacy billing service apply late fees?" The service has 1,900 files.

The agent's first move is to Read files from src/ in alphabetical order. Forty files in, its context is full of unrelated controllers and it still hasn't found the word "late".

One Grep for late_fee would have pointed at the three files that matter.

Explanation

Search tools: Grep for contents, Glob for names.

  • Grep searches inside files for a pattern: a function name, an error message, an import. "Where is applyLateFee called?" is a Grep question. It returns matching files by default, or matching lines.
  • Glob finds files by path pattern: **/*.test.tsx, src/**/billing*.ts. "Which test files exist?" is a Glob question. It never looks inside files.

File tools: Read, Edit, Write.

  • Read loads a file's contents.
  • Edit replaces one exact string (old_string) with another. The string must appear exactly once; a whitespace difference misses it.
  • Write creates a file or overwrites it entirely. Use it for new files, not for small changes to existing ones.
  • Bash runs commands: the test suite, a build, git log.

When Edit can't find a unique anchor. If old_string appears more than once, first widen it with surrounding lines until it is unique, or set replace_all if every occurrence should change. When the file has no distinguishing text around the spot (two identical config blocks, say), Read the whole file and Write it back with the one change. The exam guide names only this last step, Read plus Write, as the fallback when Edit fails.

Explore incrementally. Don't read everything first. Grep for an entry point (a route, a command name, an error message), Read that file, then follow its imports and calls one step at a time. To trace a function used through a wrapper module, first list every name the wrapper exports, then Grep for each name across the codebase, since callers may import an alias rather than the original.

Where the tools come from. In the Agent SDK you list built-in tools by name (for example a subagent's tools: ["Read", "Grep", "Glob"]). In Claude Code on macOS, Linux and WSL, Glob and Grep are left out of the default set and Claude runs find and grep through Bash instead; naming Glob or Grep in --tools or --allowedTools brings them back. The exam assumes the agent has Grep and Glob, and the choice between searching names and searching contents is the same either way.

Worked example

The question: "How does the billing service apply late fees?"

Before: Read src/accounts.ts, src/adapters.ts, src/api.ts... 40 files in, no answer and a full context.

After:

  1. Grep late_fee|lateFee in src/: 3 files match, among them routes/invoices.ts.
  2. Read routes/invoices.ts: the overdue handler calls applyPenalties from billing/index.ts.
  3. Read billing/index.ts: it re-exports applyPenalties from billing/penalties.ts, also exported as chargeLateFee.
  4. Grep both names, applyPenalties and chargeLateFee: a nightly job uses the second one.
  5. Read billing/penalties.ts and the nightly job.

Six targeted calls and four files read, out of 1,900: the agent can now explain the fee logic and both callers.