# `edit_file` Replace an exact piece of text in a file, leaving the rest alone. **Input** — `path` (required), `old_string` (required), `new_string` (optional), `replace_all` (optional, default false) `write_file` overwrites a whole file, so changing one line means reproducing every other one — expensive on a large file and easy to get subtly wrong. This edits in place. `old_string` is matched **literally**, whitespace and indentation included. It must appear exactly once, or the call is refused: include enough surrounding lines to pick out one site. `replace_all` drops the exactly-once rule and changes every occurrence. An empty `new_string` deletes the matched text. The match is not a diff or patch format. Those need context lines and line numbers that drift as the file changes, and a fuzzy match that silently picks the wrong site is worse than a failure. Literal matching gives a clear error instead. The result carries a coloured diff, the same as `write_file`. ## What it refuses **Text that isn't there**, naming the file and pointing at whitespace and indentation as the usual cause. **Text that appears more than once** without `replace_all`, reporting how many times it matched. **Identical old and new strings**, which would be a no-op.