한국어
문서
GitHub

GitHub

GitHub 이슈와 풀 리퀘스트에서 OpenCode를 사용하세요.

OpenCode는 GitHub 워크플로와 통합됩니다. 댓글에서 /opencode 또는 /oc를 멘션하면 OpenCode가 GitHub Actions 러너 내에서 작업을 실행합니다.


기능

  • 이슈 분류 : OpenCode에게 이슈를 살펴보고 설명해 달라고 요청하세요.
  • 수정 및 구현 : OpenCode에게 이슈를 수정하거나 기능을 구현하도록 요청하세요. 그러면 새 브랜치에서 작업하고 모든 변경 사항과 함께 PR을 제출합니다.
  • 안전함 : OpenCode는 GitHub 러너 내부에서 실행됩니다.

설치

GitHub 저장소에 있는 프로젝트에서 다음 명령을 실행하세요:

opencode github install

이는 GitHub 앱 설치, 워크플로 생성, 시크릿 설정을 단계별로 안내합니다.


수동 설정

또는 수동으로 설정할 수 있습니다.

  1. GitHub 앱 설치 github.com/apps/opencode-agent (opens in a new tab)로 이동하세요. 대상 저장소에 설치되어 있는지 확인하세요.

  2. 워크플로 추가 저장소의 .github/workflows/opencode.yml에 다음 워크플로 파일을 추가하세요. modelenv에 필요한 API 키를 적절히 설정하세요.

    .github/workflows/opencode.yml
    name: opencode
     
    on:
      issue_comment:
        types: [created]
      pull_request_review_comment:
        types: [created]
     
    jobs:
      opencode:
        if: |
          contains(github.event.comment.body, '/oc') ||
          contains(github.event.comment.body, '/opencode')
        runs-on: ubuntu-latest
        permissions:
          id-token: write
        steps:
          - name: Checkout repository
            uses: actions/checkout@v6
            with:
              fetch-depth: 1
              persist-credentials: false
     
          - name: Run OpenCode
            uses: anomalyco/opencode/github@latest
            env:
              ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
            with:
              model: anthropic/claude-sonnet-4-20250514
              # share: true
  3. API 키를 시크릿에 저장 조직 또는 프로젝트 settings에서 왼쪽의 Secrets and variables를 펼치고 Actions를 선택하세요. 그리고 필요한 API 키를 추가하세요.


설정

  • model: OpenCode에서 사용할 모델. provider/model 형식을 취합니다. 이는 필수입니다.

  • agent: 사용할 에이전트. 기본(primary) 에이전트여야 합니다. 찾을 수 없으면 설정의 default_agent 또는 "build"로 폴백됩니다.

  • share: OpenCode 세션을 공유할지 여부. 공개 저장소의 경우 기본값은 true입니다.

  • prompt: 기본 동작을 재정의하는 선택적 사용자 정의 프롬프트. OpenCode가 요청을 처리하는 방식을 사용자 정의하는 데 사용하세요.

  • mentions: 대소문자를 구분하지 않는 쉼표로 구분된 트리거 문구 목록입니다. 기본값은 /opencode,/oc입니다.

  • variant: 프로바이더별 추론 강도를 지정하는 모델 variant입니다. 예: high, max, minimal.

  • oidc_base_url: OIDC 토큰 교환 API의 기본 URL입니다. 사용자 지정 GitHub App 설치를 실행할 때만 필요하며 기본값은 https://api.opencode.ai입니다.

  • use_github_token: OIDC로 OpenCode App 설치 토큰을 교환하는 대신 호출자가 제공한 GITHUB_TOKEN을 사용하려면 true로 설정합니다. 기본값은 false입니다. 이 모드는 OpenCode GitHub App을 설치하지 않고 실행할 수 있습니다. env로 토큰을 전달하고 workflow에 필요한 권한을 부여하세요.

    permissions:
      contents: write
      pull-requests: write
      issues: write
     
    steps:
      - uses: anomalyco/opencode/github@latest
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          model: anthropic/claude-sonnet-4-20250514
          use_github_token: true

    이 모드에서는 OIDC 교환을 건너뛰므로 id-token: write가 필요하지 않습니다. personal access token (opens in a new tab) 또는 다른 GitHub App 토큰을 사용하려면 secret으로 저장하고 해당 secret을 GITHUB_TOKEN으로 전달하세요.


지원되는 이벤트

OpenCode는 다음 GitHub 이벤트로 트리거될 수 있습니다:

이벤트 유형트리거세부 정보
issue_comment이슈 또는 PR의 댓글댓글에서 /opencode 또는 /oc를 멘션하세요. OpenCode가 컨텍스트를 읽고 브랜치 생성, PR 열기, 답글을 할 수 있습니다.
pull_request_review_commentPR의 특정 코드 라인 댓글코드를 검토하면서 /opencode 또는 /oc를 멘션하세요. OpenCode가 파일 경로, 라인 번호, diff 컨텍스트를 받습니다.
issues이슈 열림 또는 편집이슈가 생성되거나 수정될 때 OpenCode를 자동으로 트리거합니다. prompt 입력이 필요합니다.
pull_requestPR 열림 또는 업데이트PR이 열리거나, 동기화되거나, 다시 열릴 때 OpenCode를 자동으로 트리거합니다. 자동화된 검토에 유용합니다.
scheduleCron 기반 스케줄OpenCode를 스케줄에 따라 실행합니다. prompt 입력이 필요합니다. 출력은 로그와 PR로 전달됩니다(댓글을 달 이슈가 없음).
workflow_dispatchGitHub UI에서 수동 트리거Actions 탭을 통해 필요에 따라 OpenCode를 트리거합니다. prompt 입력이 필요합니다. 출력은 로그와 PR로 전달됩니다.

