Skip to main content

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:

  1. A device code and verification URL are displayed in the terminal.
  2. Navigate to the URL in your browser.
  3. Enter the device code and authorize opencode to access your GitHub identity.
  4. 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:

PlanModel Access
Copilot FreeLimited models, rate-limited
Copilot ProStandard 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:

  1. Creates (or updates) a GitHub Actions workflow file at .github/workflows/opencode.yml.
  2. Configures the workflow with sensible defaults for your repository.
  3. 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:

  1. Fetches the PR branch from the remote repository.
  2. Checks out the branch locally.
  3. Runs opencode in review mode against the diff.
  4. 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

VariableDescriptionRequired
GITHUB_TOKENGitHub personal access token or installation tokenYes
OPENCODE_API_KEYopencode API key for model accessFor code review actions
GITHUB_SERVER_URLGitHub Enterprise Server URLFor 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 --refresh to force a model list refresh.

Security Considerations

  • GITHUB_TOKEN permissions 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_KEY rather than hardcoding.