GitHub
GitHub の issue やプルリクエストで OpenCode を使用します。
OpenCode はあなたの GitHub ワークフローと連携します。コメントで /opencode または /oc をメンションすると、OpenCode は GitHub Actions ランナー内でタスクを実行します。
機能
- issue のトリアージ : OpenCode に issue を調査して説明するよう依頼できます。
- 修正と実装 : OpenCode に issue の修正や機能の実装を依頼できます。新しいブランチで作業し、すべての変更を含む PR を提出します。
- 安全 : OpenCode はあなたの GitHub のランナー内で実行されます。
インストール
GitHub リポジトリ内にあるプロジェクトで、次のコマンドを実行します:
opencode github installこれにより、GitHub アプリのインストール、ワークフローの作成、シークレットのセットアップが順を追って案内されます。
手動セットアップ
または、手動でセットアップすることもできます。
-
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 -
API キーをシークレットに保存する 組織またはプロジェクトの settings で、左側の Secrets and variables を展開し、Actions を選択します。そして必要な API キーを追加します。
設定
-
model: OpenCode で使用するモデル。provider/modelの形式を取ります。これは必須です。 -
agent: 使用するエージェント。プライマリエージェントである必要があります。見つからない場合は、設定のdefault_agentまたは"build"にフォールバックします。 -
share: OpenCode セッションを共有するかどうか。パブリックリポジトリではデフォルトで true です。 -
prompt: デフォルトの動作をオーバーライドする任意のカスタムプロンプト。OpenCode がリクエストを処理する方法をカスタマイズするために使用します。 -
mentions: 大文字と小文字を区別しない、カンマ区切りのトリガーフレーズ一覧です。デフォルトは/opencode,/ocです。 -
variant: プロバイダー固有の推論強度を指定するモデルバリアントです。例:high、max、minimal。 -
oidc_base_url: OIDC トークン交換 API のベース URL です。カスタム GitHub App インストールを実行する場合にのみ必要です。デフォルトはhttps://api.opencode.aiです。 -
use_github_token:trueに設定すると、OIDC で OpenCode App のインストールトークンを交換せず、呼び出し元が指定したGITHUB_TOKENを使用します。デフォルトはfalseです。このモードでは OpenCode GitHub App をインストールせずに実行できます。envでトークンを渡し、ワークフローに必要な権限を付与してください。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 イベントによってトリガーできます:
| 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 に送られます。 |
スケジュールの例
スケジュールに沿って 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 を付与する必要があります。
プルリクエストの例
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 はデフォルトでプルリクエストのレビューを行います。
Issueのトリアージの例
新しい 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 入力は必須です。
カスタムプロンプト
デフォルトのプロンプトをオーバーライドして、ワークフローに合わせて 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これは、プロジェクトに関連する特定のレビュー基準、コーディング標準、または重点領域を強制するのに便利です。
例
ここでは、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 コンテキスト
- 行番号の情報
これにより、ファイルパスや行番号を手動で指定する必要なく、より的を絞ったリクエストが可能になります。