Edit
editReplace file content by exact text matching, with scoped line ranges, replace-all, and dry-run preview to avoid unintended changes.
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 and the affected line numbers, and refreshes the cache.
The diff itself is omitted unless you ask for it with show_diff;
diff_state always tells you which you got. A dry_run writes nothing
and says so: the status is would_edit and dry_run: true comes back
with it. For several edits to
one file use batch_edit; for a full rewrite use write.
Pass known_hash and the response carries a claimable content_hash, so
no read is needed afterwards. Without it, or with auto_format, you get
file_hash instead — editing a file is not the same as having read it.
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. | |
| known_hash | No | The `content_hash` from your last read of this file. Proves you hold the text being edited, so the result can be handed back as a claimable `content_hash`. | |
| 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. |