Repository navigation
[feat] custom slash commands #299
Description
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
.mdfiles - 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:
$ARGUMENTSKey Features
-
Namespacing: Support subdirectories for organization
.opencode/commands/frontend/component.md→/project:frontend:component
-
Dynamic Arguments: Use
$ARGUMENTSplaceholder for user input# Usage: /project:fix-issue 123 # Command: Fix issue #$ARGUMENTS following our coding standards
-
Bash Command Execution: Execute bash commands with
!prefix## Context - Current git status: !`git status` - Recent commits: !`git log --oneline -10`
-
File References: Include file contents with
@prefixReview 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
- Improved Workflow: Users can create reusable prompts for common tasks
- Team Collaboration: Project-level commands can be shared via version control
- Consistency: Standardize common workflows across team members
- Flexibility: Support for dynamic arguments and file references
- 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
$ARGUMENTSUsage: /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 neededUsage: /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
.mdfiles - Implement project-level (
.opencode/commands/) and user-level (~/.opencode/commands/) command directories - Support namespaced commands via subdirectories
- Implement
$ARGUMENTSplaceholder 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
[-]feature request: custom slash commands[/-][+][feat] custom slash commands[/+]adamdotdevin commentedon Jun 22, 2025
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:
would be cool to avoid all the complexity of the modal
tmeire commentedon Jun 22, 2025
@adamdotdevin can you assign it to me? I'll take a stab at this tomorrow.
pattobrien commentedon Jun 23, 2025
It'd be awesome if the main implementation for custom commands used the MCP
Promptprimitive.tmeire commentedon Jun 25, 2025
@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.
Things where the implementation differs from the OP:
~/.local/opencodeas per xdgezynda3 commentedon Jun 25, 2025
Would it be possible to have named args just like we had before the refactor? 56160f8
syabro commentedon Jun 26, 2025
/project:frontend:componentDo we really need
project/userprefixes? It's a huge downside for UXI want to type
/comand get/commitsuggestion. I don't want to type/project:comadamdotdevin commentedon Jun 26, 2025
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)
seflue commentedon Jul 5, 2025
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:newor/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.ll931217 commentedon Jul 5, 2025
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.
KP-Jaco commentedon Jul 11, 2025
Huge +1 to this. I have a lot of custom slash commands set up in claude code so this would really close the loop.
hujianxin commentedon Jul 31, 2025
I'm really looking forward to this feature. It will bring about huge changes.
thoroc commentedon Aug 12, 2025
Would be nice to have so we can use the bmad method.
monotykamary commentedon Aug 12, 2025
apologies, I read that as the "be mad" method
fettpl commentedon Aug 18, 2025
@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.
jayair commentedon Aug 18, 2025
Yeah we are hoping to get to it this week.
ndrwstn commentedon Aug 27, 2025
Probably can close this issue --> #2157 ?
martinffx commentedon Nov 12, 2025
@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
rekram1-node commentedon Nov 12, 2025
@martinffx how would that work given the current way slash commands are read from subdirs of commands dir
martinffx commentedon Nov 12, 2025
@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.
rekram1-node commentedon Nov 12, 2025
@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
martinffx commentedon Nov 12, 2025
@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.mdwill be picked up as/code/reviewnow.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.rekram1-node commentedon Nov 12, 2025
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
feat: small improve workspace UI and visual consistency (anomalyco#299)