Skip to content

[feat] custom slash commands #299

Closed
Closed

Description

@monotykamary

There's an opportunity to add support for custom slash commands similar to Claude Code's slash command system, allowing users to create reusable prompts and workflows as markdown files.

Background

Currently, opencode has a keybinding-based command system with built-in triggers (like /help, /new, /sessions), but lacks the ability to create custom slash commands. Claude Code provides a powerful slash command system that allows users to:

  • Create custom commands as .md files
  • Support both project-level and personal commands
  • Use dynamic arguments and bash execution
  • Reference files directly in commands

Proposed Feature

Custom Slash Commands

Allow users to create custom slash commands by placing .md files in:

  • Project commands: .opencode/commands/*.md (shared with team)
  • Personal commands: ~/.opencode/commands/*.md (user-specific)

Command Syntax

/project:<command-name> [arguments]
/user:<command-name> [arguments]

Command File Format

Commands would be markdown files with optional YAML frontmatter:

---
description: "Analyze code for performance issues"
allowed-tools: ["bash", "read", "edit"]
---

Analyze this code for performance issues and suggest optimizations:

$ARGUMENTS

Key Features

  1. Namespacing: Support subdirectories for organization

    • .opencode/commands/frontend/component.md → /project:frontend:component
  2. Dynamic Arguments: Use $ARGUMENTS placeholder for user input

    # Usage: /project:fix-issue 123
    # Command: Fix issue #$ARGUMENTS following our coding standards
  3. Bash Command Execution: Execute bash commands with ! prefix

    ## Context
    - Current git status: !`git status`
    - Recent commits: !`git log --oneline -10`
  4. File References: Include file contents with @ prefix

    Review the implementation in @src/utils/helpers.js
    Compare @src/old-version.js with @src/new-version.js

Implementation Plan

1. Command File System

  • Create command directory scanning logic
  • Support both .opencode/commands/ (project) and ~/.opencode/commands/ (user)
  • Parse markdown files with YAML frontmatter

2. Command Parser

  • Extend existing completion system in packages/tui/internal/completions/
  • Add custom command discovery and parsing
  • Support namespaced command syntax

3. Command Execution Engine

  • Extend command registry in packages/tui/internal/commands/command.go
  • Implement dynamic command registration from files
  • Add argument substitution ($ARGUMENTS)
  • Add bash execution support (! prefix)
  • Add file reference support (@ prefix)

4. Integration Points

  • Modify chat editor to handle custom slash commands
  • Update completion provider to include custom commands
  • Extend command execution logic in TUI

Benefits

  1. Improved Workflow: Users can create reusable prompts for common tasks
  2. Team Collaboration: Project-level commands can be shared via version control
  3. Consistency: Standardize common workflows across team members
  4. Flexibility: Support for dynamic arguments and file references
  5. Extensibility: Easy to add new commands without code changes

Examples

Project Command: Code Review

.opencode/commands/review.md:

---
description: "Perform code review with context"
---

## Context
- Current branch: !`git branch --show-current`
- Modified files: !`git diff --name-only`

## Task
Review the following changes for:
- Code quality and best practices
- Security vulnerabilities
- Performance implications

$ARGUMENTS

Usage: /project:review Please focus on the authentication logic

Personal Command: Quick Fix

~/.opencode/commands/quickfix.md:

---
description: "Quick bug fix with standard format"
---

Fix the following issue following our coding standards:

Issue: $ARGUMENTS

Please:
1. Identify the root cause
2. Implement a minimal fix
3. Add appropriate tests
4. Update documentation if needed

Usage: /user:quickfix Button click handler not working on mobile

Related Work

This feature is inspired by Claude Code's slash command system, which provides similar functionality. The implementation would leverage opencode's existing command and completion infrastructure.

Acceptance Criteria

  • Support creating custom commands via .md files
  • Implement project-level (.opencode/commands/) and user-level (~/.opencode/commands/) command directories
  • Support namespaced commands via subdirectories
  • Implement $ARGUMENTS placeholder for dynamic content
  • Support bash command execution with ! prefix
  • Support file references with @ prefix
  • Integrate with existing completion system
  • Commands appear in / completion dropdown
  • Maintain backward compatibility with existing command system

Activity

  1. changed the title [-]feature request: custom slash commands[/-] [+][feat] custom slash commands[/+] on Jun 22, 2025
  2. adamdotdevin commented on Jun 22, 2025

    @adamdotdevin
    Member

    if anyone wants to take a stab at this, please let me know here. we can use a modal for custom command args, but i wonder if we could just support them inline in the editor textarea, like:

    > /project:fix-issue 113
    

    would be cool to avoid all the complexity of the modal

  3. tmeire commented on Jun 22, 2025

    @tmeire
    Contributor

    if anyone wants to take a stab at this, please let me know here. we can use a modal for custom command args, but i wonder if we could just support them inline in the editor textarea, like:

    > /project:fix-issue 113
    

    would be cool to avoid all the complexity of the modal

    @adamdotdevin can you assign it to me? I'll take a stab at this tomorrow.

  4. pattobrien commented on Jun 23, 2025

    @pattobrien

    It'd be awesome if the main implementation for custom commands used the MCP Prompt primitive.

  5. tmeire commented on Jun 25, 2025

    @tmeire
    Contributor

    @thdxr @adamdotdevin I've implemented the basics (but majority) of this ticket in PR #385 . Would love some feedback on the general direction & some thoughts on how you would implement bash & file references support.

    The main functionality is implemented on the server side to make sure it's available on future clients without effort.

    • prompts are passed to the tui using the config endpoint
    • prompts are then injected into the command list
    • after completion, the command is injected into the textarea to allow for additional arguments
    • the command with arguments are send to the server
    • the server translates the command to the stored prompt

    Things where the implementation differs from the OP:

    • User commands are stored in ~/.local/opencode as per xdg
    • Allowed tools are parsed from the md files, but not used yet
    • Bash execution and file references are not implemented yet
    • It doesn't use the MCP prompts; the general support for those looks very weak at best
  6. ezynda3 commented on Jun 25, 2025

    @ezynda3
    Contributor

    Would it be possible to have named args just like we had before the refactor? 56160f8

  7. syabro commented on Jun 26, 2025

    @syabro

    /project:frontend:component
    Do we really need project/user prefixes? It's a huge downside for UX
    I want to type /com and get /commit suggestion. I don't want to type /project:com

  8. adamdotdevin commented on Jun 26, 2025

    @adamdotdevin
    Member

    /project:frontend:component
    Do we really need project/user prefixes? It's a huge downside for UX
    I want to type /com and get /commit suggestion. I don't want to type /project:com

    fwiw, the fuzzy matching should still allow you to match "com" in that example, but i've also thought it'd be nice to drop this distinction (even if only for aesthetic purposes)

  9. seflue commented on Jul 5, 2025

    @seflue

    It would be great, if I could refer to my existing claude-code slash-commands or github prompt files like the custom instructions.

    Regarding the namespacing: In claude-code this namespacing is just a convention. Files are matched directly but there is no working auto completion for namespaces. The lookup is somehow fuzzy, if the command file was not found, the LLM tries to find it using file system tools. What I would prefer, if the namespaced commands are actually discovered and I can then just fuzzy match, like OpenCode already does. So it is primarily a matter of discovery and presentation within a list. Namespaces would be great, because then I could define stuff like /idea:new or /feat:new. I have this already in my slash commands in claude-code, but the ergonomics are far from ideal, because the autocompletion, although it matches the relevant commands doesn't show the namespaces. This is something, where I see some potential for OpenCode to provide a better user experience.

  10. ll931217 commented on Jul 5, 2025

    @ll931217
    Contributor

    I really want this in OpenCode, so I took the initiative, I am really new to golang. Got the basics working. Took me a while to wrap my head around the packages.

    I was able to add fuzzy find on my commands, I am able to supply arguments to the command file. Here is the code if anyone wants to try it out.

    I want to first test the code some more and fix up where there is issues.

  11. KP-Jaco commented on Jul 11, 2025

    @KP-Jaco

    Huge +1 to this. I have a lot of custom slash commands set up in claude code so this would really close the loop.

  12. hujianxin commented on Jul 31, 2025

    @hujianxin

    I'm really looking forward to this feature. It will bring about huge changes.

  13. thoroc commented on Aug 12, 2025

    @thoroc

    Would be nice to have so we can use the bmad method.

  14. monotykamary commented on Aug 12, 2025

    @monotykamary
    ContributorAuthor

    apologies, I read that as the "be mad" method

  15. fettpl commented on Aug 18, 2025

    @fettpl

    @thdxr @jayair Is there any solid plan for this feature? There's a statement in #707 regarding you bringing it to internal discussion, but no follow-up.

  16. jayair commented on Aug 18, 2025

    @jayair
    Contributor

    Yeah we are hoping to get to it this week.

  17. ndrwstn commented on Aug 27, 2025

    @ndrwstn

    Probably can close this issue --> #2157 ?

  18. martinffx commented on Nov 12, 2025

    @martinffx

    @jayair would you be open to a PR add command namespaces like you get in Claude Code?

    https://code.claude.com/docs/en/slash-commands#namespacing

  19. rekram1-node commented on Nov 12, 2025

    @rekram1-node
    Collaborator

    @martinffx how would that work given the current way slash commands are read from subdirs of commands dir

  20. martinffx commented on Nov 12, 2025

    @martinffx

    @rekram1-node idk, I've not looked into it yet.

    I am checking that contributions like that are welcome, as a community contribution of commands was rejected, and I'm not sure what sort of contributions you are open to.

  21. rekram1-node commented on Nov 12, 2025

    @rekram1-node
    Collaborator

    @martinffx so we accept a lottt of contributions, this was originally rejected a while ago because so many things were in flux and the team wanted to get the baseline apis and blocks to build with to a consistent state.

    Now that we are in a better state almost any contirbution is welcome we just prefer if it is a huge change to ask questions before making huge prs.

    But this doesnt sound like a huge change to me I just wanted to clarify

  22. martinffx commented on Nov 12, 2025

    @martinffx

    @rekram1-node ok, I understand. Just wanted to confirm that was not still the case before getting stuck into something.

    So it looks like my issue is not really an issue anymore. When porting over my commands from CC back in August, none of my commands in subfolders would be read. It seems that it has been resolved since; command/code/review.md will be picked up as /code/review now.

    Which is basically what I wanted, still think CC's namespaces are a little more elegant, i.e. /code:review. But that is more of an aesthetic preference than a functional limitation.

  23. rekram1-node commented on Nov 12, 2025

    @rekram1-node
    Collaborator

    Sounds good, if u still want the namespaces we can probably add them I just worry about breaking workflows so I'd need to see what the change would encompass

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

Metadata

Metadata

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