Apply Patch
apply_patchApply a unified diff patch to files for automated code changes. Validate patches with dry run before committing to prevent errors. Supports fuzzy matching and line-ending conversion for reliable patching.
Instructions
Apply a unified diff patch to one or more files. Single-file: throws on failure. Multi-file: best-effort per file with results[]. Workflow: diff_files → apply_patch(dryRun:true) → apply_patch. On failure, regenerate the patch from current file content.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path to file to patch | |
| patch | Yes | Unified diff with @@ hunk headers. Generate with `diff_files`. | |
| fuzzFactor | No | Maximum fuzzy mismatches per hunk | |
| autoConvertLineEndings | No | Auto-convert line endings to match target file | |
| dryRun | No | Validate patch without writing. Check `applied` before committing. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ok | Yes | ||
| path | No | ||
| applied | No | ||
| hunksApplied | No | Hunks applied | |
| linesAdded | No | Lines added | |
| linesRemoved | No | Lines removed | |
| results | No | Per-file results for multi-file patches |