grep_files
Search file contents with regex to find matching lines, counts, or filenames, with optional context and filters.
Instructions
Search text patterns within file contents using regex. Returns matching line numbers and context - use with read_file/read_multiple_files to retrieve actual content. Supports: regex patterns, case-insensitive (-i), context lines (-A/-B/-C), file type filters (type: js/py/ts/etc), glob patterns, multiline mode. Output modes: content (lines+context), files_with_matches (paths only), count (match counts). Respects ignored folders. Use head_limit to cap results. Only searches within allowed directories.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| -A | No | Lines after match | |
| -B | No | Lines before match | |
| -C | No | Lines before+after match | |
| -i | No | Case insensitive | |
| glob | No | Glob filter. Without a slash it matches file names at any depth (*.md, *.test.ts); with a slash it matches the path relative to the search root (src/**/*.ts) | |
| path | No | Directory/file to search (optional) | |
| type | No | File type filter: js, py, ts, etc | |
| pattern | Yes | Regex pattern to search for | |
| multiline | No | Allow . to match newlines | |
| head_limit | No | Limit results to N | |
| output_mode | No | content|files_with_matches|count | content |