replace_text_in_file
Replace an exact text occurrence in a workspace file, with optional replace-all and case matching. Use dry_run to preview changes before writing through the open editor or disk.
Instructions
Replace text in a workspace text file as the window shows it, saved or not. old_text must occur exactly once unless replace_all is true; none or several occurrences are an error naming the count and the 1-based lines, and nothing changes. case_sensitive defaults to true. Returns replacements, the 1-based lines of the replaced places and applied. dry_run defaults to true; dry_run=false needs the user-granted write right and writes through the open editor as one undo step, or to the disk when the file is not open.
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": {
"path": "<path>",
"old_text": "<old_text>",
"new_text": "<new_text>"
},
"name": "replace_text_in_file"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Workspace-relative text file. | |
| dry_run | No | Only report what would change (default true); false writes, which needs the `write` right. | |
| new_text | Yes | What it becomes. | |
| old_text | Yes | The text to replace (not empty). | |
| replace_all | No | Replace every occurrence (default false: the text must occur exactly once). | |
| case_sensitive | No | Match case (default true). |