# Grep Tool

> The tool that searches inside files for a word or pattern.

**Field:** Artificial Intelligence  
**Category:** Claude Code  
**Also known as:** Grep, ripgrep, Search file contents

## Think of it like

It is like going through each page to find one word.

## Definition

The Grep tool searches inside files for text that matches a pattern. It is built on a fast search program called ripgrep. By default it returns only the names of files that match. It can also return the matching lines, or a count per file. It skips the files your .gitignore hides. Like Glob, it is left out by default on macOS and Linux, where Claude uses grep through Bash.

## Example

Lucy asks where an old function is still used. Claude searches for its name and gets back the six files that call it.

## Example code

```bash
claude --allowedTools "Grep"
```

Turn the Grep tool on for this session.

## Why it matters

It finds the spots to change in a big project. It does not have to read each file.

## Common mistake

Using it to look in a hidden file. Grep skips the files .gitignore hides, unless Claude gives the file's own path.

## Three principles

- **Searches inside.** Lines, not names.
- **Three outputs.** Files, lines, counts.
- **Skips ignored files.** Respects .gitignore.

## Related terms

- [Glob Tool](https://learn.benibix.com/term/ai/glob-tool)
- [Read Tool](https://learn.benibix.com/term/ai/read-tool)
- [Regular Expression (Regex)](https://learn.benibix.com/term/development/regular-expression)
- [ripgrep (rg)](https://learn.benibix.com/term/development/ripgrep)

## Told apart from

- [Glob vs Grep](https://learn.benibix.com/compare/glob-tool-vs-grep-tool): People often think Glob and Grep both search inside files. Only Grep does. Glob matches file names, such as every file that ends in .ts. Grep looks inside the files for a word or a pattern. There is one more catch. Glob also finds the files .gitignore hides, while Grep skips them.

## Taught in

- [Claude Code File Tools](https://learn.benibix.com/learn/ai-claude-code/claude-code-file-tools): Claude Code, 9/16

![Glob finds files by name, Grep finds lines inside them, Read opens one, then Edit changes a part or Write replaces it all.](https://learn.benibix.com/diagrams/ct-file-tools.svg)

---

Source: https://learn.benibix.com/term/ai/grep-tool
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
