edit_file
Replace an exact string in an existing file to make precise code changes while preserving the rest of the file. Handles line endings and requires unique matches, with replace_all option.
Instructions
Replace an exact string in an existing text file.
Preferred over write_file for changing existing code: only the named region moves, so the rest of the file cannot be lost to a truncated generation.
old_string must match EXACTLY, including indentation, and must be
unique in the file. If it appears more than once the edit is refused
rather than guessed at -- include a surrounding line or two to
disambiguate, or pass replace_all.
Line endings are handled for you: the file's own convention is detected and preserved, and CRLF/LF differences between your strings and the file are ignored when matching. So a CRLF file can be edited with plain "\n" strings and stays CRLF.
Edits are confined to the download root plus any directory listed in BIONIC_PROJECT_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": {
"path": "<path>",
"old_string": "<old_string>",
"new_string": "<new_string>"
},
"name": "edit_file"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | ||
| new_string | Yes | ||
| old_string | Yes | ||
| replace_all | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |