GitHub
GitHub の issue やプルリクエストで OpenCode を使用します。
OpenCode はあなたの GitHub ワークフローと連携します。コメントで /opencode または /oc をメンションすると、OpenCode は GitHub Actions ランナー内でタスクを実行します。
Features
- issue のトリアージ : OpenCode に issue を調査して説明するよう依頼できます。
- 修正と実装 : OpenCode に issue の修正や機能の実装を依頼できます。新しいブランチで作業し、すべての変更を含む PR を提出します。
- 安全 : OpenCode はあなたの GitHub のランナー内で実行されます。
Installation
GitHub リポジトリ内にあるプロジェクトで、次のコマンドを実行します:
opencode github installこれにより、GitHub アプリのインストール、ワークフローの作成、シークレットのセットアップが順を追って案内されます。
Manual Setup
または、手動でセットアップすることもできます。
-
GitHub アプリをインストールする github.com/apps/opencode-agent (opens in a new tab) にアクセスします。対象のリポジトリにインストールされていることを確認してください。
-
ワークフローを追加する リポジトリの
.github/workflows/opencode.ymlに次のワークフローファイルを追加します。envで適切なmodelと必要な API キーを設定することを忘れないでください。.github/workflows/opencode.ymlname: 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 # github_token: xxxx -
API キーをシークレットに保存する 組織またはプロジェクトの settings で、左側の Secrets and variables を展開し、Actions を選択します。そして必要な API キーを追加します。
Configuration
-
model: OpenCode で使用するモデル。provider/modelの形式を取ります。これは必須です。 -
agent: 使用するエージェント。プライマリエージェントである必要があります。見つからない場合は、設定のdefault_agentまたは"build"にフォールバックします。 -
share: OpenCode セッションを共有するかどうか。パブリックリポジトリではデフォルトで true です。 -
prompt: デフォルトの動作をオーバーライドする任意のカスタムプロンプト。OpenCode がリクエストを処理する方法をカスタマイズするために使用します。 -
token: コメントの作成、変更のコミット、プルリクエストのオープンなどの操作を実行するための任意の GitHub アクセストークン。デフォルトでは、OpenCode は OpenCode GitHub App のインストールアクセストークンを使用するため、コミット、コメント、プルリクエストはアプリからのものとして表示されます。あるいは、OpenCode GitHub App をインストールせずに、GitHub Action ランナーの組み込みGITHUB_TOKEN(opens in a new tab) を使うこともできます。その場合は、ワークフローで必要な権限を付与することを忘れないでください:permissions: id-token: write contents: write pull-requests: write issues: write必要に応じて、個人アクセストークン (opens in a new tab)(PAT)を使うこともできます。
Supported Events
OpenCode は、次の GitHub イベントによってトリガーできます:
| Event Type | Triggered By | Details |
|---|---|---|
issue_comment | issue または PR へのコメント | コメントで /opencode または /oc をメンションします。OpenCode はコンテキストを読み取り、ブランチの作成、PR のオープン、返信を行えます。 |
pull_request_review_comment | PR 内の特定のコード行へのコメント | コードのレビュー中に /opencode または /oc をメンションします。OpenCode はファイルパス、行番号、diff のコンテキストを受け取ります。 |
issues | issue のオープンまたは編集 | issue が作成または変更されたときに OpenCode を自動的にトリガーします。prompt 入力が必要です。 |
pull_request | PR のオープンまたは更新 | PR がオープン、同期、または再オープンされたときに OpenCode を自動的にトリガーします。自動レビューに便利です。 |
schedule | Cron ベースのスケジュール | スケジュールに沿って OpenCode を実行します。prompt 入力が必要です。出力はログと PR に送られます(コメントする issue がありません)。 |
workflow_dispatch | GitHub UI からの手動トリガー | Actions タブから OpenCode をオンデマンドでトリガーします。prompt 入力が必要です。出力はログと PR に送られます。 |
Schedule Example
スケジュールに沿って OpenCode を実行し、自動タスクを実行します:
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: write と pull-requests: write を付与する必要があります。
Pull Request Example
PR がオープンまたは更新されたときに、自動的にレビューします:
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 improvementspull_request イベントでは、prompt が指定されていない場合、OpenCode はデフォルトでプルリクエストのレビューを行います。
Issues Triage Example
新しい issue を自動的にトリアージします。この例では、スパムを減らすために 30 日より古いアカウントに絞り込んでいます:
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 入力は必須です。
Custom prompts
デフォルトのプロンプトをオーバーライドして、ワークフローに合わせて OpenCode の動作をカスタマイズします。
- 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これは、プロジェクトに関連する特定のレビュー基準、コーディング標準、または重点領域を強制するのに便利です。
Examples
ここでは、GitHub で OpenCode を使う方法の例をいくつか紹介します。
-
issue を説明する GitHub の issue にこのコメントを追加します。
/opencode explain this issueOpenCode はすべてのコメントを含むスレッド全体を読み、明確な説明を返信します。
-
issue を修正する GitHub の issue で次のように言います:
/opencode fix thisすると OpenCode は新しいブランチを作成し、変更を実装し、その変更を含む PR を開きます。
-
PR をレビューして変更する GitHub の PR に次のコメントを残します。
Delete the attachment from S3 when the note is removed /ocOpenCode は要求された変更を実装し、同じ PR にコミットします。
-
特定のコード行をレビューする PR の「Files」タブでコード行に直接コメントを残します。OpenCode はファイル、行番号、diff のコンテキストを自動的に検出し、正確な応答を提供します。
[Comment on specific lines in Files tab] /oc add error handling here特定の行にコメントすると、OpenCode は次のものを受け取ります:
- レビュー対象の正確なファイル
- 特定のコード行
- 周囲の diff コンテキスト
- 行番号の情報
これにより、ファイルパスや行番号を手動で指定する必要なく、より的を絞ったリクエストが可能になります。