Skip to content

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

Closed

Description

@evatths

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

Activity

  1. github-actions commented on Mar 29, 2026

    @github-actions
    Contributor

    This issue doesn't fully meet our contributing guidelines.

    What needs to be fixed:

    • The issue does not use one of the required issue templates (Bug Report, Feature Request, or Question). Please re-submit or edit this issue using the appropriate template structure.

    Please edit this issue to address the above within 2 hours, or it will be automatically closed.

    If you believe this was flagged incorrectly, please let a maintainer know.

  2. changed the title [-]Plugin hook tool name mismatch: docs say `patch`, source registers `apply_patch`; plus undocumented model-conditional tool substitution[/-] [+]Bug: docs list built-in tool as `patch`, source registers it as `apply_patch`[/+] on Mar 29, 2026
  3. github-actions commented on Mar 29, 2026

    @github-actions
    Contributor

    Thank you for updating the issue! It now includes a clear description, reproduction steps, version info, and OS details. Everything looks good — the compliance flag has been removed.

  4. yejiming commented on Mar 30, 2026

    @yejiming
    Contributor

    I'd like to work on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions