Search and Replace
replace_textReplace every occurrence of literal text or an RE2 regex in one file or a directory tree, with dry-run previews and optional diffs for bulk edits.
Instructions
Replace every match of literal text or an RE2 regex in one file or across a directory tree. Use when the same change must land at every occurrence. Do not use it for one unique snippet; use edit instead, patch for a unified diff, or search_text to only find matches. A live run rewrites each file as the scan reaches it; one failed file does not stop the others. Reaching maxMatches (default 100), maxFiles, or the deadline stops the run; files already rewritten stay changed. Returns changed paths, failures, skip counts, stoppedReason, and an undo id (live runs, when undo is enabled) for undo, valid 30 minutes. isError is set when every file failed or the request is invalid (bad regex, path outside roots).
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"searchPattern": "<searchPattern>",
"replacement": "<replacement>"
},
"name": "replace_text"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | File or directory to rewrite. A named file ignores pattern, hidden, and gitignore filters, and fails if binary or too large. Omitted, it targets the ENTIRE single root (required with several roots); try a wide scope with dryRun=true first | |
| dryRun | No | Preview without writing. Always returns the diff, never an undo id. | |
| exclude | No | Globs for entries to leave out, with everything under a matching folder. Without / a pattern matches a name at any depth (vendor, *.test.ts); with / it matches the path relative to path. | |
| isRegex | No | Treat searchPattern as an RE2 regex and expand $1, $<name>, and $& in replacement (default: literal text match) | |
| pattern | No | Glob limiting which files under a directory path are rewritten (e.g. **/*.ts). Without /, it matches file names at any depth. Ignored when path names a file | |
| maxDepth | No | Max directory depth. 0 scans only the base directory. Omit for no limit. | |
| maxFiles | No | Stops after this many files scanned, counting files with no match; reports stoppedReason=maxFiles (default: no limit) | |
| wholeWord | No | Match whole words only | |
| maxMatches | No | Maximum matches replaced across all files (default: 100). Setting it makes the scan sequential and exact. | |
| returnDiff | No | Include the unified diff in a live run. Cut at 20 KB. | |
| replacement | Yes | Replacement text. An empty string deletes matches. | |
| caseSensitive | No | Match case exactly. Unlike search_text, defaults to true. | |
| includeHidden | No | Include hidden items (starting with .) | |
| searchPattern | Yes | Literal text or RE2 regex to find; can span lines. With isRegex=true, ^ and $ match per line (\A and \z for the whole file); no lookaround or backreferences. All-CRLF files match as LF: write \n. | |
| includeIgnored | No | Include ignored items (node_modules, .git, etc). |