Apply Multi-File Patches with the apply_patch Tool
Learn how to use the apply_patch tool to apply structured patches across multiple files. This page covers parameters, configuration, and usage notes for developers.
Read this when
- You need structured file edits across multiple files
- You want to document or debug patch-based edits
Apply file changes with a structured patch format. This works well for edits spanning multiple files or hunks where a single edit call would be fragile.
The tool expects one input string containing one or more file operations:
*** Begin Patch
*** Add File: path/to/file.txt
+line 1
+line 2
*** Update File: src/app.ts
@@ optional change context
-old line
+new line
*** Delete File: obsolete.txt
*** End Patch
Parameters
input(required): The full patch content, including*** Begin Patchand*** End Patch.
Notes
- Patch paths support both relative paths (relative to the workspace directory) and absolute paths.
tools.exec.applyPatch.workspaceOnlydefaults totrue(workspace-contained). Set it tofalseonly when you intentionally wantapply_patchto write or delete outside the workspace directory.- Use
*** Move to:inside an*** Update File:hunk to rename files. *** End of Filemarks an EOF-only insert when needed.- Enabled by default for every model. Set
tools.exec.applyPatch.enabled: falseto disable it, or restrict it to specific models withtools.exec.applyPatch.allowModels(accepts raw ids likegpt-5.4or full ids likeopenai/gpt-5.4). - Configuration is under
tools.exec.applyPatch.*.
Example
{
"tool": "apply_patch",
"input": "*** Begin Patch\n*** Update File: src/index.ts\n@@\n-const foo = 1\n+const foo = 2\n*** End Patch"
}
Related
-
Diffs, A read-only diff viewer for presenting changes.
-
Exec tool, Runs shell commands from the agent.
-
Code execution, Sandboxed remote Python analysis with xAI.