Skip to content

Built-in Tools

This module is about choosing the right Claude Code built-in tool for codebase navigation and file modification.

The official task statement focuses on six tools: Read, Write, Edit, Bash, Grep, Glob

Claude Code’s current tools reference confirms that these built-in tool names are used directly in permissions, subagent tool lists, CLI flags, and hooks. (Claude Code)

The exam will test whether you can distinguish:

Grep = search inside files
Glob = find files by path/name pattern
Read = inspect file contents
Edit = targeted exact replacement
Write = create or overwrite whole files
Bash = run commands, tests, builds, scripts

1. High-Level Decision Table

User / agent need Best tool Why
Find all callers of calculateTotal Grep Search file contents
Find files named *.test.tsx Glob Match file paths/names
Inspect src/api/user.ts Read Load file contents
Change one unique function body Edit Targeted exact replacement
Create a new test file Write New full-file operation
Replace an entire generated config Write Whole-file overwrite
Run tests/build/lint Bash Command execution
Find an error message string Grep Content search
Find all route files under app/ Glob Path pattern search
Edit fails because old text appears multiple times Read + longer Edit anchor, or Read + Write fallback Need reliable modification

2. Grep: Search File Contents

Use Grep when you are looking for text inside files.

Claude Code’s docs define Grep as a file-content search tool: Glob finds files by name, while Grep finds lines inside files.

Claude Code Grep is built on ripgrep, supports regex syntax, and can return file paths, matching content, or counts. (Claude Code)

Examples:

Search for all callers of getUser:
Grep pattern: "getUser("

Search for an error message:
Grep pattern: "Invalid order ID"

3. Glob: Find Files by Path/Name Pattern

Use Glob when you are looking for files by filename, extension, or path pattern.

Claude Code’s docs define Glob as file-name pattern matching and show patterns such as **/*.js, src/**/*.ts, and *.{json,yaml}. Results are sorted by modification time and capped, so overly broad patterns may need narrowing. (Claude Code)

Examples:

Find all TSX test files:
Glob pattern: "**/*.test.tsx"

Find all route files:
Glob pattern: "app/**/route.ts"

Find all migration files:
Glob pattern: "db/migrations/*.sql"

4. Read: Inspect Specific File Contents

Use Read when you know which file you need to inspect.

The Anthropic text editor docs describe the view operation as the way Claude examines the contents of a file or a specific line range. (Claude)

Examples:

Read src/services/orderService.ts
Read src/components/CheckoutButton.tsx
Read the file containing the matching Grep result
Read the entrypoint found via Glob

5. Edit: Targeted Exact Modifications

Use Edit when you need to modify a specific, known piece of text in an existing file.

Claude Code’s Edit tool performs exact string replacement: it takes an old_string and new_string; the old string must match exactly, including whitespace, and it must appear exactly once unless replacing all matches is intended.

Claude Code also requires the file to have been read earlier in the current conversation before editing. (Claude Code)

Example:

Old string:
export const RETRY_LIMIT = 3;

New string:
export const RETRY_LIMIT = 5;

6. Write: Full File Create or Overwrite

Use Write when creating a new file or replacing an entire file.

Claude Code’s tool reference describes Write as the tool that creates or overwrites files. (Claude Code) The text editor docs similarly describe file creation as providing a path and full file text. (Claude)

Examples:

Create src/services/userService.test.ts
Overwrite generated/openapi-types.ts
Rewrite a small config file
Replace a whole markdown doc

7. Edit Failure: Non-Unique Match Fallback

This is one of the official tasks statement’s most important skills.

7.1 Preferred Recovery Order

Step 1: Read the File: Use Read to inspect the surrounding context.

Step 2: Try a more unique Edit anchor

Step 3 : Use Read + Write fallback: If the file has too many repeated blocks, generated formatting, or the target cannot be anchored reliably, use Read to load the current full file, then Write the corrected full file.

If Edit fails due to non-unique text, the best answer is:

Read the file to get full context, then either use a longer unique Edit anchor or use Write to replace the file reliably.

Do not blindly retry the same Edit.


8. Bash: Run Commands, Tests, Builds, Scripts

Use Bash for command execution, not as the first-choice search existing tools.

Anthropic’s Bash tool docs describe Bash as enabling command-line execution, including development workflows such as running tests, builds, scripts, package installation, and system automation.

They also emphasize safety practices such as timeouts, logging, command filtering, minimal permissions, and output handling. (Claude)

8.1 Use Bash For

Run test suites
Run lint/typecheck/build
Install dependencies
Run scripts
Inspect git status
Generate files through project tooling
Run formatters
Run codemods carefully

Examples:

npm test
npm run build
npm run typecheck
pytest
go test ./...
cargo test
git status --short

Heuristic:

Use specialized Claude Code tools for codebase search and file edits.
Use Bash for actual command execution.

9. Incremental Codebase Understanding Workflow

The official statement explicitly says:

