概述
apply_patch 是 exec 的子工具,用于通过结构化 patch 格式对多个文件进行批量编辑。适合跨文件或多 hunk 的编辑场景,比单次 edit 调用更健壮。默认对 OpenAI 和 OpenAI Codex 模型启用。
核心功能
- 支持操作类型:
*** Add File:— 新增文件*** Update File:— 更新文件(支持*** Move to:重命名)*** Delete File:— 删除文件*** End of File— EOF 插入标记
- 路径支持:相对路径(从工作区目录)和绝对路径
- 工作区限制:
tools.exec.applyPatch.workspaceOnly默认true,限制在工作区内操作 - 模型限制:仅对 OpenAI/OpenAI Codex 模型可用
配置/权限
{
tools: {
exec: {
applyPatch: {
enabled: true,
workspaceOnly: true,
allowModels: ["gpt-5.5"]
}
}
}
}工具策略注意事项:
allow: ["write"]隐式允许apply_patchdeny: ["write"]不会拒绝apply_patch,需显式deny: ["apply_patch"]或deny: ["group:fs"]
Patch 格式示例:
*** Begin Patch
*** Add File: path/to/file.txt
+line 1
+line 2
*** Update File: src/app.ts
@@
-old line
+new line
*** Delete File: obsolete.txt
*** End Patch
相关页面
- tool-exec — exec 工具(apply_patch 的父工具)
- tool-diffs — 只读 diff 查看器