Skip to content
This repository was archived by the owner on Jul 29, 2025. It is now read-only.

feat: custom commands #133

Merged
merged 12 commits into from
May 9, 2025

Conversation

ezynda3
Copy link
Contributor

@ezynda3 ezynda3 commented May 1, 2025

Users can create custom commands by adding .md files to their configured <data_dir>/commands dir (default is .opencode/commands). They can then open the command dialog as normal with cttrl+k and select one of the custom commands.

Custom commands are simply prompts and work similar to custom slash commands in Claude Code
ref: https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/tutorials#create-custom-slash-commands

Addresses: #132

@ezynda3 ezynda3 changed the title Implement custom commands feat: custom commands May 1, 2025
@@ -56,6 +57,12 @@ func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if cmd != nil {
return p, cmd
}
case dialog.CommandRunCustomMsg:
// Handle custom command execution
cmd := p.sendMessage(msg.Content)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to check if the agent is busy here before we send the message.
p.app.CoderAgent.IsBusy()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's busy what should the behavior be?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess just returning a warning should be fine right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you already did what I wanted to suggest 😂 awesome.

@kujtimiihoxha
Copy link
Collaborator

@ezynda3 do you mind adding a section for this in the readme?

@ezynda3
Copy link
Contributor Author

ezynda3 commented May 2, 2025

@ezynda3 do you mind adding a section for this in the readme?

Done!

README.md Outdated

Global
```
$HOME/.opencode/commands/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the code is actually looking for this global dir? maybe I am missing something but I think this is a good idea to add.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@ezynda3
Copy link
Contributor Author

ezynda3 commented May 3, 2025

@kujtimiihoxha So it now looks in the global opencode config dir as well as the project level data dir and prefixes with either user: or project:

@kujtimiihoxha
Copy link
Collaborator

checking this now.. sorry it took so long.

Copy link
Collaborator

@kujtimiihoxha kujtimiihoxha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an awesome addition 🙌 just a couple of small things.

Maybe later we could make it possible to have multiple inputs and anything that starts with $ and is all upper case could be considered a variable... this way we could add many variables and not be limited to one.

var commands []Command

// Load user commands from XDG_CONFIG_HOME/opencode/commands
xdgConfigHome := os.Getenv("XDG_CONFIG_HOME")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also make it possible to add commands in $HOME/.opencode/commands this way this behaves similar to the config path defaults.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kujtimiihoxha updated

ezynda3 and others added 2 commits May 9, 2025 17:16
@kujtimiihoxha kujtimiihoxha merged commit a58e607 into opencode-ai:main May 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants