Sub topic 3
The tools an agent can call
This chapter assumes you know the agent loop (model call, tool call, observation) and are comfortable with a shell and git. It covers the built-in tools that Claude Code, Codex CLI, and Copilot CLI give the model, and how to reason about each one's risk.
Why tools matter
A language model only produces text. It cannot read your repository or run your tests. A tool is a function the agent program exposes to the model. The model asks for a tool by name with arguments, the program runs it, and the result goes back into the conversation as an observation. Everything an agent does to your machine happens through a tool call.
The four core tool groups
Names differ between products, but all three tools offer the same groups.
| Group | What it does | Typical risk |
|---|---|---|
| File read | Opens files or line ranges and returns the text | Exposes secrets such as `.env` to the model |
| File edit | Replaces text in a file or creates a new file | Wrong or unwanted changes to your code |
| Shell | Runs a command and returns output and exit code | Highest. Can delete files, use the network, or push code |
| Search | Finds files by name pattern or text by regular expression | Low. Read-only |
Search tools matter more than they look. The model cannot load a whole repository, so it searches first and then reads only the files that match. Good search keeps the context window small.
A tool call in practice
Suppose you ask the agent to fix a failing date test. A typical sequence looks like this:
The model decides each step after seeing the last result. The agent program, not the model, executes the call. That is the point where permissions apply.
Edits are exact replacements
Edit tools usually take the old text and the new text, not a whole file. If the old text does not match the file exactly, the edit fails and the model sees an error. It then reads the file again and retries. Failed edits are normal and cost only a little context. Large rewrites of whole files are rarer and harder to review.
The shell is the general tool
The shell tool lets the agent do anything you can do in a terminal: run tests, call git, start a build, or use curl. Because of that, most permission rules target it. Each tool treats it differently:
- Claude Code matches commands against rules such as
Bash(npm run test:*). - Codex CLI relies on an approval policy and a sandbox that limits what a command can touch.
- Copilot CLI asks you before running a command and lets you approve it once or for the session.
Later chapters cover these controls in detail.
Tools beyond the built-ins
Agents can also fetch web pages, call external services, or run subagents. These usually come from extensions such as MCP servers, which a later chapter covers. Treat their output as data from an outside source, because it enters the same context as your instructions.
Exercise
An agent runs npm test and reports success, but you never saw the output. Which tool group produced that result, and what should you check?
Show answer
The shell tool ran the command. Check the exit code and the actual output yourself, for example by running npm test in your own terminal, because the model's summary is not proof that the tests passed.
Exercise
Why do agents search before they read files?
Show answer
The context window is limited. Searching finds the few relevant files so the agent reads only those, which keeps the context small and focused.