Claude Code's Built-in Tools: Read, Write, Edit, Bash, Grep and Glob, and When Each One Is the Right Pick
A small shop codebase you have never seen, and one question: where do refunds happen? Search first with Grep and Glob, read only what matches, fall back to Read plus Write when Edit finds two matches, and follow renamed imports through a wrapper module.
What you will learn
- Say what each of the six built-in tools is for
- Choose Grep to search file contents and Glob to match file paths
- Fall back to Read plus Write when an Edit anchor matches more than once
- Trace a flow from a Grep hit through its imports, including wrapper modules that rename functions
Before you start
- Running Claude Code in a terminal
- Reading a small Python project
You join a team and open a shop codebase you've never seen. There are files for orders, refunds, an API, agent tools and tests. Your task: find every place that issues a refund.
One way is to open every file and read it all. That's slow, and it fills the context with noise. The better way is to search first, then read only the files that match. Claude Code works the same way, with six built-in tools: Read, Write, Edit, Bash, Grep and Glob. Picking the right one for each step is the whole skill.
What each tool is for
The lecture's project carries a cheat sheet, TOOLS.md. Here it is as a table:
| Tool | Job | Example call |
|---|---|---|
| Read | Load a whole file | Read(file_path: "shop/refunds.py") |
| Write | Create or replace a whole file | Write(file_path: "shop/refunds.py", content: ...) |
| Edit | Change one exact piece of text (it must match once) | Edit(file_path: ..., old_string: ..., new_string: ...) |
| Bash | Run a shell command | Bash(command: "python -m pytest -q") |
| Grep | Search inside file contents | Grep(pattern: "process_refund") |
| Glob | Match file paths by name | Glob(pattern: "**/test_*.py") |
Find with Grep and Glob, load with Read, change with Write and Edit, run with Bash.
Grep reads contents, Glob reads paths
Think of a big library. Grep looks inside every page of every book for the words you want. Glob only reads the labels on the shelf: it finds every title that starts with test and never opens a book. Read takes a whole book off the shelf, and Write puts a whole new copy back.
The call blocks in this article show the sequence of tool calls Claude Code would make, not a recorded session, so no tool results are shown. For "find every place that issues a refund", the order is:
Grep(pattern: "process_refund") # which files mention the function?
Glob(pattern: "**/test_*.py") # which files are tests?
Read(file_path: "shop/refunds.py") # now load the one that defines it
Reading the project's files shows what those searches would find. In its Python code, process_refund appears in shop/refunds.py (where it's defined), shop/api.py and tests/test_refunds.py, and tests/test_refunds.py is the only file whose path matches the test pattern. Grep needs to open files to know; Glob never does.
refunds.py and the Edit anchor
Here's the file Claude reads. Notice the two identical "refused" lines; the project puts them there on purpose.
"""Refund rules for the support agent."""
from shop.orders import lookup_order
REFUND_LIMIT = 100.0
def process_refund(order_id, amount):
order = lookup_order(order_id)
if amount > REFUND_LIMIT:
return {"ok": False, "reason": "refused"}
if order is None or order["total"] < amount:
return {"ok": False, "reason": "refused"}
return {"ok": True, "refunded": amount}
def refund_status(order_id):
order = lookup_order(order_id)
return "refunded" if order and order.get("refunded") else "none"
Edit changes text by matching an anchor, its old_string, and the anchor must match exactly once.
- Anchor
REFUND_LIMIT = 100.0appears once, so Edit can change the limit. - Anchor
"reason": "refused"appears twice. Edit can't tell which one you mean, so it fails with a two-matches error.
Say the task is the project's sample prompt: change the second "refused" message to "more than paid". The reliable fallback is Read, then Write:
Edit(file_path: "shop/refunds.py",
old_string: "reason": "refused",
new_string: "reason": "more than paid") # two matches: fails
Read(file_path: "shop/refunds.py") # load the whole file
Write(file_path: "shop/refunds.py", content: ...) # the whole file, one line changed
Bash(command: "python -m pytest -q") # check nothing broke
Write saves the full file with only the second message different. Then Bash runs the project's two tests, which check that a small refund is accepted and one over the limit is refused. A longer anchor that occurs only once would also work for Edit. What doesn't work is running the same Edit again, or asking Grep or Glob to pick a match: those two only search.
Learn a codebase: Grep the entry point, then follow imports
A new question: why is a refund refused? You don't need all five Python files to answer it.
- Grep for
refused. In theshop/code, onlyrefunds.pycontains it. - Read
refunds.py. At the top it importsfrom shop.orders import lookup_order, and the secondrefuseddepends on what that lookup returns. - Read
orders.py, following the import:
"""Order lookups for the support agent."""
ORDERS = {
1042: {"item": "headphones", "total": 59.0, "customer": "C-77"},
}
def lookup_order(order_id):
return ORDERS.get(order_id)
Now the flow is clear: a refund is refused if it's over the 100.0 limit, or if the order is missing or the amount is more than the order total. The API module, the agent tools and the tests were never opened.
Wrapper modules: names change, search each one
One more trap. shop/api.py re-exports the refund code under new names:
from shop.refunds import process_refund as issue_refund
from shop.refunds import refund_status as check_refund
from shop.orders import lookup_order as find_order
And this is the code that really calls them, shop/agent_tools.py:
"""Tools the support agent can call."""
from shop.api import find_order, issue_refund
def refund_tool(order_id, amount):
if find_order(order_id) is None:
return "no such order"
return issue_refund(order_id, amount)
A search for process_refund alone never reaches agent_tools.py, because that file never uses the old name. So first list the exported names, then search for each new one:
Grep(pattern: "import", path: "shop/api.py") # list the exported names
Grep(pattern: "issue_refund") # who calls the renamed refund?
Grep(pattern: "find_order")
Grep(pattern: "check_refund")
In the project, issue_refund and find_order both appear in agent_tools.py as well as api.py, and check_refund appears only in api.py: it has no callers yet. Searching only for the original name would have missed the agent's refund tool.
Common mistakes
- Reading every file first. It's slow and fills the context. Search, then read what matches.
- Using Glob to find a function. Glob sees names and paths, not code. Use Grep.
- Retrying an Edit that found two matches. It fails the same way. Use a unique anchor, or Read then Write.
- Searching one name through a wrapper. List what the wrapper exports and Grep every name.
How this shows up in a question
A scenario might say the same error message appears in two functions of a long file and Edit reports two matches. Read the file, then Write the whole file with the change. Options that use Grep or Glob to "replace" or "pick" a match fail, because both tools only search.
Quick recap
| Question | Tool |
|---|---|
| Where is this function used? | Grep (contents) |
| Which files are tests? | Glob (paths) |
| Show me this file | Read |
| Change one unique line | Edit |
| Edit found 2 matches | Read, then Write the whole file |
| Did it break anything? | Bash runs the tests |
The built-in tools are the first shelf to check before you build anything yourself; see built-in tool, custom tool, skill or MCP. The sample shop codebase for this lesson is in the community, free to join.
Try it yourself
Open the shop folder in a terminal, start claude, and ask for every caller of process_refund. Watch which tool it picks first, and whether it finds agent_tools.py. Then ask it to change the second "refused" message and see what it does when Edit finds two matches.
Related course on Udemy
Claude Certified Architect - Foundations (CCAR-F) Exam Prep
Agentic loops, tools, MCP, Claude Code, prompts, structured output and context.View on Udemy ↗: Claude Certified Architect - Foundations (CCAR-F) Exam Prep (paid course, opens in a new tab)Related posts
CLAUDE.md, settings.json and Plugins: Which Claude Code File Advises, Which Enforces, Which Packages
Three needs in one repo: a test command, a rule that Claude must never read .env, and a shared deploy skill. See which file each belongs in, how the settings layers merge, and what a plugin manifest carries.
Authoring a Claude Skill: SKILL.md, Frontmatter, Progressive Disclosure and the Description That Triggers It
Pack a support team's ticket-triage routine into one skill folder, then watch three requests load one, two or all three levels: the catalog, the SKILL.md body, and a script whose code never enters the context.
One Change, Four Environments: Where a Claude Config Edit Lands in Dev, Staging, Prod and CI
Change one line in a repo and ask where it lands. A small resolver for bookshop-bot shows that a new model id in settings.json reaches only CI, a prompt bump reaches dev and CI, and a prod block edit reaches only prod.
Claude in the SDLC: Prompts in Git, a Change Gate by Path, a Claude Review That Advises and a Person Who Merges
Follow one prompt edit from a branch to a merge: version prompts and the model pin like code, keep the API key in GitHub Secrets, gate changes by path, let Claude review the diff, and leave the merge to a person.
