Skip to content

[FEATURE]: Add cancellation support for command.execute.before hook #18554

Closed as not planned

Description

@kldzj

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Summary

Plugins that intercept commands via command.execute.before have no way to cancel the subsequent prompt() call without throwing an error. This causes a 500 response on the web app (error toast + input restoration), even though the plugin handled the command successfully.

Problem

The command.execute.before hook signature returns Promise<void>. There's no way to signal that the command was fully handled and prompt() should be skipped.

The only way to prevent the LLM call is to throw, which propagates through Plugin.trigger() → SessionPrompt.command() → route handler → onError.

TUI: Unaffected (SDK uses throwOnError: false + fire-and-forget).
Web app: Shows "command failed" error toast and restores the input text.

Suggested fix

Add a cancelled property to the hook output:

// In SessionPrompt.command() (prompt.ts ~line 1895):
const output = { parts, cancelled: false }
await Plugin.trigger("command.execute.before", { ... }, output)
if (output.cancelled) return

const result = await prompt({ ... })

Plugin usage:

"command.execute.before": async (input, output) => {
  if (input.command === "my-command") {
    // Handle the command...
    output.cancelled = true // skip prompt()
  }
}

This would be a minimal, backwards-compatible change, existing plugins that don't set cancelled behave identically.

Activity

  1. added
    discussionUsed for feature requests, proposals, ideas, etc. Open discussion
    on Mar 21, 2026
  2. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Mar 21, 2026
  3. github-actions commented on Mar 21, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    • feat: Add noReply option to command.execute.before hook #9306: Very similar request — adding a way to skip the LLM/prompt() call from a command.execute.before hook, with the same motivation (current workaround of throwing an error is hacky). The proposed solutions differ slightly (noReply vs cancelled), but the underlying problem is identical.
  4. removed
    discussionUsed for feature requests, proposals, ideas, etc. Open discussion
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  5. github-actions commented on Jul 4, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions