edit_file
Replace exact text in files with transactional edits, validating all changes in memory and writing atomically to prevent partial file states. Supports dry-run and SHA-256 verification.
Instructions
Replace exact text in an existing UTF-8 file. Supply either old_text/new_text or an edits array. Array edits are validated in memory then written atomically, so a failed edit never leaves a partial file.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path relative to the workspace root, or an allowed absolute path. | |
| edits | No | Transactional sequence of edits; all succeed or none are written. | |
| dry_run | No | Report what would change without writing the file. | |
| new_text | No | Replacement text. | |
| old_text | No | Exact text to find, copied verbatim from read_file output. | |
| replace_all | No | Replace every occurrence; defaults to false. | |
| expected_sha256 | No | Optional SHA-256 returned by a previous read or write. The call fails if the file changed since then. | |
| expected_replacements | No | Require exactly this many occurrences. |