[PR #707] [CLOSED] feat: Custom slash command #9686

Closed
opened 2026-02-16 18:13:59 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/anomalyco/opencode/pull/707
Author: @ll931217
Created: 7/5/2025
Status: Closed

Base: devHead: custom-slash-command


📝 Commits (10+)

  • 1de15d0 feat: added custom slash command
  • 2957e69 fix: Use markdown frontmatter "description" as autocompletion description
  • 6e76596 feat: added commands namespacing based on their parent directory
  • 709d0a7 feat: added arguments feature
  • f8e06b9 feat: add bash command execution before slash command
  • a9c8788 Merge branch 'sst:dev' into custom-slash-command
  • 0b6e3b2 feat: Add file reference with @ prefix
  • 617a546 fix: Remove some commands from banned commands
  • 8fbaf89 fix: Tab autocompletion to not autosend and custom command check
  • d0081d1 fix: Import BANNED_COMMANDS from bash tool

📊 Changes

19 files changed (+2153 additions, -234 deletions)

View changed files

packages/opencode/src/commands/index.ts (+554 -0)
📝 packages/opencode/src/server/server.ts (+112 -0)
📝 packages/opencode/src/session/index.ts (+11 -1)
📝 packages/opencode/src/tool/ls.ts (+1 -1)
📝 packages/opencode/src/tool/todo.ts (+1 -1)
📝 packages/opencode/src/tool/tool.ts (+4 -4)
packages/opencode/src/util/file-reference.ts (+86 -0)
packages/opencode/test/commands/api-integration.test.ts (+169 -0)
packages/opencode/test/commands/bash-commands.test.ts (+124 -0)
packages/opencode/test/commands/custom-commands.test.ts (+184 -0)
packages/opencode/test/commands/git-commit.md (+16 -0)
packages/opencode/test/util/file-reference.test.ts (+100 -0)
📝 packages/tui/internal/app/app.go (+135 -30)
packages/tui/internal/commands/client.go (+170 -0)
📝 packages/tui/internal/commands/command.go (+247 -190)
📝 packages/tui/internal/completions/commands.go (+95 -6)
📝 packages/tui/internal/components/chat/editor.go (+34 -0)
📝 packages/tui/internal/components/dialog/complete.go (+41 -1)
📝 packages/tui/internal/tui/tui.go (+69 -0)

📄 Description

Based off Issues #299

Custom slash command feature

Commands location

Checks for the commands directory under OpenCode's configuration directory.

~/.config/opencode/commands/

Commands under project directory

$PWD/.opencode/commands/

Usage

Should work exactly like Claude Code's Slash Command

/foo:bar:test-command $ARGUMENTS

Here is a command file I used to test:

---
description: Your weather forecast (Powered by wttr.in)
allowed-tools:
  - Bash(curl *)
---
# Context

- Get the weather forecast: !`curl wttr.in $ARGUMENTS`

Display the weather forecast for $ARGUMENTS

I don't have the allowed-tools frontmatter setup, because I don't think it is needed? Correct me if I am wrong


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/anomalyco/opencode/pull/707 **Author:** [@ll931217](https://github.com/ll931217) **Created:** 7/5/2025 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `custom-slash-command` --- ### 📝 Commits (10+) - [`1de15d0`](https://github.com/anomalyco/opencode/commit/1de15d0632d6c2b5f351303112fc5a74cc99e179) feat: added custom slash command - [`2957e69`](https://github.com/anomalyco/opencode/commit/2957e69a2a5896173b904597625538162b6f491b) fix: Use markdown frontmatter "description" as autocompletion description - [`6e76596`](https://github.com/anomalyco/opencode/commit/6e76596ef199f1bc744e549e5018930cff153b31) feat: added commands namespacing based on their parent directory - [`709d0a7`](https://github.com/anomalyco/opencode/commit/709d0a70dc0ec7334060d74c07a8d9b81cb24f3e) feat: added arguments feature - [`f8e06b9`](https://github.com/anomalyco/opencode/commit/f8e06b9a532620bbe56a647e5df10dda8aab5467) feat: add bash command execution before slash command - [`a9c8788`](https://github.com/anomalyco/opencode/commit/a9c8788bb3a9768baf62a618d059de6ae1dabdd8) Merge branch 'sst:dev' into custom-slash-command - [`0b6e3b2`](https://github.com/anomalyco/opencode/commit/0b6e3b2209cd0e098bf3aab53b4fab9dfcbf327a) feat: Add file reference with @ prefix - [`617a546`](https://github.com/anomalyco/opencode/commit/617a5461dfc80887987d54e121dc5e4e682d68c9) fix: Remove some commands from banned commands - [`8fbaf89`](https://github.com/anomalyco/opencode/commit/8fbaf894055e7e3003051018302483e03e26e93c) fix: Tab autocompletion to not autosend and custom command check - [`d0081d1`](https://github.com/anomalyco/opencode/commit/d0081d18bf1e43953eaf2d7dd6edc5bf03f4ac66) fix: Import BANNED_COMMANDS from bash tool ### 📊 Changes **19 files changed** (+2153 additions, -234 deletions) <details> <summary>View changed files</summary> ➕ `packages/opencode/src/commands/index.ts` (+554 -0) 📝 `packages/opencode/src/server/server.ts` (+112 -0) 📝 `packages/opencode/src/session/index.ts` (+11 -1) 📝 `packages/opencode/src/tool/ls.ts` (+1 -1) 📝 `packages/opencode/src/tool/todo.ts` (+1 -1) 📝 `packages/opencode/src/tool/tool.ts` (+4 -4) ➕ `packages/opencode/src/util/file-reference.ts` (+86 -0) ➕ `packages/opencode/test/commands/api-integration.test.ts` (+169 -0) ➕ `packages/opencode/test/commands/bash-commands.test.ts` (+124 -0) ➕ `packages/opencode/test/commands/custom-commands.test.ts` (+184 -0) ➕ `packages/opencode/test/commands/git-commit.md` (+16 -0) ➕ `packages/opencode/test/util/file-reference.test.ts` (+100 -0) 📝 `packages/tui/internal/app/app.go` (+135 -30) ➕ `packages/tui/internal/commands/client.go` (+170 -0) 📝 `packages/tui/internal/commands/command.go` (+247 -190) 📝 `packages/tui/internal/completions/commands.go` (+95 -6) 📝 `packages/tui/internal/components/chat/editor.go` (+34 -0) 📝 `packages/tui/internal/components/dialog/complete.go` (+41 -1) 📝 `packages/tui/internal/tui/tui.go` (+69 -0) </details> ### 📄 Description Based off Issues #299 # Custom slash command feature ## Commands location Checks for the `commands` directory under OpenCode's configuration directory. ```bash ~/.config/opencode/commands/ ``` ## Commands under project directory ```bash $PWD/.opencode/commands/ ``` ## Usage Should work exactly like [Claude Code's Slash Command](https://docs.anthropic.com/en/docs/claude-code/slash-commands) ```bash /foo:bar:test-command $ARGUMENTS ``` Here is a command file I used to test: ```markdown --- description: Your weather forecast (Powered by wttr.in) allowed-tools: - Bash(curl *) --- # Context - Get the weather forecast: !`curl wttr.in $ARGUMENTS` Display the weather forecast for $ARGUMENTS ``` I don't have the `allowed-tools` frontmatter setup, because I don't think it is needed? Correct me if I am wrong --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 18:13:59 -05:00
yindo closed this issue 2026-02-16 18:13:59 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#9686