Apply file changes using a structured patch format. This is ideal for multi-file or multi-hunk edits where a single edit call would be brittle.

The tool accepts a single input string that wraps 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
*** Update File: src/old-name.ts
*** Move to: src/new-name.ts
@@
 context line
-old line
+new line
*** Update File: src/tail.ts
@@
+appended last line
*** End of File
*** Delete File: obsolete.txt
*** End Patch

*** Move to: goes on the line directly after its *** Update File: header. *** End of File goes after the hunk lines it terminates, marking that the hunk runs to the end of the file.

Parameters

Notes

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

Read-only diff viewer for change presentation.

Exec tool

Shell command execution from the agent.

Code execution

Sandboxed remote Python analysis with xAI.