mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-26 20:24:21 +01:00
slash commands (#2157)
Co-authored-by: adamdotdevin <2363879+adamdottv@users.noreply.github.com>
This commit is contained in:
167
packages/web/src/content/docs/docs/commands.mdx
Normal file
167
packages/web/src/content/docs/docs/commands.mdx
Normal file
@@ -0,0 +1,167 @@
|
||||
---
|
||||
title: Commands
|
||||
description: 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`:
|
||||
|
||||
```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.
|
||||
|
||||
```bash frame="none"
|
||||
"/test"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Create command files
|
||||
|
||||
For complex commands, create markdown files in the `command/` directory.
|
||||
|
||||
Create `.opencode/command/test.md`:
|
||||
|
||||
```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 arguments
|
||||
|
||||
Pass arguments to commands using the `$ARGUMENTS` placeholder.
|
||||
|
||||
```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:
|
||||
|
||||
```bash frame="none"
|
||||
"/component Button"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Inject shell output
|
||||
|
||||
Use `!`command`` to inject shell command output into your prompt.
|
||||
|
||||
```md
|
||||
---
|
||||
description: Analyze test coverage
|
||||
---
|
||||
|
||||
Here are the current test results:
|
||||
`!npm test`
|
||||
|
||||
Based on these results, suggest improvements to increase coverage.
|
||||
```
|
||||
|
||||
```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.
|
||||
|
||||
```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
|
||||
|
||||
```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.
|
||||
@@ -41,26 +41,10 @@ You can also install it with the following:
|
||||
- **Using Node.js**
|
||||
|
||||
<Tabs>
|
||||
<TabItem label="npm">
|
||||
```bash
|
||||
npm install -g opencode-ai
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem label="Bun">
|
||||
```bash
|
||||
bun install -g opencode-ai
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem label="pnpm">
|
||||
```bash
|
||||
pnpm install -g opencode-ai
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem label="Yarn">
|
||||
```bash
|
||||
yarn global add opencode-ai
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem label="npm">```bash npm install -g opencode-ai ```</TabItem>
|
||||
<TabItem label="Bun">```bash bun install -g opencode-ai ```</TabItem>
|
||||
<TabItem label="pnpm">```bash pnpm install -g opencode-ai ```</TabItem>
|
||||
<TabItem label="Yarn">```bash yarn global add opencode-ai ```</TabItem>
|
||||
</Tabs>
|
||||
|
||||
- **Using Homebrew on macOS and Linux**
|
||||
@@ -308,4 +292,4 @@ Here's an [example conversation](https://opencode.ai/s/4XP1fce5) with opencode.
|
||||
|
||||
And that's it! You are now a pro at using opencode.
|
||||
|
||||
To make it your own, we recommend [picking a theme](/docs/themes), [customizing the keybinds](/docs/keybinds), [configuring code formatters](/docs/formatters), or playing around with the [opencode config](/docs/config).
|
||||
To make it your own, we recommend [picking a theme](/docs/themes), [customizing the keybinds](/docs/keybinds), [configuring code formatters](/docs/formatters), [creating custom commands](/docs/commands), or playing around with the [opencode config](/docs/config).
|
||||
|
||||
Reference in New Issue
Block a user