OpenCode School

Lesson 7

Commands

Create custom slash commands for tasks you run repeatedly.

If you find yourself typing the same kind of prompt over and over — “summarize this project”, “review my changes”, “explain this file” — custom commands let you save that prompt and run it with a single slash command.

Type / in the input and you’ll see a list of available commands. Built-in commands like /new, /undo, and /help are always there. Custom commands you create show up in the same list.

Two ways to define a command

Markdown files

Create a .md file in ~/.config/opencode/commands/ (global, available in every project) or .opencode/commands/ (per-project). The filename becomes the command name.

~/.config/opencode/commands/summarize.md:

---
description: Summarize the current project
---
Give me a brief overview of this project. What is it? What are the main files and folders? What does it seem to be for?

Now you can run /summarize in any OpenCode session.

JSON in opencode.jsonc

You can also define commands directly in your config file:

{
  "$schema": "https://opencode.ai/config.json",
  "command": {
    "summarize": {
      "description": "Summarize the current project",
      "template": "Give me a brief overview of this project. What is it? What are the main files and folders? What does it seem to be for?"
    }
  }
}

Both approaches produce the same result. Markdown files are easier to read and edit; JSON is convenient if you want everything in one config file.

Try it: create a /summarize command

Ask OpenCode to create the file ~/.config/opencode/commands/summarize.md with this content:

---
description: Summarize the current project
---
Give me a brief overview of this project. What is it? What are the main files and folders? What does it seem to be for?

Then restart OpenCode. Commands are loaded at startup, so new command files won’t appear until you reopen the app.

Once you’re back, type /summarize in the input — you should see it appear in the autocomplete list. Select it and hit Return to run it.

Passing arguments

Add a $ARGUMENTS placeholder to your template and you can pass extra context when invoking the command:

---
description: Explain a file
---
Explain what $ARGUMENTS does in plain language.

Then run it as /explain src/index.ts and $ARGUMENTS gets replaced with src/index.ts.

More options

Commands support a few other options in their frontmatter: agent (run the command with a specific agent) and model (use a specific model for this command). We’ll cover agents in a later lesson. For the full reference, see the commands documentation.