Start with Grep to find entry points, then use Read to follow imports and trace flows, rather than reading all files upfront.

9.1 Bad Workflow

Read every file in src/
Try to infer the architecture from raw volume
Edit based on partial understanding

Problems:

Wastes context
Misses actual call paths
Increases hallucination risk
Makes irrelevant files dominate

9.2 Better workflow

Suppose the task is:

“Update how checkout errors are handled.”

A strong Claude Code workflow:

1. Grep for known error string or function:
   "Checkout failed"

2. Grep for likely symbols:
   "handleCheckoutError"
   "submitCheckout"
   "checkoutService"

3. Read the most relevant files from Grep results.

4. Follow imports from those files:
   Read imported service/module files.

5. Grep for callers of the key exported function:
   "submitCheckout("

6. Read callers that matter.

7. Make targeted Edit changes.

8. Bash test/typecheck relevant package.

This is efficient because it uses Grep to discover, Read to understand, Edit to change, and Bash to validate.


10. Tracing Function Usage Across Wrapper Modules

The official statement calls this out directly:

Trace function usage across wrapper modules by first identifying all exported names, then searching for each name across the codebase.

This matters because a function may be re-exported, aliased, or wrapped.

10.1 Example

Suppose you are tracing:

getCurrentUser

The implementation file contains:

export function getCurrentUser() {
  return authClient.currentUser();
}

But another file re-exports it:

// src/auth/index.ts
export { getCurrentUser as getUser } from "./session";

And another wrapper exposes:

export const loadUser = getUser;

If you only search:

getCurrentUser

you miss calls to:

getUser
loadUser

10.2 Strong Tracing Workflow

1. Grep for the original implementation:
   "function getCurrentUser"
   "const getCurrentUser"
   "export.*getCurrentUser"

2. Read the implementation file.

3. Grep for exports/re-exports:
   "getCurrentUser"
   "getCurrentUser as"

4. Identify aliases:
   getCurrentUser
   getUser
   loadUser

5. Grep for each exported or aliased name:
   "getCurrentUser("
   "getUser("
   "loadUser("

6. Read important caller files.

7. Follow imports to verify that the symbol is the same one, not an unrelated same-name function.

Heuristic:

Find exported names and aliases first, then search each exported name across the codebase.


11. Practical Examples by Task

11.1 Find All Tests for "Checkout”

Glob: "**/*checkout*.test.ts"
Glob: "**/*checkout*.spec.ts"
Glob: "**/*.test.tsx" with path narrowed to checkout directories if needed

Why not Grep? Because you are searching by file name/path.


11.2 Find Every Place That Throws This Error

Grep: "Payment authorization failed"

Why not Glob? Because you are searching file contents.


11.3 Change the Retry Count from 3 to 5 in "config.Ts”

Read config.ts
Edit unique old string:
  maxRetries: 3
to:
  maxRetries: 5

If maxRetries: 3 appears multiple times:

Read more context
Use a longer unique block
Or Read + Write the full corrected file

11.4 Add a New Unit Test

Glob to find existing test naming patterns
Read nearby test file to match conventions
Write new test file
Bash run targeted test

Example workflow:

Glob: "src/**/*.test.ts"
Read: src/services/userService.test.ts
Write: src/services/orderService.test.ts
Bash: npm test -- orderService.test.ts

11.5 Understand Request Flow for "POST /api/orders:

Grep: "POST"
Grep: "/api/orders"
Glob: "app/**/route.ts" or "src/**/routes/**/*.ts"
Read matching route file
Follow imports with Read
Grep key service function callers

This combines Glob and Grep correctly.

15. Final D2.5 checklist

Memorize this:

1. Grep searches file contents.
2. Glob searches file paths/names.
3. Read loads known file contents.
4. Edit performs targeted exact replacement.
5. Write creates or overwrites whole files.
6. Bash runs commands, tests, builds, scripts, and project tooling.
7. Use Grep for callers, imports, function names, error messages.
8. Use Glob for **/*.test.tsx, route files, configs, migrations.
9. Use Read before Edit.
10. Edit requires exact, unique old text.
11. If Edit fails due to non-unique text, use longer context or Read + Write.
12. Do not read the whole codebase upfront.
13. Build understanding incrementally: Grep → Read → follow imports → Grep again.
14. To trace wrappers, identify exported aliases first, then search each name.
15. Prefer specialized tools over Bash for search and file modification.

Exam mental model

For D2.5, think:

Search what is inside files? Grep.
Search which files exist? Glob.
Need to inspect? Read.
Need a small precise change? Edit.
Need a whole file operation? Write.
Need to execute project commands? Bash.

The most exam-relevant workflow is:

Grep to discover entry points.
Read only the relevant files.
Follow imports and exports.
Grep aliases and wrappers.
Edit with unique anchors.
Use Read + Write when Edit is unreliable.
Run Bash tests to validate.
Test yourself on this topic Interactive questions for Task 2.5 — Built-in Tools, with instant explanations and scoring.
Start quiz →