# grep

Canonical URL: https://developers.iagenify.com/sdk/agent/tools/grep/
Language: en

`grep({ pattern, path?, glob?, ignore_case?, max_results? })`

Search file contents with a regular expression. Returns path, line number and the matching line.

Status: category: read · free · 100 results by default

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `pattern` | string | required | A regular expression. |
| `path` | string |  | Where to search. |
| `glob` | string |  | Only files matching this pattern, e.g. `**/*.js`. |
| `ignore_case` | boolean |  | Case-insensitive. |
| `max_results` | integer | 100 | How many matching lines to return. |

## What comes back {#output}

```bash
src/auth.js:42: if (!token) throw new Unauthorized();
src/auth.js:88: // TODO: rotate the token here
src/session.js:14: const token = await exchange(key);
```

Path, line, text — enough for the agent to decide which file to open, without opening any of them.

## Narrow with glob, not with a bigger pattern {#narrow}

> **glob cuts the search; max_results cuts the answer**
>
> A pattern that matches a lot in a large tree fills the turn with lines. Restricting the files is cheaper than restricting the output, because the output is what is paid for.

## The usual sequence {#pairing}

`grep` to find where, `read { paths }` to see the places, `edit` to change them. Three turns for a change across a project.

- [glob](/sdk/agent/tools/glob): Finding by name.
- [multi_edit](/sdk/agent/tools/multi-edit): Changing several places in one file.
- [Agent tools](/sdk/agent/tools): The 35, by family.
