batch_edit
Apply multiple exact edits to one file in a single, atomic call. Supports full-file, scoped, and line-range replacements with partial success handling.
Instructions
Apply multiple exact edits to one file in a single call.
Preferred over repeated edit calls on the same file: single response,
atomic across all edits, and faster on large files. For cross-file work,
call the relevant tools per file instead of trying to batch across files.
Supported entry forms:
[old, new]for full-file exact replacement[old, new, start_line, end_line]for scoped replacement[null, new, start_line, end_line]for line-range replacement{"old": ..., "new": ..., "start_line": ..., "end_line": ...}
Behavior:
Partial success is allowed.
Failed edits are returned so you can retry only the misses.
Prefer line-range entries when you already have line numbers from
read.Deterministic all-success batches omit full diffs unless
show_diff=trueor debug mode is enabled.
Args: path: File path to modify. edits: JSON array of edit entries for that file. dry_run: Preview without writing. auto_format: Run formatter after edits. show_diff: Return the diff explicitly for successful deterministic batches.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | ||
| edits | Yes | ||
| dry_run | No | ||
| auto_format | No | ||
| show_diff | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| truncated | No | ||
| status | No | ||
| path | No | ||
| succeeded | No | ||
| failed | No | ||
| failures | No | ||
| diff | No | ||
| diff_state | No | ||
| diff_omitted | No | ||
| tokens_saved | No | ||
| outcomes | No | ||
| diff_stats | No | ||
| content_hash | No | ||
| from_cache | No | ||
| params | No |