Commands

Create custom commands for repetitive tasks.

Define custom commands to automate repetitive coding tasks.


Create command files

Create markdown files in the command/ directory to define custom commands.

Create .opencode/command/test.md:

.opencode/command/test.md
---
description: Run tests with coverage
agent: build
model: anthropic/claude-3-5-sonnet-20241022
---

Run the full test suite with coverage report and show any failures.
Focus on the failing tests and suggest fixes.

The frontmatter defines command properties. The content becomes the template.

Use the command by typing / followed by the command name.

"/test"

Use arguments

Pass arguments to commands using the $ARGUMENTS placeholder.

Create .opencode/command/component.md:

.opencode/command/component.md
---
description: Create a new component
---

Create a new React component named $ARGUMENTS with TypeScript support.
Include proper typing and basic structure.

Run the command with arguments:

"/component Button"

Inject shell output

Use !command to inject shell command output into your prompt.

Create .opencode/command/analyze-coverage.md:

.opencode/command/analyze-coverage.md
---
description: Analyze test coverage
---

Here are the current test results:
`!npm test`

Based on these results, suggest improvements to increase coverage.

Create .opencode/command/review-changes.md:

.opencode/command/review-changes.md
---
description: Review recent changes
---

Recent git commits:
`!git log --oneline -10`

Review these changes and suggest any improvements.

Commands run in your project's root directory and their output becomes part of the prompt.


Reference files

Include files in your command using @ followed by the filename.

Create .opencode/command/review-component.md:

.opencode/command/review-component.md
---
description: Review component
---

Review the component in @src/components/Button.tsx.
Check for performance issues and suggest improvements.

The file content gets included in the prompt automatically.


Command properties

Configure commands with these optional frontmatter properties:

  • description: Brief explanation of what the command does

  • agent: Agent to use (defaults to "build")

  • model: Specific model to use for this command

Create .opencode/command/code-review.md:

.opencode/command/code-review.md
---
description: Code review assistant
agent: build
model: anthropic/claude-3-5-sonnet-20241022
---

Review the code for best practices and suggest improvements.

Command directory

Store command files in these locations:

  • .opencode/command/ - Project-specific commands

  • command/ - Global commands in config directory

Project commands take precedence over global ones.


Built-in commands

opencode includes several built-in commands:

  • /init - Initialize project and create AGENTS.md

  • /undo - Revert the last changes

  • /redo - Restore reverted changes

  • /share - Share the current conversation

  • /help - Show available commands and keybinds

Use /help to see all available commands in your setup.

How is this guide?

Last updated on

Powered by Holocron

Documentation