한국어
문서
명령어

명령어

반복적인 작업을 위한 커스텀 명령어를 만드세요.

커스텀 명령어를 사용하면 TUI에서 해당 명령어를 실행할 때 실행할 프롬프트를 지정할 수 있습니다.

/my-command

커스텀 명령어는 /init, /undo, /redo, /share, /help와 같은 내장 명령어에 추가됩니다. 자세히 알아보기.


명령어 파일 만들기

commands/ 디렉토리에 markdown 파일을 만들어 커스텀 명령어를 정의합니다.

.opencode/commands/test.md 만들기:

.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

설정

OpenCode 설정을 통해 또는 commands/ 디렉토리에 markdown 파일을 만들어 커스텀 명령어를 추가할 수 있습니다.


JSON

OpenCode 설정에서 command 옵션을 사용합니다:

opencode.jsonc
{
  "$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/
~/.config/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.

markdown 파일 이름이 명령어 이름이 됩니다. 예를 들어, test.md는 다음을 실행할 수 있게 합니다:

/test

프롬프트 설정

커스텀 명령어의 프롬프트는 여러 특수 플레이스홀더와 구문을 지원합니다.


인수

$ARGUMENTS 플레이스홀더를 사용하여 명령어에 인수를 전달합니다.

.opencode/commands/component.md
---
description: Create a new component
---
 
Create a new React component named $ARGUMENTS with TypeScript support.
Include proper typing and basic structure.

인수와 함께 명령어 실행:

/component Button

$ARGUMENTSButton으로 대체됩니다.

위치 매개변수를 사용하여 개별 인수에 액세스할 수도 있습니다:

  • $1 - 첫 번째 인수
  • $2 - 두 번째 인수
  • $3 - 세 번째 인수
  • 계속...

예를 들어:

.opencode/commands/create-file.md
---
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\" }"

이것은 다음을 대체합니다:

  • $1config.json으로
  • $2src
  • $3{ "key": "value" }

Shell 출력

*!command*를 사용하여 bash 명령어 출력을 프롬프트에 주입합니다.

예를 들어, 테스트 커버리지를 분석하는 커스텀 명령어를 만들려면:

.opencode/commands/analyze-coverage.md
---
description: Analyze test coverage
---
 
Here are the current test results:
!`npm test`
 
Based on these results, suggest improvements to increase coverage.

또는 최근 변경 사항을 검토하려면:

.opencode/commands/review-changes.md
---
description: Review recent changes
---
 
Recent git commits:
!`git log --oneline -10`
 
Review these changes and suggest any improvements.

명령어는 프로젝트의 루트 디렉토리에서 실행되며 출력은 프롬프트의 일부가 됩니다.


파일 참조

@ 다음에 파일 이름을 사용하여 명령어에 파일을 포함합니다.

.opencode/commands/review-component.md
---
description: Review component
---
 
Review the component in @src/components/Button.tsx.
Check for performance issues and suggest improvements.

파일 내용이 자동으로 프롬프트에 포함됩니다.


옵션

설정 옵션을 자세히 살펴보겠습니다.


Template

template 옵션은 명령어가 실행될 때 LLM에 전송될 프롬프트를 정의합니다.

opencode.json
{
  "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 옵션을 사용하여 명령어가 수행하는 작업에 대한 간단한 설명을 제공합니다.

opencode.json
{
  "command": {
    "test": {
      "description": "Run tests with coverage"
    }
  }
}

TUI에서 명령어를 입력할 때 설명으로 표시됩니다.


Agent

agent 설정을 사용하여 이 명령어를 실행할 agent를 선택적으로 지정합니다. 이것이 subagent인 경우 명령어는 기본적으로 subagent 호출을 트리거합니다. 이 동작을 비활성화하려면 subtaskfalse로 설정합니다.

opencode.json
{
  "command": {
    "review": {
      "agent": "plan"
    }
  }
}

이것은 선택적 설정 옵션입니다. 지정하지 않으면 현재 agent가 기본값입니다.


Subtask

subtask 불리언을 사용하여 명령어가 subagent 호출을 트리거하도록 강제합니다. 명령어가 기본 컨텍스트를 오염시키지 않도록 하려는 경우 유용하며, agent 설정에서 modeprimary로 설정되어 있어도 agent가 subagent로 작동하도록 강제합니다.

opencode.json
{
  "command": {
    "analyze": {
      "subtask": true
    }
  }
}

이것은 선택적 설정 옵션입니다.


Model

model 설정을 사용하여 이 명령어의 기본 모델을 재정의합니다.

opencode.json
{
  "command": {
    "analyze": {
      "model": "anthropic/claude-3-5-sonnet-20241022"
    }
  }
}

이것은 선택적 설정 옵션입니다.


내장 명령어

OpenCode에는 /init, /undo, /redo, /share, /help와 같은 여러 내장 명령어가 포함되어 있습니다; 자세히 알아보기.

참고

커스텀 명령어는 내장 명령어를 재정의할 수 있습니다.

동일한 이름의 커스텀 명령어를 정의하면 내장 명령어를 재정의합니다.