grep_text_files
Search file contents using regex, including non-UTF-8 encodings. Match multiple patterns in one pass and output lines, filenames, or counts.
Instructions
Regex search in file contents with encoding support. PREFER THIS over built-in Grep for non-UTF-8 files. Skips .gitignore'd files (respectGitignore=false to include). Parameters: pattern (regex) or patterns (array), paths (array of files, or dirs searched recursively), caseSensitive (default true), contextBefore/After, maxMatches (default 1000), offset, include/includes, exclude/excludes, encoding. patterns finds ANY of several regexes in ONE pass — sweeping a codebase for a list of names is one call, not one per name. outputMode: "content" (default, matching lines), "files_with_matches" (paths only, far cheaper when you just need WHICH files), "count" (matching lines per file). contextBefore/After apply to content mode only. matchesOnly=true returns the matched substring instead of the whole line, for extracting values — with patterns it also tells you which one hit. offset skips the first N results, so you can page past maxMatches; the response echoes nextOffset when truncated. Include and exclude patterns are basename-only globs; {a,b} alternatives work and a leading **/ is ignored. Includes match any pattern and excludes reject any match. Do not combine a singular field with its plural. Example: {"patterns": ["TCustomer", "TOrder"], "paths": ["D:\proj\src"], "includes": [".pas", ".dfm"], "outputMode": "files_with_matches"}
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| paths | Yes | ||
| offset | No | ||
| exclude | No | ||
| include | No | ||
| pattern | Yes | ||
| encoding | No | ||
| excludes | No | ||
| includes | No | ||
| patterns | No | ||
| maxMatches | No | ||
| outputMode | No | ||
| matchesOnly | No | ||
| contextAfter | No | ||
| caseSensitive | No | ||
| contextBefore | No | ||
| respectGitignore | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| hint | No | ||
| files | No | ||
| counts | No | ||
| matches | Yes | ||
| truncated | No | ||
| nextOffset | No | ||
| filesMatched | Yes | ||
| totalMatches | Yes | ||
| filesSearched | Yes |