Apply patch
apply_patchApply a unified diff to one or more files atomically: all hunks are validated in memory first, and any failing hunk rolls every file back from an automatic checkpoint.
Instructions
Apply a unified diff (git apply compatible) to one or more files, all-or-nothing. Every file is validated in memory before anything is written; a failing hunk rolls every file back from an automatic checkpoint, like edit_batch. dry_run=true validates and reports without writing. Use when: a change arrives as a diff (git diff, a patch file, another tool's output) and must land completely or not at all — files created, modified, deleted or renamed. Avoid when: you have no diff (edit_file/edit_batch) or only need a new file (write_file). Not for directories or symbolic links. Output: dry_run: files[] {action, relative_path, hunks, bytes} plus added/modified/deleted/renamed counts; nothing is written. success: same list plus sha256_after per file. Failure: nothing is changed; data carries rollback_succeeded and, for a mismatching hunk, nearest_context lines for the file and hunk that failed.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"patch": "<patch>"
},
"name": "apply_patch"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| patch | Yes | Unified diff. Multiple files supported: each section starts with 'diff --git a/old b/new' or '--- a/old' + '+++ b/new' ('/dev/null' for created/deleted files). | |
| reason | No | Optional why (max 400 chars), audit-logged. | |
| dry_run | No | true validates the patch against the current files and reports what would change, writing nothing (default false). | |
| expected_sha256 | No | Optional map of workspace-relative path -> hex SHA-256; the patch is refused if a file changed since it was read. Keys must be paths the patch touches. |