Task statement 2.5 · Tool design and MCP integration
Select and apply built‑in tools (Read, Write, Edit, Bash, Grep, Glob) effectively
The engineer has never opened the billing code, so the agent does the reading through six built-in tools. Each wrong choice has a visible cost here: a search that finds nothing although the code exists, an edit that is refused every time, or a context window full of files the question never needed.
share
The tempting moves all feel thorough. Reading the whole billing codebase first seems safe, but it fills the context window before the agent knows what matters. Retrying a rejected Edit seems persistent, but the rejection is deterministic, so the retry fails the same way. Searching for a function with a filename pattern returns no matches, which looks like "no callers" when the pattern simply never looked inside a file.
KnowledgeGrep searches contents, Glob matches paths
Grep opens files and searches their contents for a pattern, such as a function name, an error message or an import statement. Glob never opens a file. It matches file paths against a glob, a filename pattern such as **/*.test.tsx (every test file at any depth) or **/*.sql (every file with that extension). So the question "where is roundCurrency called?" is about contents and needs Grep, while "which files are migrations?" is about names and needs Glob. A Glob for a function name returns nothing, and an agent that reads that as "unused" draws the wrong conclusion.
Grep
Grep("roundCurrency")
src/invoices/close.ts:58
src/dunning/schedule.ts:112
Grep("Invoice total mismatch")
src/invoices/validate.ts:41Built on ripgrep, so patterns use ripgrep regex, and it skips files listed in .gitignore.
Glob
Glob("**/*.sql")
db/migrations/0001_invoices.sql
db/migrations/0002_fees.sql
Glob("**/roundCurrency*")
// no matches: no file has that nameResults are sorted by modification time, and gitignored files are included by default.
More precise than the guide. Current Claude Code leaves Glob and Grep out of the default tool set on macOS, Linux and WSL, and Claude searches with find and grep through Bash instead. Naming either tool in the --tools or --allowedTools launch flags, or in the equivalent Agent SDK options, brings them back (checked 2026-10-01). Exam answer: Grep searches file contents and Glob matches file paths.
KnowledgeRead, Write, Edit and Bash
Read and Write work on whole files, while Edit makes a targeted change by unique text matching. Edit takes an old_string, the anchor text it searches for, and replaces it with a new_string. The match is exact, with no regex, and the anchor must appear exactly once, so an anchor that occurs three times is rejected rather than applied to a guess. Bash covers what no dedicated tool does, such as running the test suite.
Returns a file with line numbers. A file over the token limit returns its first page with a PARTIAL view notice.
Creates a file or overwrites all of it. It never appends or merges.
Replaces one exact, unique old_string in a file read earlier in the conversation. A PARTIAL view read does not count.
Runs a shell command. A cd inside the project carries over to later commands, but an export does not.
SkillWhen Edit cannot find unique anchor text
The engineer asks the agent to raise the refunds timeout, the second of three identical lines in billing/config.ts. The agent sends old_string: "timeout: 3000,", the edit is rejected, and the identical retry is rejected again, because the text appears three times. The docs give two ways out. Widening the anchor with the line above it (retries: 2,) makes it match once, and replace_all: true changes every occurrence, which is right only when all three should change. The guide's fallback is to Read the full file and Write it back with the one line changed, which works even when no nearby text is unique.
Interactive · one Edit, three outcomes
Choose how to change one timeout. old_string is timeout: 3000,.
Edit is rejected: the text matches three times, so there is no single place to apply it. Retrying fails the same way.
Docs resolution: add the line above to old_string, so exactly one occurrence matches.
Guide fallback: Read the full file, then Write all of it back with only line 3 changed.
SkillExploring 900 files without reading 900 files
The engineer asks how a late fee ends up on an invoice. Reading every file first would fill the context window with code the question never touches, and the few relevant lines would be hard to find among them. Building understanding incrementally works better: Grep finds an entry point, then Read follows its imports and traces the flow, so every file in context is one the question needs.
Read everything first
Glob("**/*.ts") → 900 files
Read(...) × 900Follow the imports
Grep("applyLateFee")
→ src/invoices/close.ts:58
Read("src/invoices/close.ts")
→ imports lateFee from billing
Read("billing/index.ts")That trace has just reached a wrapper module, which renames functions on the way out. Callers import lateFee, so a Grep for the original name calcLateFee finds only the definition and the wrapper. First identify all the names the wrapper exports, then search for each name across the codebase.
// billing/index.ts (the wrapper) export { calcLateFee as lateFee, calcTax as salesTax } from './legacy/fees'; Grep("calcLateFee") → billing/legacy/fees.ts, billing/index.ts Grep("lateFee") → 14 files Grep("salesTax") → 9 files
| Text inside files | Grep, then Read only the files it returns. |
| Files by name or extension | Glob. |
| One line whose text is not unique | Widen old_string if nearby text is unique; otherwise Read the file and Write it back. |
- A function name is content, so a filename pattern will never find its callers.
- A rejected
Editfails identically on retry; the guide's fallback is a fullReadthenWrite. - Start from one
Grephit and follow imports, and search every name a wrapper exports.