Skip to content

Conversation

@nsoufian
Copy link

@nsoufian nsoufian commented Jan 23, 2026

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

@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found a potentially related PR:

Potential Duplicate:

This PR appears to address the same core feature: adding plugin command registration. It's referenced multiple times across different search queries for plugin command functionality.

I'd recommend reviewing PR #7563 to understand if this is an earlier attempt at the same feature that may have been closed, superseded, or needs rebasing against the current dev branch.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Allow plugins to register slash commands

1 participant