OpenCode GitHub
OpenCode can deeply integrate with GitHub workflows, allowing AI to directly participate in Issue, Pull Request, and code review processes.
By entering /opencode or /oc in a comment, you can trigger AI to automatically execute tasks.
OpenCode GitHub = Turn AI into your automated development team member, directly participating in Issue, PR, and code workflows.
1. Core Capabilities
- Issue Analysis:Automatically understand problems and provide explanations
- Automatic Fix:Create a branch and submit a PR
- Code Review:Analyze PR and suggest improvements
- Automated Execution:Runs on GitHub Actions
Features:
- Runs in your own GitHub Runner
- Secure and controllable, does not rely on external servers to execute code
2. Quick Install (Recommended)
Run in the GitHub project root directory:
opencode github install
This command will automatically complete:
- Install GitHub App
- Create GitHub Actions workflow
- Guide configuration of API Key
3. Manual Install (Advanced)
1. Install GitHub App
Visit:
https://github.com/apps/opencode-agent
Install to your repository
2. Add Workflow File
Create 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 the GitHub repository:
- Go to Settings → Secrets → Actions
- Add API Key (e.g., ANTHROPIC_API_KEY)
4. Configuration Parameter Reference
| Parameter | Description |
|---|---|
| model | Model to use (required) |
| agent | Specify proxy |
| prompt | Custom prompt |
| share | Whether to share session |
| token | GitHub Token |
Notes:
- Uses the OpenCode GitHub App Token by default
- You can also use GITHUB_TOKEN or PAT
5. Supported Trigger Events
| Event | Description |
|---|---|
| issue_comment | Comment trigger /opencode |
| pull_request_review_comment | Code line comment trigger |
| issues | Issue created/updated |
| pull_request | PR automatic review |
| schedule | Scheduled task |
| workflow_dispatch | Manual trigger |
6. Common Usage Methods
1. Explain Issue
In Issue comment:
/opencode explain this issue
AI will summarize the problem and explain
2. Automatically Fix Issue
/opencode fix this
Automatically:
- Create branch
- Modify code
- Submit Pull Request
3. Modify PR
Delete the attachment from S3 when the note is removed /oc
Execute modifications directly on the PR
4. Code Line-Level Operations (Very Powerful)
Comment on the Files page of the PR:
/oc add error handling here
OpenCode will automatically retrieve:
- File path
- Line number
- Context diff
No need to manually specify the location
7. Scheduled Tasks (Automation)
Example: Weekly TODO scan
on:
schedule:
- cron: "0 9 * * 1"
Example prompt:
Review the codebase for TODO comments and summarize them
Note:
- Scheduled tasks must provide a prompt
- Requires write permissions (contents / pull-requests)
8. PR Automatic Review
Example:
on:
pull_request:
types: [opened, synchronize]
Default behavior:
- Analyze code quality
- Detect potential bugs
- Suggest improvements
9. Issue Automatic Classification
Can automatically handle new Issues, for example:
- Filter spam accounts
- Auto-reply with suggestions
- Supplement documentation
Note:
- The issues event must provide a prompt
10. Custom Prompts (Advanced Usage)
Can override default behavior:
prompt: | Review this pull request: - Check for bugs - Suggest improvements
Used for:
- Unifying code standards
- Customizing review criteria
- Automating team workflows
11. Security and Permissions
Recommended permission configuration:
permissions: id-token: write contents: write pull-requests: write issues: write
Notes:
- Principle of least privilege
- Only expose necessary capabilities