Apply changes
apply_changesApply line-addressed file changes atomically by naming each action and path, using read_file revisions to safely create, edit, delete, move, or copy files.
Instructions
Apply line-addressed file changes atomically. Prefer this over apply_patch when you know the line numbers: nothing has to match. Each change names an action (create, write, edit, delete, move, copy), and a path. write is an upsert: it needs the revision read_file reported when the path exists, but may omit it when creating a missing path. edit, delete, move, and copy always need that revision; create rejects it and asserts absence. edit takes line operations (replace, delete, insert_after, insert_before) whose numbers all refer to the file as read, not to the result of earlier edits in the same call. content is whole lines: "" is zero lines and a trailing newline adds a blank line. One path per call; use apply_patch to chain several edits onto one file. Example: {"changes":[{"action":"edit","path":"app.py","revision":"","edits":[{"op":"replace","start_line":10,"end_line":12,"content":"new line"}]}]}
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| changes | Yes | One entry per file, at least one. A path may appear once per call; use apply_patch to chain several edits onto one file. The whole request must fit in 1 MiB, so keep it to roughly 20 files per call. | |
| dry_run | No | ||
| idempotency_key | No | Names this exact request so a retry after a lost response replays the recorded result (flagged idempotent_replay) instead of doing the work twice. Use a new key for new work: the key is bound to the arguments that first used it, and reusing it with any other argument — including a different dry_run — is refused with IDEMPOTENCY_KEY_REUSED. Only a successful non-dry-run result is recorded, and only the 64 most recently used keys are kept across all tools. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ok | Yes | ||
| clean | No | ||
| error | No | ||
| dry_run | No | ||
| summary | No | ||
| removals | No | ||
| warnings | No | ||
| additions | No | ||
| affected_files | No | ||
| already_applied | No | ||
| idempotent_replay | No | ||
| revision_algorithm | No |