Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

OpenCode GitHub

OpenCode GitHub

OpenCode can deeply integrate with GitHub workflows, letting AI directly participate in Issues, Pull Requests, and code review processes.

By entering /opencode or /oc in a comment, you can trigger the AI to automatically execute tasks.

OpenCode GitHub = turn AI into your automated development member, directly participating in Issues, PRs, and code flows.


I. Core capabilities

Characteristics:


II. Quick install (recommended)

Run in the root of your GitHub project:


opencode github install

This command automatically:


III. Manual install (advanced)

1. Install the GitHub App

to access:


https://github.com/apps/opencode-agent

Install it into your repository


2. Add a workflow file

Create a file:


.github/workflows/opencode.yml

Example:


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

3. Configure Secrets

In your GitHub repository:


IV. Configuration parameter description

Parameters Description
model Model to use (required)
agent Specify agent
prompt Custom prompt
share Whether to share the session
token GitHub Token

Explanation:


V. Supported trigger events

Events Description
issue_comment Comment trigger /opencode
pull_request_review_comment Code line comment trigger
issues Issue create/update
pull_request PR auto-review
schedule Scheduled Tasks
workflow_dispatch Manual trigger

VI. Common usage patterns

1. Explain an Issue

In an Issue comment:


/opencode explain this issue

AI will summarize the problem and explain it


2. Auto-fix an Issue


/opencode fix this

Automatically:


3. Modify a PR


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

Perform modifications directly on the PR


4. Line-level operations (very powerful)

Comment on the Files tab of a PR:


/oc add error handling here

OpenCode will automatically fetch:

No need to manually specify the location


VII. Scheduled tasks (automation)

Example: scan to-do items weekly


on:
  schedule:
    - cron: "0 9 * * 1"

Example prompt:


Review the codebase for TODO comments and summarize them

Note:


VIII. PR auto-review

Example:


on:
  pull_request:
    types: [opened, synchronize]

Default behavior:


IX. Issue auto-classification

Can automatically handle new Issues, for example:

Note:


X. Custom prompts (advanced usage)

Can override the default behavior:


prompt: |
  Review this pull request:
  - Check for bugs
  - Suggest improvements

Used for:


XI. Security and permissions

Recommended permission configuration:


permissions:
  id-token: write
  contents: write
  pull-requests: write
  issues: write

Explanation: