Tools · Files and code

edit_file

Changes things

Apply an exact string replacement patch to an existing file.

When to use: Use this for surgical edits after reading the file. Prefer exact replacements over full rewrites.

Example

Run for real by scripts/tool-examples.py in a small demo project, with Haiku 5.5 where the tool calls a model. The output is exactly what the tool returned.

The call

tool call
{
  "tool": "edit_file",
  "arguments": {
    "path": "src/pricing.py",
    "old_text": "\"team\": 29.0}",
    "new_text": "\"team\": 29.0, \"enterprise\": 79.0}"
  }
}

Real output

File patched: <project>/src/pricing.py (1 occurrence replaced)
--- a/pricing.py
+++ b/pricing.py
@@ -1,5 +1,5 @@
 """Seat pricing for the demo app."""
 
-PLANS = {"starter": 12.0, "team": 29.0}
+PLANS = {"starter": 12.0, "team": 29.0, "enterprise": 79.0}

Parameters

NameTypeDescription
path*stringRelative file path
old_text*stringExact existing text to replace
new_text*stringReplacement text
replace_allbooleanReplace all matches instead of exactly one

* required

Read, search and edit the project; run commands, code and git.