[PR #10028] feat(plugin): add tool.execute.error hook #13304

Open
opened 2026-02-16 18:18:10 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/10028

State: open
Merged: No


Add a new plugin hook that fires when tool execution throws an error, allowing plugins to log, modify, or recover from errors.

Fixes #10027

What Changed

Added tool.execute.error hook to the plugin system. The hook receives:

  • input: tool name, session ID, call ID, and args
  • output: mutable object with error and optional result

Plugins can either modify the error or provide a fallback result.

Example Usage

export default {
  hooks: {
    "tool.execute.error": async (input, output) => {
      console.error(`Tool ${input.tool} failed:`, output.error.message)

      // Option 1: Modify error message
      if (output.error.message.includes("rate limit")) {
        output.error = new Error("Service temporarily unavailable, please try again")
      }

      // Option 2: Recover from error by providing a result
      if (input.tool === "read" && output.error.message.includes("not found")) {
        output.result = {
          title: "File not found",
          output: `The file ${input.args.filePath} does not exist.`,
          metadata: {}
        }
      }
    }
  }
}

How I Verified

  • Typecheck passes
  • Manually tested hook invocation on tool errors
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/10028 **State:** open **Merged:** No --- Add a new plugin hook that fires when tool execution throws an error, allowing plugins to log, modify, or recover from errors. Fixes #10027 ## What Changed Added `tool.execute.error` hook to the plugin system. The hook receives: - `input`: tool name, session ID, call ID, and args - `output`: mutable object with `error` and optional `result` Plugins can either modify the error or provide a fallback result. ## Example Usage ```typescript export default { hooks: { "tool.execute.error": async (input, output) => { console.error(`Tool ${input.tool} failed:`, output.error.message) // Option 1: Modify error message if (output.error.message.includes("rate limit")) { output.error = new Error("Service temporarily unavailable, please try again") } // Option 2: Recover from error by providing a result if (input.tool === "read" && output.error.message.includes("not found")) { output.result = { title: "File not found", output: `The file ${input.args.filePath} does not exist.`, metadata: {} } } } } } ``` ## How I Verified - Typecheck passes - Manually tested hook invocation on tool errors
yindo added the pull-request label 2026-02-16 18:18:10 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13304