[PR #10261] feat(core): add plugin-registered slash commands to the command list #13383

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

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

State: open
Merged: No


Closes #10262

What does this PR do?

Currently, plugin authors have no way to interact with users through the OpenCode interface. Plugins cannot:

  • Register dynamic slash commands that appear in the command list
  • Trigger plugin-managed processes from user input
  • Update plugin internal state through UI interactions

This PR addresses these limitations by introducing plugin-registered slash commands.

How it works

Plugins can now define commands that appear in the slash command list. When invoked, these commands execute plugin-defined logic and persist the output as session messages—no LLM involvement required.

Example

import type { Plugin } from "@opencode-ai/plugin"

export const TogglePlugin: Plugin = async () => {
  return {
    command: [
      {
        name: "toggle",
        description: "toggle plugin state",
        hints: ["$ARGUMENTS"],
        mode: "plugin",
      },
    ],
    "command.execute": async (input) => {
      if (input.command !== "toggle") return undefined
      return {
        parts: [{ type: "text", text: `toggle:${input.arguments.trim() || "off"}` }],
      }
    },
  }
}

Benefits

  • User interaction: Plugins can respond to user intent through slash commands
  • State management: Plugin state can be updated via UI without external tooling
  • Process triggers: Plugins can kick off background processes on demand
  • Discoverability: Plugin commands appear alongside built-in commands
  • Clean architecture: Plugin command execution is isolated in a dedicated service

How did you verify your code works?

  • Automated: Unit tests for command listing and execution (bun test --cwd packages/opencode test/command/plugin-commands.test.ts)
  • Manual: Created a plugin using the example above, verified the command appears in the list, invoked /toggle on, and confirmed output persists in the session
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/10261 **State:** open **Merged:** No --- Closes #10262 ## What does this PR do? Currently, plugin authors have no way to interact with users through the OpenCode interface. Plugins cannot: - Register dynamic slash commands that appear in the command list - Trigger plugin-managed processes from user input - Update plugin internal state through UI interactions This PR addresses these limitations by introducing plugin-registered slash commands. ### How it works Plugins can now define commands that appear in the slash command list. When invoked, these commands execute plugin-defined logic and persist the output as session messages—no LLM involvement required. ### Example ```ts import type { Plugin } from "@opencode-ai/plugin" export const TogglePlugin: Plugin = async () => { return { command: [ { name: "toggle", description: "toggle plugin state", hints: ["$ARGUMENTS"], mode: "plugin", }, ], "command.execute": async (input) => { if (input.command !== "toggle") return undefined return { parts: [{ type: "text", text: `toggle:${input.arguments.trim() || "off"}` }], } }, } } ``` ### Benefits - **User interaction**: Plugins can respond to user intent through slash commands - **State management**: Plugin state can be updated via UI without external tooling - **Process triggers**: Plugins can kick off background processes on demand - **Discoverability**: Plugin commands appear alongside built-in commands - **Clean architecture**: Plugin command execution is isolated in a dedicated service ## How did you verify your code works? - **Automated**: Unit tests for command listing and execution (`bun test --cwd packages/opencode test/command/plugin-commands.test.ts`) - **Manual**: Created a plugin using the example above, verified the command appears in the list, invoked `/toggle on`, and confirmed output persists in the session
yindo added the pull-request label 2026-02-16 18:18:14 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13383