Skip to content

Bug: docs list built-in tool as patch, source registers it as apply_patch #19941

@evatt-harvey-salinger

Description

@evatt-harvey-salinger

Description

The Tools documentation lists a built-in tool called patch in the Built-in section. The actual registered tool ID in the source is apply_patch. This causes plugin hooks that check input.tool === "patch" to silently never fire — no error, no warning.

Additionally, the docs don't describe the apply_patch args shape or path format, which differs significantly from edit/write.

Tool name mismatch

Docs say: patch

Source (packages/opencode/src/tool/apply_patch.ts):

export const ApplyPatchTool = Tool.define("apply_patch", { ... })

A plugin author following the docs and writing:

"tool.execute.before": async (input, output) => {
  if (input.tool === "patch") { /* never runs */ }
}

gets silent failure. The correct name is "apply_patch".

apply_patch args shape (undocumented)

apply_patch has a different args shape than edit/write and the docs don't mention it:

// edit / write — filePath is directly available:
output.args.filePath  // absolute path

// apply_patch — no filePath; paths are embedded in patchText as relative paths:
output.args.patchText  // must parse marker lines to extract paths

Marker lines in patchText (paths are relative to project root):

*** Add File: src/new-file.ts
*** Update File: src/existing.ts
*** Move to: src/renamed.ts
*** Delete File: src/obsolete.ts

Resolved internally via path.resolve(Instance.directory, hunk.path).


OpenCode version

1.3.6

Steps to reproduce

  1. Read the Tools docs — note tool is listed as patch
  2. Write a plugin with if (input.tool === "patch") { ... }
  3. Trigger any file edit with a GPT-5-series model
  4. Observe: the branch never executes, no error thrown

Verified via:

  • GitHub source (dev branch): Tool.define("apply_patch", ...) in src/tool/apply_patch.ts
  • Compiled binary string search (v1.3.6)
  • Live logging plugin test confirming input.tool values

Operating System

macOS

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions