edit
Replace exact text in files using find/replace, scoped, or line-range modes. Returns diff and updates cache.
Instructions
Edit one file by exact text replacement.
Three modes:
find/replace:
old_string+new_string(the default).scoped: add
start_line/end_lineto confine the search to a range.line-range: omit
old_stringand give both lines to replace them wholesale.
old_string must match exactly — whitespace and indentation included —
and, unless replace_all=true, must be unique, or the edit fails. Use
edit_preview first if you're unsure an anchor is unique. Returns the
replacement count, affected line numbers, and a unified diff, and refreshes
the cache. For several edits to one file use batch_edit; for a full
rewrite use write.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | File path to modify (absolute, or relative to root). | |
| dry_run | No | Preview without writing. | |
| end_line | No | 1-based inclusive end line for a scoped or line-range edit. | |
| show_diff | No | Return the diff even on a deterministic edit. | |
| new_string | No | Replacement text (an empty string deletes the match). | |
| old_string | No | Exact text to find. Omit only for a line-range replacement. | |
| start_line | No | 1-based inclusive start line for a scoped or line-range edit. | |
| auto_format | No | Run the formatter after editing. | |
| replace_all | No | Replace every occurrence instead of requiring a unique match. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| diff | No | ||
| path | No | ||
| params | No | ||
| status | No | ||
| replaced | No | ||
| truncated | No | ||
| diff_state | No | ||
| diff_stats | No | ||
| from_cache | No | ||
| content_hash | No | ||
| diff_omitted | No | ||
| line_numbers | No | ||
| tokens_saved | No |