internal/agent/tools/multiedit.md
Apply multiple find-and-replace edits to a single file in one operation; edits run sequentially. Prefer over edit for multiple changes to the same file. Same exact-match rules as edit apply.
<prerequisites> 1. Use View tool to understand file contents and context 2. Verify directory path is correct 3. CRITICAL: Note exact whitespace, indentation, and formatting from View output </prerequisites> <parameters> 1. file_path: Absolute path to file (required) 2. edits: Array of edit operations, each containing: - old_string: Text to replace (must match exactly including whitespace/indentation) - new_string: Replacement text - replace_all: Replace all occurrences (optional, defaults to false) </parameters> <operation> - Edits applied sequentially in provided order. - Each edit operates on result of previous edit. - PARTIAL SUCCESS: If some edits fail, successful edits are still applied. Failed edits are returned in the response. - File is modified if at least one edit succeeds. - Ideal for several changes to different parts of same file. </operation><inherited_rules> All instructions from the Edit tool documentation apply verbatim to every edit item:
<critical_requirements>
<verification_before_using>
<recovery_steps> If some edits fail:
<best_practices>
<whitespace_checklist> For EACH edit, verify:
edits: [
{
old_string: "func A() {\n doOld()\n}",
new_string: "func A() {\n doNew()\n}",
},
{
// Uses context that still exists AFTER the first replacement
old_string: "func B() {\n callA()\n}",
new_string: "func B() {\n callA()\n logChange()\n}",
},
]
❌ Incorrect: Second old_string no longer matches due to whitespace change introduced by the first edit
edits: [
{
old_string: "func A() {\n doOld()\n}",
new_string: "func A() {\n\n doNew()\n}", // Added extra blank line
},
{
old_string: "func A() {\n doNew()\n}", // Missing the new blank line, will FAIL
new_string: "func A() {\n doNew()\n logChange()\n}",
},
]
✅ Correct: Handling partial success
// If edit 2 fails, edit 1 is still applied
// Response will indicate:
// - edits_applied: 1
// - edits_failed: [{index: 2, error: "...", edit: {...}}]
// You can then retry edit 2 with corrected context