# edit

Canonical URL: https://developers.iagenify.com/sdk/agent/tools/edit/
Language: en

`edit({ path, old_string, new_string, replace_all? })`

Replace an exact string in a file. It must match exactly — including whitespace — and be unique unless you say otherwise.

Status: category: write · exact match · keeps the old version

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `path` | string | required | The file. |
| `old_string` | string | required | What to replace. Exact, whitespace included. |
| `new_string` | string | required | What to put there. |
| `replace_all` | boolean | false | Replace every occurrence instead of requiring one. |

## Read the file first {#read-first}

> **Indentation is part of the match**
>
> A string copied from memory rather than from the file usually differs by a space or a tab, and the edit fails. The instruction to read before editing is in the system prompt for that reason — and a failed edit costs a turn.

## Unique, unless replace_all {#unique}

A string appearing twice is refused: replacing one of two identical passages is ambiguous, and guessing which would be worse than failing. Add more surrounding context to make it unique, or set `replace_all`.

## Several edits in one file {#several}

Use [multi_edit](/sdk/agent/tools/multi-edit): one call, applied in order, all or nothing. Several `edit` calls on one file cost a turn each.

- [multi_edit](/sdk/agent/tools/multi-edit): Several replacements at once.
- [read](/sdk/agent/tools/read): What to do first.
- [Agent tools](/sdk/agent/tools): The 35, by family.
