edit_file
Edit text and code files with intelligent matching strategies. Supports single-file or batch multi-file edits with dry-run preview and atomic rollback.
Instructions
Apply precise modifications to text and code files with intelligent matching.
Single File Editing (mode: 'single'): Edit one file with multiple sequential edits using exact, flexible, or fuzzy matching strategies.
Multi-File Editing (mode: 'multiple'): Edit multiple files concurrently in a single operation. Each file can have its own edit configuration.
Matching Strategies:
Exact: Character-for-character match (fastest, safest)
Flexible: Whitespace-insensitive, preserves original indentation
Fuzzy: Token-based regex matching for maximum compatibility
Features:
Concurrent processing for multi-file operations
Per-file matching strategy control
Dry-run preview mode
Detailed diff output with statistics
Atomic operations with rollback capability
Cross-platform line ending preservation
Maximum: 50 files per multi-file operation
Best Practices:
Include 3-5 lines of context before and after the change for reliability
Add 'instruction' field to describe the purpose of each edit
Use 'dryRun: true' to preview changes before applying
For multiple related changes, use array of edits (applied sequentially)
Set 'expectedOccurrences' to validate replacement count
Use 'matchingStrategy' to control matching behavior (defaults to 'auto')
CRITICAL - Multi-line Content:
Use actual newline characters in oldText/newText strings, NOT \n escape sequences
The MCP/JSON layer handles encoding automatically
Using \n literally will search for/write backslash+n characters (wrong!)
Only works within allowed directories.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| mode | No | Edit mode: 'single' for one file, 'multiple' for batch editing | single |
| path | No | Path to file (required for single mode) | |
| edits | No | Array of edits to apply | |
| files | No | Array of file edit requests (required for multiple mode) | |
| failFast | No | Stop processing on first file failure (true) or continue with remaining files (false) | |
| matchingStrategy | No | Matching strategy: - 'exact': Strict character-for-character match (fastest, safest) - 'flexible': Whitespace-insensitive line-by-line matching - 'fuzzy': Token-based regex matching (most permissive) - 'auto': Try exact → flexible → fuzzy (recommended, default) | auto |
| dryRun | No | Preview changes without writing | |
| failOnAmbiguous | No | If true, fail when oldText matches multiple locations (unless expectedOccurrences > 1). If false, replace first occurrence only and warn about ambiguity. |