Search and Replace
replace_textSearch and replace text across multiple files using glob patterns. Replace all occurrences per file, with optional regex, dry-run preview, and unified diff output.
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). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| diff | No | Unified diff of all changes (present when returnDiff=true or dryRun=true) | |
| results | Yes | Per-file results: modified files, then any that could not be processed | |
| summary | Yes | ||
| filesScanned | Yes | Total number of files examined | |
| totalMatches | Yes | Total number of replacements made across all files | |
| diffTruncated | No | True when the diff was cut due to the size limit | |
| stoppedReason | No | Why enumeration stopped early: maxResults = match cap reached, maxFiles = file cap reached, timeout = time limit hit or cancelled. Absent when every matching file was enumerated. Marks the sweep incomplete, not the writes; files already dispatched still complete. | |
| resultsTruncated | No | True when the results list holds fewer entries than summary.total: the changed-file or failed-file cap was hit. Trust summary over results.length. |