GitHub
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 にアクセスし、対象のリポジトリにインストールされていることを確認します。
-
ワークフローを追加する
以下のワークフローファイルをリポジトリ内の
.github/workflows/opencode.ymlに追加します。env内で適切なmodelと必要な API キーを設定してください。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 # github_token: xxxx -
API キーをシークレットに保存する
組織またはプロジェクトの Settings で、左側の Secrets and variables を展開し Actions を選択します。必要な API キーを追加します。
設定
-
model:OpenCode で使用するモデル。provider/modelの形式で指定します。これは必須です。 -
agent:使用するエージェント。プライマリエージェントである必要があります。見つからない場合は設定のdefault_agent、それでもなければ"build"にフォールバックします。 -
share:OpenCode セッションを共有するかどうか。公開リポジトリではデフォルトで true になります。 -
prompt:デフォルトの動作を上書きする任意のカスタムプロンプト。OpenCode によるリクエスト処理方法をカスタマイズする際に使用します。 -
token:コメントの作成、変更のコミット、プルリクエストのオープンなどの操作に使用する任意の GitHub アクセストークン。デフォルトでは、OpenCode は OpenCode GitHub App のインストールアクセストークンを使用するため、コミット、コメント、プルリクエストはアプリからのものであるかのように表示されます。あるいは、OpenCode GitHub App をインストールせずに、GitHub Actions ランナーの 組み込み
GITHUB_TOKENを使用することもできます。その場合は、ワークフロー内で必要な権限を付与してください。permissions: id-token: write contents: write pull-requests: write issues: write必要であれば、personal access token(PAT) を使用することもできます。
サポートされるイベント
OpenCode は以下の GitHub イベントをトリガーとして使用できます。
| Event Type | Triggered By | Details |
|---|---|---|
issue_comment | Issue や PR へのコメント | コメント内で /opencode または /oc をメンションします。OpenCode はコンテキストを読み取り、ブランチの作成、PR のオープン、返信が可能です。 |
pull_request_review_comment | PR 内の特定のコード行へのコメント | コードレビュー中に /opencode または /oc をメンションします。OpenCode はファイルパス、行番号、差分コンテキストを受け取ります。 |
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 improvements
pull_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 はファイル、行番号、差分コンテキストを自動的に検出し、正確な応答を提供します。
[Comment on specific lines in Files tab] /oc add error handling here特定の行にコメントすると、OpenCode は次のような情報を受け取ります。
- レビュー対象の正確なファイル
- 対象のコード行
- 周辺の差分コンテキスト
- 行番号情報
これにより、ファイルパスや行番号を手動で指定することなく、より的を絞ったリクエストが可能になります。