Search and Replace
replace_textFind and replace literal text or regex patterns in a file or across a directory, with glob filters, dry-run preview, and diff output.
Instructions
Find and replace every occurrence of literal text or an RE2 regex, like sed -i, in one file or all files under a directory, optionally filtered by glob. The pattern runs over the whole file: it can span lines, and ^ and $ anchor to file start and end. edit replaces one unique exact match.
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). |