Skip to main content

Overview

The glob tool provides fast file pattern matching using ripgrep’s file enumeration. Use this when you need to find files by name patterns. Source: src/tools/glob/

Implementation

Uses ripgrep (rg --files) with glob pattern matching:
  • 60 second timeout
  • 100 file limit
  • Results sorted by modification time (newest first)
  • Respects .gitignore and .ignore files

Parameters

pattern
string
required
The glob pattern to match files againstExamples:
  • "**/*.js" - All JavaScript files
  • "src/**/*.ts" - TypeScript files in src/
  • "*.json" - JSON files in current directory
  • "**/test/*.spec.ts" - Test files
  • "components/**/*.{tsx,jsx}" - React components
Syntax:
  • * - Match any characters except /
  • ** - Match any characters including /
  • ? - Match single character
  • [abc] - Match one character from set
  • {a,b} - Match either pattern
path
string
The directory to search inDefaults to current working directory.Important: Omit this field to use the default directory. DO NOT enter “undefined” or “null” - simply omit it for the default behavior.Example: "src/components"

Response

output
string
Matching file pathsSuccess with matches:
Found 15 files matching "**/*.ts" (showing newest first):

src/tools/glob/tools.ts
src/tools/grep/tools.ts
src/tools/task/tools.ts
src/agents/explore/index.ts
src/shared/logger.ts
...
No matches:
No files found matching "**/*.xyz"
Truncated results (over 100 files):
Found 250 files matching "**/*.js" (showing newest 100):

[Results truncated to 100 files. Refine your pattern for full results.]
Error:
Error: ripgrep not found. Install ripgrep or add it to PATH.

Usage examples

Find all TypeScript files

glob(pattern="**/*.ts")

Find React components

glob(pattern="**/*.{tsx,jsx}")

Find test files

glob(pattern="**/*.{test,spec}.{ts,js}")

Find config files

glob(pattern="*.{json,yaml,yml,toml}")

Search specific directory

glob(pattern="**/*.ts", path="src/tools")

Find markdown files

glob(pattern="**/*.md")

Common patterns

Find by extension

# Single extension
glob(pattern="**/*.js")

# Multiple extensions
glob(pattern="**/*.{js,ts,jsx,tsx}")

Find by directory

# Specific directory
glob(pattern="src/**/*.ts")

# Multiple directories
glob(pattern="{src,tests}/**/*.ts")

Find by name pattern

# Files starting with "test"
glob(pattern="**/test*.ts")

# Files ending with "spec"
glob(pattern="**/*spec.ts")

# Files containing "util"
glob(pattern="**/*util*.ts")

Exclude patterns

Use .gitignore or .ignore files to exclude patterns:
node_modules/
dist/
build/
*.log
The glob tool respects these files automatically.

Safety limits

Timeout

Commands timeout after 60 seconds:
Error: Timeout after 60000ms
Refine your pattern or search a smaller directory.

File limit

Results are limited to 100 files:
Found 500 files matching "**/*.js" (showing newest 100)

[Results truncated to 100 files. Refine your pattern for full results.]
Refine your pattern to get more specific results.

Sorting

Results are sorted by modification time (newest first):
src/tools/glob/tools.ts           (modified 1 minute ago)
src/tools/grep/tools.ts           (modified 5 minutes ago)
src/agents/explore/index.ts       (modified 1 hour ago)
This helps surface recently changed files first.

Ripgrep integration

The tool uses ripgrep’s --files mode with glob filtering:
rg --files --glob 'pattern' path
Ripgrep is fast because it:
  • Respects .gitignore automatically
  • Uses parallel directory traversal
  • Skips binary files
  • Handles large codebases efficiently

Auto-installation

If ripgrep is not found, the tool attempts to auto-install:
  1. Checks for rg in PATH
  2. If not found, downloads platform-specific binary
  3. Installs to ~/.local/bin/rg
  4. Retries command
Supported platforms:
  • Linux x64/arm64
  • macOS x64/arm64
  • Windows x64

Error handling

Ripgrep not found

Error: ripgrep not found. Install ripgrep or add it to PATH.
Install ripgrep:
# macOS
brew install ripgrep

# Ubuntu/Debian
sudo apt install ripgrep

# Fedora
sudo dnf install ripgrep

# Windows
winget install BurntSushi.ripgrep.MSVC

Invalid pattern

Error: invalid glob pattern
Check your glob syntax. Common mistakes:
  • Missing quotes: **/*.ts (wrong) vs "**/*.ts" (right)
  • Invalid regex: [a- (unclosed bracket)

Permission denied

Error: Permission denied
Check directory permissions or use a different search path.

Performance tips

Be specific

Instead of:
glob(pattern="**/*")
Use:
glob(pattern="src/**/*.ts")

Use file extensions

Instead of:
glob(pattern="**/auth*")
Use:
glob(pattern="**/auth*.ts")

Search subdirectories

Instead of:
glob(pattern="**/*.ts")
Use:
glob(pattern="**/*.ts", path="src/tools")

Comparison with find

Glob tool vs Unix find command:
Featureglobfind
SpeedVery fast (ripgrep)Slower
GitignoreAutomaticManual
SortingBy mtimeManual
Limits100 files, 60sNone
SyntaxGlob patternsComplex expressions
For most use cases, glob is faster and easier.

Implementation details

CLI execution

Executes ripgrep via runRgFiles():
const result = await runRgFiles(
  {
    pattern: args.pattern,
    paths: [searchPath],
  },
  cli
)

Result formatting

Results are formatted by formatGlobResult():
  • Sorts by modification time
  • Truncates to 100 files
  • Adds context messages
  • Handles empty results

Thread limiting

Ripgrep thread count is limited to prevent resource exhaustion on large codebases.
  • grep - Search file contents
  • bash - Execute shell commands
  • read - Read file contents

Build docs developers (and LLMs) love