GitHub
opencode integrates deeply with GitHub through two primary channels: using a GitHub Copilot subscription as a model provider, and automating workflows via GitHub Actions.
GitHub Copilot as a Model Provider
opencode can use an active GitHub Copilot subscription to access a range of large language models for code generation, editing, and chat. This is one of the quickest ways to get started because many developers already have a Copilot license.
Connecting
Open the command palette and run:
/connect
From the provider list, select GitHub Copilot. opencode initiates a device-code authentication flow:
- A device code and verification URL are displayed in the terminal.
- Navigate to the URL in your browser.
- Enter the device code and authorize opencode to access your GitHub identity.
- Return to the terminal. opencode confirms the connection.
Selecting a Model
After connecting, run:
/models
Browse the available models and select one. The models available depend on your GitHub Copilot plan:
| Plan | Model Access |
|---|---|
| Copilot Free | Limited models, rate-limited |
| Copilot Pro | Standard model set |
| Copilot Pro+ | All available models including premium |
Some advanced models require a GitHub Copilot Pro+ subscription. If a model is unavailable, opencode displays an explanatory message.
Disconnecting
To remove the GitHub Copilot connection:
/connect
Select a different provider, or remove credentials from your GitHub account settings.
GitHub Actions Integration
opencode ships with a CLI subcommand for GitHub Actions that enables automated code review and task execution in CI/CD pipelines.
Installing the Workflow
In any GitHub repository, run:
opencode github install
This command:
- Creates (or updates) a GitHub Actions workflow file at
.github/workflows/opencode.yml. - Configures the workflow with sensible defaults for your repository.
- Optionally prompts you to define trigger events (pull requests, pushes, issue comments).
The generated workflow file looks like this:
name: opencode review
on:
pull_request:
types: [opened, synchronize]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: anaisco/opencode-github-action@v1
with:
github-token: \${{ secrets.GITHUB_TOKEN }}
opencode-api-key: \${{ secrets.OPENCODE_API_KEY }}
The GITHUB_TOKEN is automatically provided by GitHub Actions. For opencode model access, you must add an OPENCODE_API_KEY secret to your repository.
Running on a Pull Request
Trigger a review on any pull request:
opencode github run 42
This command:
- Fetches the PR branch from the remote repository.
- Checks out the branch locally.
- Runs opencode in review mode against the diff.
- Posts results back as a PR comment or check run.
PR Workflow (ad-hoc)
For quick ad-hoc reviews without a full CI setup:
opencode pr 123
This shorthand fetches the PR branch, runs opencode, and outputs the analysis to stdout. No installation or workflow file is required.
Environment Variables
| Variable | Description | Required |
|---|---|---|
GITHUB_TOKEN | GitHub personal access token or installation token | Yes |
OPENCODE_API_KEY | opencode API key for model access | For code review actions |
GITHUB_SERVER_URL | GitHub Enterprise Server URL | For self-hosted GitHub |
GitHub Enterprise Server
For GHES instances, set the server URL:
export GITHUB_SERVER_URL=https://github.example.com
opencode github run 42
Configuration
You can configure GitHub integration behaviour in opencode.json:
{
"github": {
"copilot": {
"models": ["gpt-4o", "claude-sonnet-4"]
},
"actions": {
"autoApprove": false,
"reviewSeverity": "critical"
}
}
}
Troubleshooting
Authentication Failures
If the device-code flow fails, try:
- Ensure you are signed into GitHub in your browser.
- Check that the device code has not expired (codes expire after 15 minutes).
- Verify your GitHub Copilot subscription is active at
github.com/settings/copilot.
Workflow Not Running
If a workflow does not trigger after opencode github install:
- Confirm the workflow file exists at
.github/workflows/opencode.yml. - Verify the repository's Actions tab shows the workflow.
- Check that any required secrets (
OPENCODE_API_KEY) are configured.
Model Unavailable
If a specific Copilot model is not listed:
- Upgrade to GitHub Copilot Pro+ if the model requires it.
- Contact GitHub Support if the model should be available on your plan.
- Run
/models --refreshto force a model list refresh.
Security Considerations
GITHUB_TOKENpermissions should follow the principle of least privilege.- For organization-wide workflows, use a GitHub App installation token rather than a personal token.
- Review workflow files before committing them to ensure no secrets are exposed.
- Use repository secrets for
OPENCODE_API_KEYrather than hardcoding.