Applies a structured diff-like patch envelope to one or more files. Unlike
btw_tool_files_edit() (which requires hashline references from a prior
read) or btw_tool_files_replace() (which requires exact strings), the
patch tool uses context-matching hunks so models can produce coordinated
edits across multiple files in a single tool call. A single patch envelope
can add, update, delete, and move files atomically: either all operations
succeed or none are applied.
Patch syntax
A patch is a text envelope that begins with *** Begin Patch and ends with
*** End Patch. Inside the envelope, each operation starts with a header:
** Begin Patch
** Add File: docs/example.md
Hello
World
** Update File: src/main.py
@@
context line
old line
new line
** Delete File: old.txt
** Update File: src/old.ts
** Move to: src/new.ts
@@
context line
export const oldName = 1
export const newName = 1
** End PatchHeaders
*** Add File: <path>– create a new file (must not exist).*** Update File: <path>– modify an existing file.*** Delete File: <path>– remove an existing file.*** Move to: <path>– sub-header inside anUpdate Fileblock; renames the file to<path>after applying any hunks. Destination must not exist.
Hunk lines (inside Update File)
@– hunk boundary; any trailing text on this line is informational and ignored.<text>(space prefix) – context line that must match the file exactly.-<text>– line to delete; must match the file exactly at this position.+<text>– line to insert.
Every hunk must include at least one context or delete line to anchor the
edit; pure-insert hunks are rejected. Use *** Add File for new files.
See also
btw_tool_files_edit() for hashline-based targeted edits,
btw_tool_files_replace() for exact find-and-replace edits.
Other files tools:
btw_tool_files_edit(),
btw_tool_files_list(),
btw_tool_files_read(),
btw_tool_files_replace(),
btw_tool_files_search(),
btw_tool_files_write()
