Agent tools

edit

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.

category: writeexact matchkeeps the old version
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

pathstringrequired

The file.

old_stringstringrequired

What to replace. Exact, whitespace included.

new_stringstringrequired

What to put there.

replace_allbooleanfalse

Replace every occurrence instead of requiring one.

Read the file 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

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

Use multi_edit: one call, applied in order, all or nothing. Several edit calls on one file cost a turn each.