Search and Replace
replace_textReplace every occurrence of a text or regex pattern in all files matching a glob, with optional diff preview before writing.
Instructions
Bulk search-and-replace across files matching a glob pattern. Replaces ALL occurrences per file (unlike edit, which replaces only the first match). Set returnDiff=true to preview changes as a unified diff before or after writing. Literal matching by default; set isRegex=true to enable RE2 regex with capture groups ($1, $2).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | File to rewrite, or directory to rewrite under. Omitting it targets the ENTIRE first allowed root — scope it deliberately, and pair a wide scope with dryRun=true first | |
| dryRun | No | Preview replacements without writing to disk (default: false = apply changes) | |
| isRegex | No | Treat searchPattern as a RE2 regex (default: literal text match) | |
| pattern | No | Glob to restrict replacements to specific file types (e.g. **/*.ts); default: all text files | |
| maxDepth | No | Max directory depth to scan; 0 = base directory only, omit for unlimited | |
| maxFiles | No | Maximum number of files to process | |
| wholeWord | No | Match whole words only (word boundary anchoring) | |
| maxResults | No | Maximum total match count across all files before stopping | |
| returnDiff | No | Include a unified diff of all changes in the response | |
| replacement | Yes | Replacement text. Use capture group references ($1, $2, etc.) when isRegex=true. Use an empty string to delete all matches. | |
| caseSensitive | No | Enable case-sensitive matching (default: case-insensitive) | |
| includeHidden | No | Include hidden items (starting with .) | |
| searchPattern | Yes | Exact literal text or RE2 regex pattern to search for. When isRegex=true, uses RE2 syntax (no lookahead, lookbehind, or backreferences are supported). Cannot be empty or whitespace-only. | |
| includeIgnored | No | Include ignored items (node_modules, .git, etc). |