Skip to content

[FEATURE]: droid-like custom slash commands in arbitrary languages using shebang lines #4839

Closed

Description

@ariane-emory

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

Factory's droid tool supports using files containing shebang lines to write custom slash commands in arbitrary interpreted languages, see: https://docs.factory.ai/cli/configuration/custom-slash-commands#3-%C2%B7-executable-commands

The basic gist of the idea is that if we had this feature, a file like ./opencode/command/command.py, so long as it started with a #!/usr/bin/env python shebang line, would then show up in the opencode as a /command command, and would run a Python script that would generate the output that was sent to the model.

Being able to write custom commands in any interpreted language that supported being executed from files with shebang lines (i.e, very nearly all of them, including all of the most popular ones and even theoretical future languages that don't exist yet) would potentially provide a lot of power and flexibility.

Now, there are other things about droid that I didn't much care for - that's why I'm staying over here with Team Opencode instead of becoming a droid user - but that particular feature sounds pretty killer, it'd be amazing if we implemented something similar.

Activity

  1. added
    discussionUsed for feature requests, proposals, ideas, etc. Open discussion
    on Nov 27, 2025
  2. github-actions commented on Nov 27, 2025

    @github-actions
    Contributor

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

    Feel free to ignore if none of these address your specific case.

  3. JunarisAlf commented on Nov 28, 2025

    @JunarisAlf

    Isn't it already there?
    https://opencode.ai/docs/commands/#shell-output

    Add this to the command markdown !python3 path/to/script.py

  4. ariane-emory commented on Nov 28, 2025

    @ariane-emory
    ContributorAuthor

    @JunarisAlf Shell expansions in the Markdown files can let you achieve somewhat similar things, but it's slightly more cumbersome since you need to maintain both an .md file and a .py (or whatever other language) file instead of being to do it all in a single .py (or whatever) file.

    Personally, I feel that it would be more ergonomic and provide a better DevX for custom command authors if they could do it all in a single file instead of having to maintain two files for a single command. Maintaining a second Markdown file that's just a shim calling some other script is a technical burden that could be easily avoided by the inclusion of support for directly using script files written in other languages. Why bear this burden if we don't have to?

  5. einarpersson commented on Nov 28, 2025

    @einarpersson

    I think this is cool, but if we were to get something like #4411 then perhaps the feature that you are looking for here would just be the question of creating that plugin (and sharing it with the world?).

    As i understand it, commands are right now either built-in custom stuff or "do something with a llm". But being able to utilize the SDK to register and run commands that execute code feels obvious. And that could of course include execute some other script with uv, node, julia or whatever with the proper shebang.

    OR the other way around. Get something like this working first, like you propose. But the opencode SDK is only available in ts/js, so i suppose that if you want that script to also interact with the running client/server then you'd have to use that (or use the API perhaps, i'm not sure about feature parity sdk/api).

    Bottom line: I'm all for stuff that opens up for power users to use opencode whatever way they want. Instead of building all features into opencode, let's create nice interfaces and get that eco-system going (and lower the treshold to customize it whatever way you want).

    Questions:

    1. Would this allow for slash commands with arguments? to be provided to the commands
    2. Could something like env variables be used to provide the command with some context that could be useful? The API/SDK could perhaps be used to look up such stuff on a need-to-know basis but at the very least it could be useful for the command to get some id:s so it'd be easier to look up.
  6. ariane-emory commented on Nov 28, 2025

    @ariane-emory
    ContributorAuthor

    I'm gonna have to spend a bit more time reading #4411 and thinking about it to say for sure, but my first instinct is to say that it doesn't seem quite as open-ended or flexible.

    Part of what seems attractive about the shebang line method is that it isn't limited to some small subset of languages, it could be used with any language that can interface with standard Unix behaviours regarding the use of shebang lines to invoke interpreters via command lines - popular languages, ancient languages that have been nearly forgotten about and even languages to be invented in the future that don't exist yet. Whether that's valuable is a judgement call the reader will have to make for themselves.

    Answers:

    1. Sure, arguments could be passed to the interpreter specified by the shebang line in the same way that they would be if you executed the script from the command line.
    2. Sure, I'd presume that those languages that would be able to access environment variables if you executed the script from the command line would be able to do so here as well. Some exotic languages might support shebang lines but not support environment variables: if you decided to write your command in Befunge we would be able to run it but you'd probably be out of luck on the environment variables.
  7. einarpersson commented on Nov 28, 2025

    @einarpersson

    Yes I like what you are proposing. I just meant that as soon as the sdk can be used to create commands (that execute code) it should be possible to without further changes to source code, create such a plugin, that allows for registering and executing commands in any language as you propose, for example if is a commands folder is existing as in your proposal. If I'm not missing something. But adding this to core would be nice also. It would make it super easy to add slash commands

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionUsed for feature requests, proposals, ideas, etc. Open discussion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions