update_file
Performs targeted search-and-replace operations on an existing file using {search, replace} blocks, optionally with regex. Ideal for localized updates without overwriting the entire file.
Instructions
Performs targeted search-and-replace operations within an existing file using an array of {search, replace} blocks. Preferred for smaller, localized changes. For large-scale updates or overwrites, consider using write_file
. Accepts relative or absolute paths. File must exist. Supports optional useRegex
(boolean, default false) and replaceAll
(boolean, default false).
Input Schema
Name | Required | Description | Default |
---|---|---|---|
blocks | Yes | An array of objects, each with a `search` (string) and `replace` (string) property. | |
path | Yes | The path to the file to update. Can be relative or absolute (resolved like readFile). The file must exist. | |
replaceAll | No | If true, replace all occurrences matching the SEARCH criteria within the file. If false, only replace the first occurrence. Defaults to false. | |
useRegex | No | If true, treat the `search` field of each block as a JavaScript regular expression pattern. Defaults to false (exact string matching). |