apply_patch
Applies unified diffs, Codex Begin Patch envelopes, or Aider SEARCH/REPLACE blocks to modify files. Supports exact-match replacement, file deletes, and three-way merges for stale context.
Instructions
Apply a unified diff, a Codex *** Begin Patch document, or an Aider SEARCH/REPLACE / DiffFenced document. The diff parameter is the full unified diff text, a *** Begin Patch ... *** End Patch envelope (Add/Update/Delete/Move), or <<<<<<< SEARCH / ======= / >>>>>>> REPLACE blocks (path on the first line after SEARCH). SEARCH/REPLACE is unique by default (multi-match is ambiguous, no write); set replace_all=true to update every exact match. Empty-hunk +++ /dev/null (git deleted file mode, no hunks) unlinks. A hunked delete applies minus lines first; leftover bytes rewrite the file (preview --diff). Stale minus lines are ambiguous and the file is not removed; regenerate minus lines or use file.delete for path-only unlink. Use on_stale=merge for three-way merge on stale unified-diff context; allow_conflicts=true writes conflict markers. Never commit files containing conflict markers. IMPORTANT: do NOT issue concurrent patches/writes against the same files; use execute_plan for multi-op atomicity. Example: {"diff": "--- a/file.txt\n+++ b/file.txt\n@@ -1 +1 @@\n-old\n+new", "on_stale": "fail"}
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| diff | Yes | ||
| strict | No | Roll back all writes when format/validate lifecycle steps fail. | |
| on_stale | No | fail | |
| replace_all | No | SEARCH/REPLACE only: update every exact match. Default unique. | |
| allow_conflicts | No |