1Make multiple edits to a single file in one operation. Prefer over `edit` for multiple changes.
2
3<when_to_use>
4Use MultiEdit when:
5- 2+ changes to the same file
6- Changes are in different parts of the file
7- Want atomic success/failure per edit
8
9Do NOT use MultiEdit when:
10- Single change → use `edit`
11- Different files → use separate `edit` calls
12- Complete rewrite → use `write`
13</when_to_use>
14
15<parameters>
16- file_path: Absolute path (required)
17- edits: Array of {old_string, new_string, replace_all} objects
18</parameters>
19
20<critical_rules>
211. **View first**: Read the file before editing
222. **Exact match**: Same rules as `edit` - whitespace matters
233. **Sequential**: Edits apply in order; each operates on result of previous
244. **Partial success**: If edit #2 fails, edit #1 is still applied
255. **Plan ahead**: Earlier edits change content that later edits must match
26</critical_rules>
27
28<common_mistake>
29Edit #1 adds a blank line. Edit #2 tries to match old content that no longer exists:
30
31```
32❌ Wrong:
33edits: [
34 { old_string: "func A() {", new_string: "func A() {\n" }, // Adds newline
35 { old_string: "func A() {", new_string: "..." } // Fails - content changed!
36]
37```
38</common_mistake>
39
40<recovery>
41If some edits fail:
421. Check response for failed edits list
432. `view` file to see current state
443. Retry failed edits with corrected old_string
45</recovery>
46
47<example>
48Rename function and update its call site:
49```
50edits: [
51 {
52 old_string: "func oldName() {\n return nil\n}",
53 new_string: "func newName() {\n return nil\n}"
54 },
55 {
56 old_string: "result := oldName()",
57 new_string: "result := newName()"
58 }
59]
60```
61</example>