스케줄 예시

자동화된 작업을 수행하기 위해 OpenCode를 스케줄에 따라 실행하세요:

.github/workflows/opencode-scheduled.yml
name: Scheduled OpenCode Task
 
on:
  schedule:
    - cron: "0 9 * * 1" # Every Monday at 9am UTC
 
jobs:
  opencode:
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: write
      pull-requests: write
      issues: write
    steps:
      - name: Checkout repository
        uses: actions/checkout@v6
        with:
          persist-credentials: false
 
      - name: Run OpenCode
        uses: anomalyco/opencode/github@latest
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
        with:
          model: anthropic/claude-sonnet-4-20250514
          prompt: |
            Review the codebase for any TODO comments and create a summary.
            If you find issues worth addressing, open an issue to track them.

스케줄 이벤트의 경우, 지침을 추출할 댓글이 없으므로 prompt 입력이 필수입니다. 스케줄 워크플로는 권한을 확인할 사용자 컨텍스트 없이 실행되므로, OpenCode가 브랜치나 PR을 생성하기를 기대한다면 워크플로가 contents: writepull-requests: write를 부여해야 합니다.


풀 리퀘스트 예시

PR이 열리거나 업데이트될 때 자동으로 검토하세요:

.github/workflows/opencode-review.yml
name: opencode-review
 
on:
  pull_request:
    types: [opened, synchronize, reopened, ready_for_review]
 
jobs:
  review:
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: read
      pull-requests: read
      issues: read
    steps:
      - uses: actions/checkout@v6
        with:
          persist-credentials: false
      - uses: anomalyco/opencode/github@latest
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          model: anthropic/claude-sonnet-4-20250514
          use_github_token: true
          prompt: |
            Review this pull request:
            - Check for code quality issues
            - Look for potential bugs
            - Suggest improvements

pull_request 이벤트의 경우, prompt가 제공되지 않으면 OpenCode는 기본적으로 풀 리퀘스트를 검토합니다.


이슈 분류 예시

새 이슈를 자동으로 분류하세요. 이 예시는 스팸을 줄이기 위해 30일 이상 된 계정으로 필터링합니다:

.github/workflows/opencode-triage.yml
name: Issue Triage
 
on:
  issues:
    types: [opened]
 
jobs:
  triage:
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: write
      pull-requests: write
      issues: write
    steps:
      - name: Check account age
        id: check
        uses: actions/github-script@v7
        with:
          script: |
            const user = await github.rest.users.getByUsername({
              username: context.payload.issue.user.login
            });
            const created = new Date(user.data.created_at);
            const days = (Date.now() - created) / (1000 * 60 * 60 * 24);
            return days >= 30;
          result-encoding: string
 
      - uses: actions/checkout@v6
        if: steps.check.outputs.result == 'true'
        with:
          persist-credentials: false
 
      - uses: anomalyco/opencode/github@latest
        if: steps.check.outputs.result == 'true'
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
        with:
          model: anthropic/claude-sonnet-4-20250514
          prompt: |
            Review this issue. If there's a clear fix or relevant docs:
            - Provide documentation links
            - Add error handling guidance for code examples
            Otherwise, do not comment.

issues 이벤트의 경우, 지침을 추출할 댓글이 없으므로 prompt 입력이 필수입니다.


사용자 정의 프롬프트

기본 프롬프트를 재정의하여 워크플로에 맞게 OpenCode의 동작을 사용자 정의하세요.

.github/workflows/opencode.yml
- uses: anomalyco/opencode/github@latest
  with:
    model: anthropic/claude-sonnet-4-5
    prompt: |
      Review this pull request:
      - Check for code quality issues
      - Look for potential bugs
      - Suggest improvements

이는 특정 검토 기준, 코딩 표준, 또는 프로젝트와 관련된 중점 영역을 적용하는 데 유용합니다.


예시

다음은 GitHub에서 OpenCode를 사용하는 몇 가지 예시입니다.

  • 이슈 설명 GitHub 이슈에 이 댓글을 추가하세요.

    /opencode explain this issue

    OpenCode가 모든 댓글을 포함한 전체 스레드를 읽고 명확한 설명으로 답합니다.

  • 이슈 수정 GitHub 이슈에서 이렇게 말하세요:

    /opencode fix this

    그러면 OpenCode가 새 브랜치를 만들고, 변경 사항을 구현하고, 변경 사항과 함께 PR을 엽니다.

  • PR 검토 및 변경 GitHub PR에 다음 댓글을 남기세요.

    Delete the attachment from S3 when the note is removed /oc

    OpenCode가 요청된 변경을 구현하고 같은 PR에 커밋합니다.

  • 특정 코드 라인 검토 PR의 "Files" 탭에서 코드 라인에 직접 댓글을 남기세요. OpenCode는 정확한 응답을 제공하기 위해 파일, 라인 번호, diff 컨텍스트를 자동으로 감지합니다.

    [Comment on specific lines in Files tab]
    /oc add error handling here

    특정 라인에 댓글을 달면 OpenCode는 다음을 받습니다:

    • 검토 중인 정확한 파일
    • 특정 코드 라인
    • 주변 diff 컨텍스트
    • 라인 번호 정보

    이를 통해 파일 경로나 라인 번호를 수동으로 지정할 필요 없이 더 표적화된 요청이 가능합니다.