glob - Find Files
Overview
The glob tool efficiently finds files matching specific glob patterns (e.g., src/**/*.ts, **/*.md), returning absolute paths sorted by modification time (newest first). Ideal for quickly locating files based on their name or path structure, especially in large codebases.
Tool Name
- Internal Name:
glob - Display Name: FindFiles
- Icon: FileSearch
Parameters
Required Parameters
| Parameter | Type | Description |
|---|---|---|
pattern | string | The glob pattern to match against (e.g., **/*.py, docs/*.md). |
Optional Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | The absolute path to the directory to search within. If omitted, searches the root directory. |
case_sensitive | boolean | Whether the search should be case-sensitive. Defaults to false. |
respect_git_ignore | boolean | Whether to respect .gitignore patterns when finding files. Only available in git repositories. Defaults to true. |
Features
Glob Pattern Matching:
- Supports standard glob syntax
- Can match filenames and paths
- Supports multi-level directory matching
Sorting:
- Sorted by modification time (newest first)
- Recently modified files appear first
- Older files sorted alphabetically
Filtering:
- Optional
.gitignorerespect - Case-sensitive/insensitive search support
- Automatically excludes common ignore directories
- Optional
Performance Optimization:
- Efficient filesystem traversal
- Suitable for large codebases
- Fast file location
Glob Pattern Syntax
Basic Wildcards
*: Matches any characters (excluding directory separator)- Example:
*.jsmatches all JavaScript files
- Example:
**: Matches any characters (including directory separator)- Example:
src/**/*.tsmatches all TypeScript files under src
- Example:
?: Matches a single character- Example:
file?.txtmatches file1.txt, fileA.txt, etc.
- Example:
[abc]: Matches any character in brackets- Example:
file[123].txtmatches file1.txt, file2.txt, file3.txt
- Example:
{a,b}: Matches any pattern in braces- Example:
*.{js,ts}matches all .js and .ts files
- Example:
Common Pattern Examples
**/*.ts # All TypeScript files
src/**/*.test.js # All test files under src
docs/*.md # Markdown files in docs directory
**/*config*.json # All JSON files containing 'config'
lib/**/*.{js,ts} # All JS and TS files under libUsage Examples
Find All TypeScript Files
json
{
"pattern": "**/*.ts"
}Search in Specific Directory
json
{
"pattern": "*.md",
"path": "/home/user/project/docs"
}Case-Sensitive Search
json
{
"pattern": "**/*.Test.ts",
"case_sensitive": true
}Ignore .gitignore Rules
json
{
"pattern": "**/*.log",
"respect_git_ignore": false
}Find Multiple File Types
json
{
"pattern": "**/*.{js,ts,jsx,tsx}"
}Return Value
The tool returns an object containing:
llmContent: List of absolute paths to matching filesreturnDisplay: User-friendly display informationsummary: Operation summary (e.g., "Found 25 files matching pattern")
Return Format
Found 3 file(s) matching "**/*.ts":
/home/user/project/src/main.ts (modified: 2024-01-15)
/home/user/project/src/utils.ts (modified: 2024-01-14)
/home/user/project/src/types.ts (modified: 2024-01-10)Error Handling
Possible error scenarios:
Path Errors:
- Search path does not exist
- Search path is not a directory
- Search path is outside project root
Pattern Errors:
- Pattern is empty or invalid
- Pattern syntax error
Parameter Errors:
- Missing required parameters
- Incorrect parameter types
Sorting Rules
Files are sorted by the following rules:
Recent Files First:
- Files modified within recent threshold (default 30 days)
- Sorted by modification time, newest to oldest
Older Files Alphabetically:
- Files beyond recent threshold
- Sorted alphabetically by path
Performance Considerations
Large Codebases:
- Tool is optimized for large codebases
- Uses efficient filesystem traversal
Pattern Complexity:
- Simple patterns (like
*.js) are faster than complex ones **wildcard recursively searches all subdirectories
- Simple patterns (like
Ignore Rules:
- Respecting
.gitignorecan improve performance - Automatically skips common large directories (node_modules, etc.)
- Respecting
Notes
- Path Format: Returned paths are always absolute
- Symbolic Links: Does not follow symbolic links by default
- Hidden Files: Includes hidden files (starting with
.) by default - Permissions: Requires read permission for directories
Differences from Other Tools
- vs list_directory:
globsupports recursive search and pattern matching,list_directoryonly lists a single directory - vs search_file_content:
globsearches by filename/path,search_file_contentsearches by file content
Related Tools
list_directory: List directory contentssearch_file_content: Search file contentread_file: Read fileread_many_files: Read multiple files in batch
