What you will be able to do
- Choose Grep for content searches (callers, error messages, imports) and Glob for file-name and extension patterns
- Explain why the dedicated Read, Grep and Glob tools are preferred over shell equivalents run through Bash
- Build understanding of a codebase step by step: search for entry points first, then read only the files the search points to
Key concept
Path match vs. content match — Glob matches file paths and names, and Grep matches text inside files. Pick the tool by asking where the thing you want lives, in the file's name or in its contents, and only Read the files those searches turn up.
1.Six tools that do most of the work
Claude Code comes with many built-in tools. For work inside a codebase, six of them handle nearly everything. The tools reference gives each a one-line description: Read "Reads the contents of files", Write "Creates or overwrites files", Edit "Makes targeted edits to specific files", Bash "Executes shell commands in your environment", Grep "Searches for patterns in file contents", and Glob "Finds files based on pattern matching".
The how-it-works page sorts these capabilities by job: file operations, search and execution. It describes search as the ability to "find files by pattern, search content with regex, explore codebases". Those are two different verbs, and each one belongs to a different tool.
The reference also lists which tools need permission, and that split gives you a useful mental model. Read, Grep and Glob need no permission. They only look, so they are cheap to call while you are still figuring out what to change. Edit, Write and Bash change files or run arbitrary commands, so they are gated. The same table notes that Glob and Grep are "Absent by default on macOS, Linux, and WSL". Whether you have them depends on how the session is set up. Configuring tools is covered in another lesson. This one is about choosing the right tool when they are available.
| Tool | Description | Permission required |
|---|---|---|
| Read | Reads the contents of files | No |
| Grep | Searches for patterns in file contents | No |
| Glob | Finds files based on pattern matching | No |
| Edit | Makes targeted edits to specific files | Yes |
| Write | Creates or overwrites files | Yes |
| Bash | Executes shell commands in your environment | Yes |
Checkpoint 1 of 5· Match them up
Match each built-in tool to its job
Tap a term, then the definition that fits it.
Grep searches inside files and Glob matches file paths. Read loads a file's contents, and Bash runs shell commands.
“Searches for patterns in file contents”Source: code.claude.com
2.Grep for what's inside files, Glob for what files are called
The choice comes down to one question: is the thing you're matching in the file's path, or in its text?
Glob takes a pattern such as **/*.ts, plus an optional path that defaults to the current working directory. Use it whenever a naming convention carries the answer, for example test files (**/*.test.tsx), every file with a given extension, or files in a certain directory layout. If the project pairs Button.tsx with Button.test.tsx, two Glob calls give you both lists of names, and you can compare them without opening a single file.
Grep takes a pattern that is a regular expression, such as TODO.*fix. It also takes an optional path and an optional glob filter, so you can restrict a content search to, say, *.ts files. Use Grep when the evidence is inside the code: every caller of a function, the place an error message is raised, every file that imports a module.
Two other Grep parameters are worth knowing. output_mode can be content, files_with_matches or count, and the default is files_with_matches. So a plain Grep call returns a list of files, not the matching lines. Ask for content when you need to see the lines themselves, or count when you only need a number. Grep also supports case-insensitive search (-i) and multiline matching.
| Parameter | Glob | Grep |
|---|---|---|
| pattern | Glob pattern to match files against (e.g. **/*.ts) | Regular expression pattern to search for (e.g. TODO.*fix) |
| path | Optional directory; defaults to current working directory | Optional file or directory to search in |
| glob | Not a parameter | Optional glob pattern to filter files (e.g. *.ts) |
| output_mode | Not a parameter | content, files_with_matches, or count; defaults to files_with_matches |
Checkpoint 2 of 5· Check yourself
A user reports the message "Invalid session token" and asks where it comes from. What is the most direct first step?
An error message lives inside a file, not in its name, so this is a content search. Grep's regex pattern finds the exact location without guessing at filenames.
“Regular expression pattern to search for”Source: code.claude.com
Checkpoint 3 of 5· Exam question
An architect asks Claude Code to find every place in a large monorepo that calls a function named `parseInvoice`, including calls inside a minified bundle that is gitignored but still needs to be checked. Which approach correctly locates all call sites?
Correct answer: D — Run Grep across the repo for parseInvoice, then Grep the gitignored bundle's path directly, since a direct path is still searched
- A. Incorrect. The multiline flag changes whether a pattern can match across line boundaries; it has no effect on whether gitignored files are included in the search.
- B. Incorrect. Globbing for files named after the function only finds a file that happens to share the name, not the files where the function is called, so real call sites in other files are missed.
- C. Incorrect. Glob only matches file paths by name pattern; it cannot see whether a file's contents reference parseInvoice, so this cannot identify call sites.
- D. Correct. Grep respects .gitignore and skips gitignored files by default, but passing a gitignored file's path directly still searches it, so a normal repo-wide Grep plus a targeted Grep on the bundle path covers both tracked and gitignored call sites.
Sources3
3.Prefer the dedicated tools over shell equivalents
Bash can run find, grep, cat and sed, so technically it could handle every search and edit itself. Claude Code deliberately steers away from that. One changelog entry records that system prompts were improved to guide the model toward "using dedicated tools (Read, Edit, Glob, Grep) instead of bash equivalents (cat, sed, grep, find)", which cut down on unnecessary Bash calls.
The tools reference gives a practical reason as well. Bash needs permission, while Read, Grep and Glob do not. The dedicated tools also have structured inputs that shell one-liners lack. Read takes an optional offset (the line number to start from) and limit (how many lines to read), so you can view part of a large file without piping it through head or sed. Grep has output_mode and a glob filter.
Bash is still the right tool for real execution. The how-it-works page lists that category as "Run shell commands, start servers, run tests, use git". Use Bash for those jobs. Searching and reading belong to the dedicated tools.
Checkpoint 4 of 5· Check yourself
Claude needs a list of every .ts file in the project. Which approach matches Claude Code's guidance?
Glob is the dedicated tool for matching file paths. Claude Code's system prompts steer the model toward it and away from shell equivalents like find.
“using dedicated tools (Read, Edit, Glob, Grep) instead of bash equivalents (cat, sed, grep, find)”Source: code.claude.com
4.Build understanding incrementally: search, then read
Reading every file in a repository up front fills the context window with code that probably doesn't matter. The documented workflows do it the other way round. The how-it-works page walks through fixing a failing test: run the test suite, read the error output, search for the relevant source files, read those files, edit them, then run the tests again. Search comes before reading, and the search decides which files get read.
The common-workflows guide gives the same advice: "Start with broad questions, then narrow down to specific areas". Its example prompts escalate from finding the files that handle authentication to tracing "the login process from front-end to database". In tool terms, Grep finds an entry point, such as a route handler or a function name. Read opens that file. Its imports name the next files to open, and you Read those in turn. Each read is chosen by what the previous one showed you.
The skills docs bake this order into an example research skill that runs in an Explore subagent:
Research $ARGUMENTS thoroughly:
1. Find relevant files using Glob and Grep
2. Read and analyze the code
3. Summarize findings with specific file referencesCheckpoint 5 of 5· Put it in order
Put the documented bug-fixing loop in order
- 1.Read the error output
- 2.Run the tests again to verify
- 3.Search for the relevant source files
- 4.Run the test suite to see what's failing
- 5.Read those files to understand the code
- 6.Edit the files to fix the issue
The search narrows down which files deserve a Read. Edits come only after those files are understood, and running the tests again confirms the fix.
“Read those files to understand the code”Source: code.claude.com
Exam traps
Each one states something that sounds right. Open it to see what is actually true.
1.To find files that follow a naming convention (like *.test.tsx), Grep the codebase for the word "test".Why is that wrong?
A naming convention lives in the file path, so Glob is the direct tool. Grep searches file contents and would match any file that happens to contain the word.
Covered in Grep for what's inside files, Glob for what files are called
2.Running find or grep through Bash is just as good as calling Glob or Grep, because the results are the same.Why is that wrong?
Claude Code's guidance prefers the dedicated tools over their shell equivalents. Bash also needs permission, while Grep and Glob do not.
Covered in Prefer the dedicated tools over shell equivalents
Sources
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.https://code.claude.com/docs/en/tools-referenceOfficial docs
“Searches for patterns in file contents”
↩︎ Six tools that do most of the work“Absent by default on macOS, Linux, and WSL”
↩︎ Six tools that do most of the work“Finds files based on pattern matching”
↩︎ Exam trap 1 - 2.
“Find files by pattern, search content with regex, explore codebases”
↩︎ Six tools that do most of the work“Run shell commands, start servers, run tests, use git”
↩︎ Prefer the dedicated tools over shell equivalents“Find files by pattern, search content with regex, explore codebases”
↩︎ Key concept“Read those files to understand the code”
↩︎ Checkpoint - 3.https://code.claude.com/docs/en/hooksOfficial docs
“Glob pattern to match files against”
↩︎ Grep for what's inside files, Glob for what files are called“Optional glob pattern to filter files”
↩︎ Grep for what's inside files, Glob for what files are called“Optional line number to start reading from”
↩︎ Prefer the dedicated tools over shell equivalents“Regular expression pattern to search for”
↩︎ Checkpoint - 4.https://code.claude.com/docs/en/changelogOfficial docs
“using dedicated tools (Read, Edit, Glob, Grep) instead of bash equivalents (cat, sed, grep, find)”
↩︎ Prefer the dedicated tools over shell equivalents“using dedicated tools (Read, Edit, Glob, Grep) instead of bash equivalents (cat, sed, grep, find)”
↩︎ Exam trap 2 - 5.https://code.claude.com/docs/en/common-workflowsOfficial docs
“Start with broad questions, then narrow down to specific areas”
↩︎ Build understanding incrementally: search, then read“trace the login process from front-end to database”
↩︎ Build understanding incrementally: search, then read - 6.https://code.claude.com/docs/en/skillsOfficial docs
“Find relevant files using Glob and Grep”
↩︎ Build understanding incrementally: search, then read