한국어
문서
명령어

명령어

반복 작업을 위한 사용자 정의 명령어를 만드세요.

사용자 정의 명령어를 사용하면 TUI에서 해당 명령어가 실행될 때 실행하고 싶은 프롬프트를 지정할 수 있습니다.

/my-command

사용자 정의 명령어는 /init, /undo, /redo, /share, /help 같은 내장 명령어에 더해 추가됩니다. 자세히 알아보기.


명령어 파일 만들기

commands/ 디렉토리에 마크다운 파일을 만들어 사용자 정의 명령어를 정의합니다.

.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/ 디렉토리에 마크다운 파일을 만들어 사용자 정의 명령어를 추가할 수 있습니다.


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

마크다운

마크다운 파일을 사용하여 명령어를 정의할 수도 있습니다. 다음 위치에 배치하세요:

  • 전역: ~/.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.

마크다운 파일 이름이 명령어 이름이 됩니다. 예를 들어 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" }

셸 출력

!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 설정을 사용하여 이 명령어를 실행할 에이전트를 선택적으로 지정하세요. 이것이 서브에이전트인 경우 명령어는 기본적으로 서브에이전트 호출을 트리거합니다. 이 동작을 비활성화하려면 subtaskfalse로 설정하세요.

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

이는 선택적 설정 옵션입니다. 지정하지 않으면 현재 에이전트가 기본값으로 사용됩니다.


Subtask

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

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 같은 여러 내장 명령어가 포함되어 있습니다. 자세히 알아보기.

참고: 사용자 정의 명령어는 내장 명령어를 재정의할 수 있습니다.

같은 이름의 사용자 정의 명령어를 정의하면 내장 명령어를 재정의합니다.