edit
Make cache-aware exact replacements in files. Use find/replace or line-range edit to modify specific content while preserving the rest.
Instructions
Edit one file using cache-aware exact replacement.
Prefer this over write when you want to preserve the rest of the file.
Use line numbers from read whenever possible to keep the edit precise.
Modes:
Find/replace:
old_string+new_stringScoped replace: add
start_line+end_lineLine-range replace: omit
old_string, providestart_line+end_line
Routing rules:
One localized change: use
editMultiple independent changes in the same file: use
batch_editFull-file rewrite: use
write
Precision rules:
Keep
old_stringexact and as short as possible, ideally one line.If a match is ambiguous, add more context or line bounds.
Use
replace_all=trueonly when every match should change.Deterministic successful edits omit full diffs unless
show_diff=trueor debug mode is enabled.
Args: path: File path to modify. old_string: Exact text to find. Omit only for line-range replacement. new_string: Replacement text. replace_all: Replace all matches instead of requiring uniqueness. dry_run: Preview without writing. auto_format: Run formatter after editing. show_diff: Return the diff explicitly for successful deterministic edits. start_line: 1-based inclusive start line for scoped or line-range edit. end_line: 1-based inclusive end line for scoped or line-range edit.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | ||
| old_string | No | ||
| new_string | No | ||
| replace_all | No | ||
| dry_run | No | ||
| auto_format | No | ||
| show_diff | No | ||
| start_line | No | ||
| end_line | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| truncated | No | ||
| status | No | ||
| path | No | ||
| replaced | No | ||
| line_numbers | No | ||
| diff | No | ||
| diff_state | No | ||
| diff_omitted | No | ||
| tokens_saved | No | ||
| diff_stats | No | ||
| content_hash | No | ||
| from_cache | No | ||
| params | No |