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
- **Issue analysis:** automatically understand the problem and give an explanation
- **Auto-fix:** create a branch and submit a PR
- **Code review:** analyze the PR and suggest improvements
- **Automated execution:** runs on GitHub Actions
Characteristics:
- Runs on your own GitHub Runner
- Secure and controllable, no reliance on external servers to execute code
II. Quick install (recommended)
Run in the root of your GitHub project:
opencode github install
This command automatically:
- Install the GitHub App
- Create a GitHub Actions workflow
- Guide you through configuring the API Key
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:
- Go to Settings → Secrets → Actions
- Add an API Key (e.g. ANTHROPIC_API_KEY)
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:
- By default, the OpenCode GitHub App Token is used
- You can also use GITHUB_TOKEN or PAT
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:
- Create a branch
- Modify the code
- Submit a Pull Request
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:
- File path
- line number
- Context diff
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:
- Scheduled tasks must provide a prompt
- Requires write permission (contents / pull-requests)
VIII. PR auto-review
Example:
on:
pull_request:
types: [opened, synchronize]
Default behavior:
- Analyze code quality
- Detect potential bugs
- Suggest improvements
IX. Issue auto-classification
Can automatically handle new Issues, for example:
- Filter spam accounts
- Auto-reply with suggestions
- Supplement documentation
Note:
- issues events must provide a prompt
X. Custom prompts (advanced usage)
Can override the default behavior:
prompt: |
Review this pull request:
- Check for bugs
- Suggest improvements
Used for:
- Unify code standards
- Customize review standards
- Automate team workflows
XI. Security and permissions
Recommended permission configuration:
permissions:
id-token: write
contents: write
pull-requests: write
issues: write
Explanation:
- Principle of least privilege
- Only enable necessary capabilities