GlobTool for finding files by name, and GrepTool for searching file contents by regular expression — plus BashTool for any search patterns that need direct ripgrep invocation.
GlobTool
Finds files whose paths match a glob pattern. Results are sorted by modification time, so the most recently changed files appear first.Parameters
The glob pattern to match file paths against. Supports standard glob syntax including
*, **, ?, and brace expansion {a,b}.The directory to search in. If omitted, the current working directory is used. Must be a valid directory path — do not pass
"undefined" or "null".Pattern examples
| Pattern | Matches |
|---|---|
**/*.ts | All TypeScript files anywhere in the tree |
src/**/*.test.ts | All test files under src/ |
*.json | JSON files in the root directory only |
**/*.{ts,tsx} | TypeScript and TSX files anywhere |
src/tools/*/index.ts | index.ts in any direct subdirectory of src/tools/ |
Behavior
- Results are capped at 100 files. If more than 100 files match, the tool returns a truncated set and indicates that results were truncated.
- Paths are returned relative to the current working directory to save context tokens.
- Works efficiently on any codebase size.
Example
GrepTool
Searches file contents using regular expressions, powered by ripgrep. Supports three output modes and a rich set of filtering options.Parameters
The regular expression to search for. Supports full Rust regex syntax (the same syntax ripgrep uses).
File or directory to search in. Defaults to the current working directory.
Glob pattern to filter which files are searched, e.g.
"*.ts" or "*.{ts,tsx}". Maps to ripgrep’s --glob flag.Controls what is returned:
"files_with_matches"(default) — returns file paths that contain at least one match, sorted by modification time."content"— returns the matching lines with file path and line number."count"— returns each file path with its match count.
Number of lines to show after each match (ripgrep
-A). Only applies when output_mode is "content".Number of lines to show before each match (ripgrep
-B). Only applies when output_mode is "content".Number of lines to show before and after each match (ripgrep
-C). Alias for context. Only applies when output_mode is "content".Show line numbers in output. Defaults to
true when output_mode is "content".Case-insensitive search. Defaults to
false.Ripgrep file type filter, e.g.
"ts", "py", "rust". More efficient than glob for standard file types because ripgrep has built-in type definitions.Limit output to the first N lines or entries. Equivalent to piping through
head -N. Defaults to 250. Pass 0 for unlimited results (use sparingly — large result sets consume context).Skip the first N entries before applying
head_limit. Use with head_limit to paginate through large result sets.Enable multiline mode so
. matches newlines and patterns can span lines (ripgrep -U --multiline-dotall). Defaults to false.Regex syntax examples
Output mode examples
- files_with_matches (default)
- content
- count
Filtering by file type
- Using glob
- Using type
Pagination
When a search returns more results than the defaulthead_limit of 250, use offset to page through:
BashTool for search
For search tasks that go beyond whatGlobTool and GrepTool support, you can invoke ripgrep directly through BashTool.
Counting matches within files
GrepTool with output_mode: "count" aggregates counts per file. For a total count across all files, use rg directly:
Finding files with find
Listing large directories
Prefer
GlobTool and GrepTool over BashTool for file searches. They are read-only tools that don’t require shell permission approval, and their output is automatically formatted for Claude’s context window.