Overview
The MultiEdit tool applies multiple edits to a single file in one operation. It’s built on top of the Edit tool and follows the same exact-matching rules. Use MultiEdit instead of multiple Edit calls when making several changes to the same file.Parameters
string
required
The absolute path to the file to modify. Relative paths are resolved from the working directory.
array
required
Array of edit operations to apply sequentially. Each edit contains:
old_string- Text to find and replacenew_string- Replacement textreplace_all- (optional) Replace all occurrences
Edit Operation Structure
Features
Sequential Application
Edits are applied in order, with each edit operating on the result of the previous edit:Partial Success
If some edits fail, successful edits are still applied:- See which edits succeeded
- Get error details for failed edits
- Retry failed edits with corrected parameters
File Creation
The first edit can create a new file by having an emptyold_string:
- Only the first edit can have empty
old_string - File must not already exist
- Subsequent edits work on the created content
Critical Requirements
All Edit Tool Rules Apply
Every single rule from the Edit tool applies to each edit:- ✅ Exact whitespace matching
- ✅ Indentation precision
- ✅ Blank line matching
- ✅ Uniqueness requirements
- ✅ Context inclusion
- ✅ Character-for-character matching
Sequential Context
Each edit changes the file content for the next edit: Example - Planning Ahead:Verification Requirements
Before submitting MultiEdit:- View the file to understand current state
- Plan the sequence - mentally apply each edit
- Check for conflicts - will edit N affect edit N+1?
- Verify uniqueness of each
old_stringat its application time - Include context for each edit (3-5 lines)
- Double-check whitespace for every edit
Usage Examples
Multiple Function Modifications
Rename Multiple Occurrences
Add Multiple Imports
Create and Populate File
Best Practices
Planning Edits
- Read the file first with View tool
- List all changes you want to make
- Order edits from top to bottom of file (usually safest)
- Check for conflicts between edits
- Dry-run mentally - simulate each edit
Independent vs Dependent Edits
Independent edits (safe to combine):Handling Failures
- Check response metadata for failed edits
- View the file to see current state after successful edits
- Adjust failed edits based on new content
- Retry failed edits with corrected
old_string - Consider breaking complex batches into smaller operations
Error Handling
Some Edits Failed
Response includes details:- View the file to see current state
- Note which edits succeeded
- Adjust the failed edit’s
old_string - Retry with corrected edit
All Edits Failed
If no edits succeed:- File content doesn’t match expectations
- Whitespace mismatches
- Wrong file
- File modified externally
Edit Validation Errors
- Only edit #1 can have empty
old_string - Other edits must provide
old_string
Permissions
MultiEdit requires permission for all write operations. You can pre-approve:LSP Integration
After applying edits, Crush automatically:- Notifies LSP servers about file changes
- Waits for diagnostics
- Includes diagnostics in response
Whitespace Checklist
For EACH edit in the array, verify:- Viewed the file first
- Counted indentation spaces/tabs
- Included blank lines if present
- Matched brace/bracket positioning
- Included 3-5 lines of context
- Verified text appears exactly once (or using replace_all)
- Copied character-for-character, not approximated
- Considered impact on subsequent edits
Common Pitfalls
Pitfall 1: Not Accounting for Previous Edits
❌ Wrong:Pitfall 2: Edits Conflict
❌ Wrong:Pitfall 3: Wrong Order
❌ Wrong:MultiEdit vs Multiple Edits
Use MultiEdit When:
- ✅ Multiple changes to same file
- ✅ Changes are independent or carefully planned
- ✅ Want atomic operation (partial success acceptable)
- ✅ Reducing round trips to file system
Use Multiple Edit Calls When:
- ✅ Changes to different files
- ✅ Unsure about edit sequence
- ✅ Want all-or-nothing behavior
- ✅ Edits are complex and error-prone
Example Comparison
Multiple Edit calls:- ✅ Makes one file write instead of two
- ✅ Provides aggregate diff
- ✅ Allows partial success
- ❌ Requires more careful planning