コマンド
Commands
カスタムコマンドを使用すると、そのコマンドが TUI で実行されるときに実行するプロンプトを指定できます。
/my-command
カスタムコマンドは、/init、/undo、/redo、/share、/help などの組み込みコマンドに加えて使用できます。詳細。
Create command files
commands/ ディレクトリに Markdownファイルを作成してカスタムコマンドを定義します。
.opencode/commands/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.
Frontmatter はコマンドプロパティを定義します。コンテンツがテンプレートになります。
コマンド名を入力してコマンドを使用します。
"/test"
Configure
カスタムコマンドは OpenCode 設定または commands/ ディレクトリ内の Markdown ファイル作成 を通じて追加できます。
JSON
OpenCode config の command オプションを使用します:
{
"$schema": "https://opencode.ai/config.json",
"command": {
// This becomes the name of the command
"test": {
// This is the prompt that will be sent to the LLM
"template": "Run the full test suite with coverage report and show any failures.\nFocus on the failing tests and suggest fixes.",
// This is shown as the description in the TUI
"description": "Run tests with coverage",
"agent": "build",
"model": "anthropic/claude-3-5-sonnet-20241022"
}
}
} これで TUI でこのコマンドを実行できます:
/test
Markdown
Markdown ファイルを使用してコマンドを定義することもできます。それらを配置する場所:
- グローバル:
~/.config/opencode/commands/ - プロジェクトごと:
.opencode/commands/
---
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.
Markdown ファイル名がコマンド名になります。例えば、test.md を使用すると:
/test
Prompt config
カスタムコマンドのプロンプトは、いくつかの特別なプレースホルダーと構文をサポートしています。
Arguments
$ARGUMENTS プレースホルダーを使用してコマンドに引数を渡します。
---
description: Create a new component
---
Create a new React component named $ARGUMENTS with TypeScript support.
Include proper typing and basic structure.
引数付きでコマンドを実行します:
/component Button
$ARGUMENTS は Button に置き換えられます。
位置パラメータを使用して個々の引数にアクセスすることもできます:
$1-最初の引数$2- 2番目の引数$3- 3 番目の引数- 以下同様…
例えば:
---
description: Create a new file with content
---
Create a file named $1 in the directory $2
with the following content: $3
コマンドを実行します:
/create-file config.json src "{ \"key\": \"value\" }"
これにより置き換えられます:
$1→config.json$2→src$3→{ "key": "value" }
Shell output
!command を使用して bashコマンドの出力をプロンプトに挿入します。
例えば、テストカバレッジを分析するカスタムコマンドを作成するには:
---
description: Analyze test coverage
---
Here are the current test results:
!`npm test`
Based on these results, suggest improvements to increase coverage.
または、最近の変更を確認するには:
---
description: Review recent changes
---
Recent git commits:
!`git log --oneline -10`
Review these changes and suggest any improvements.
コマンドはプロジェクトルートディレクトリで実行され、出力がプロンプトの一部になります。
File references
@ に続けてファイル名を使用して、コマンドにファイルをインクルードします。
---
description: Review component
---
Review the component in @src/components/Button.tsx.
Check for performance issues and suggest improvements.
ファイルコンテンツは自動的にプロンプトにインクルードされます。
Options
設定オプションを詳しく見てみましょう。
Template
template オプションは、コマンド実行時に LLM に送信されるプロンプトを定義します。
{
"command": {
"test": {
"template": "Run the full test suite with coverage report and show any failures.\nFocus on the failing tests and suggest fixes."
}
}
} これは 必須 の設定オプションです。
Description
description オプションを使用して、コマンドが何をするかの簡単な説明を提供します。
{
"command": {
"test": {
"description": "Run tests with coverage"
}
}
} コマンド入力時に TUI で説明として表示されます。
Agent
agent 設定を使用して、このコマンドを実行する agent をオプションで指定できます。Subagent の場合、コマンドはデフォルトでサブタスク呼び出しをトリガーします。この動作を無効にするには、subtask を false に設定します。
{
"command": {
"review": {
"agent": "plan"
}
}
} これは オプション の設定オプションです。指定しない場合、現在の agent がデフォルトになります。
Subtask
subtask ブール値を使用して、コマンドに subagent 呼び出しを強制させます。これは、コマンドがプライマリコンテキストを汚さないようにしたい場合に便利です。また、agent 設定で mode が primary に設定されていても、エージェントをサブエージェントとして動作することを 強制 します。
{
"command": {
"analyze": {
"subtask": true
}
}
} これは オプション の設定オプションです。
Model
model 設定を使用して、このコマンドのデフォルトモデルを上書きします。
{
"command": {
"analyze": {
"model": "anthropic/claude-3-5-sonnet-20241022"
}
}
} これは オプション の設定オプションです。
Built-in
opencode には、/init、/undo、/redo、/share、/help などの組み込みコマンドが含まれています。詳細。