Edit a file
edit_fileReplace exact text in a file without rewriting it, keeping permissions and uniqueness checks; reports where the closest match differs instead of applying a near match.
Instructions
Change part of a text file: replace old_string (exact, whitespace included, unique unless replace_all) with new_string; atomic, keeps permissions. Refuses what write_file refuses. If old_string is not there, it says where the closest text is and how it differs; it never applies a near match. Prefer this to rewriting a file with write_file.
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_string": "<old_string>",
"new_string": "<new_string>"
},
"name": "edit_file"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| why | No | one line in plain words: what this does and why (logged). With outside_sandbox: what the user asked for that the sandbox blocked | |
| path | Yes | the file: absolute, ~/..., or relative to the home folder | |
| new_string | Yes | the text to put in its place | |
| old_string | Yes | the exact text to replace, whitespace and line breaks included | |
| replace_all | No | replace every occurrence (default false: old_string must occur exactly once) |