|
| 1 | +# opencode GitHub Action |
| 2 | + |
| 3 | +A GitHub Action that integrates [opencode](https://opencode.ai) directly into your GitHub workflow. |
| 4 | + |
| 5 | +Start your comment with `hey opencode`, and opencode will take action via your GitHub Actions runner. |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +#### Triage and explain issues |
| 10 | + |
| 11 | +``` |
| 12 | +hey opencode, explain this issue |
| 13 | +``` |
| 14 | + |
| 15 | +#### Fix or implement issues - opencode will create a PR with the changes. |
| 16 | + |
| 17 | +``` |
| 18 | +hi opencode, fix this |
| 19 | +``` |
| 20 | + |
| 21 | +- Review PRs and make changes |
| 22 | + |
| 23 | +``` |
| 24 | +Delete the attachment from S3 when the note is removed @opencode-agent |
| 25 | +``` |
| 26 | + |
| 27 | +## Installation |
| 28 | + |
| 29 | +Run the following command in the terminal from your GitHub repo: |
| 30 | + |
| 31 | +``` |
| 32 | +opencode github install |
| 33 | +``` |
| 34 | + |
| 35 | +This will walk you through installing the GitHub app, configuring the workflow, and setting up secrets. |
| 36 | + |
| 37 | +### Manual Setup |
| 38 | + |
| 39 | +1. Install the GitHub app https://github.com/apps/opencode-agent. Make sure it is installed on the target repository. |
| 40 | +2. Add the following workflow file to `.github/workflows/opencode.yml` in your repo. Set the appropriate `model` and required API keys in `env`. |
| 41 | + |
| 42 | +```yml |
| 43 | +name: opencode |
| 44 | + |
| 45 | +on: |
| 46 | + issue_comment: |
| 47 | + types: [created] |
| 48 | + |
| 49 | +jobs: |
| 50 | + opencode: |
| 51 | + if: | |
| 52 | + startsWith(github.event.comment.body, 'opencode') || |
| 53 | + startsWith(github.event.comment.body, 'hi opencode') || |
| 54 | + startsWith(github.event.comment.body, 'hey opencode') || |
| 55 | + contains(github.event.comment.body, '@opencode-agent') |
| 56 | + runs-on: ubuntu-latest |
| 57 | + permissions: |
| 58 | + id-token: write |
| 59 | + steps: |
| 60 | + - name: Checkout repository |
| 61 | + uses: actions/checkout@v4 |
| 62 | + with: |
| 63 | + fetch-depth: 1 |
| 64 | + |
| 65 | + - name: Run opencode |
| 66 | + uses: sst/opencode/github@latest |
| 67 | + env: |
| 68 | + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} |
| 69 | + with: |
| 70 | + model: anthropic/claude-sonnet-4-20250514 |
| 71 | +``` |
| 72 | +
|
| 73 | +3. Store the API keys in secrets. In your organization or project **settings**, expand **Secrets and variables** on the left and select **Actions**. Add the required API keys. |
| 74 | +
|
| 75 | +## Support |
| 76 | +
|
| 77 | +This is an early release. If you encounter issues or have feedback, please create an issue at https://github.com/sst/opencode/issues. |
| 78 | +
|
| 79 | +## Development |
| 80 | +
|
| 81 | +To test locally: |
| 82 | +
|
| 83 | +1. Navigate to a test repo (e.g. `hello-world`): |
| 84 | + |
| 85 | +``` |
| 86 | +cd hello-world |
| 87 | +``` |
| 88 | +
|
| 89 | +2. Run: |
| 90 | +
|
| 91 | +``` |
| 92 | +MODEL=anthropic/claude-sonnet-4-20250514 \ |
| 93 | + ANTHROPIC_API_KEY=sk-ant-api03-1234567890 \ |
| 94 | + GITHUB_RUN_ID=dummy \ |
| 95 | + bun /path/to/opencode/packages/opencode/src/index.ts github run \ |
| 96 | + --token 'github_pat_1234567890' \ |
| 97 | + --event '{"eventName":"issue_comment",...}' |
| 98 | +``` |
| 99 | +
|
| 100 | +- `MODEL`: The model used by opencode. Same as the `MODEL` defined in the GitHub workflow. |
| 101 | +- `ANTHROPIC_API_KEY`: Your model provider API key. Same as the keys defined in the GitHub workflow. |
| 102 | +- `GITHUB_RUN_ID`: Dummy value to emulate GitHub action environment. |
| 103 | +- `/path/to/opencode`: Path to your cloned opencode repo. `bun /path/to/opencode/packages/opencode/src/index.ts` runs your local version of `opencode`. |
| 104 | +- `--token`: A GitHub persontal access token. This token is used to verify you have `admin` or `write` access to the test repo. Generate a token [here](https://github.com/settings/personal-access-tokens). |
| 105 | +- `--event`: Mock GitHub event payload (see templates below). |
| 106 | +
|
| 107 | +#### Issue comment event |
| 108 | +
|
| 109 | +``` |
| 110 | + --event '{"eventName":"issue_comment","repo":{"owner":"sst","repo":"hello-world"},"actor":"fwang","payload":{"issue":{"number":4},"comment":{"id":1,"body":"hey opencode, summarize thread"}}}' |
| 111 | +``` |
| 112 | +
|
| 113 | +Replace: |
| 114 | +
|
| 115 | +- `"owner":"sst"` with repo owner |
| 116 | +- `"repo":"hello-world"` with repo name |
| 117 | +- `"actor":"fwang"` with the GitHub username of commentor |
| 118 | +- `"number":4` with the GitHub issue id |
| 119 | +- `"body":"hey opencode, summarize thread"` with comment body |
| 120 | +
|
| 121 | +#### Issue comment with image attachment. |
| 122 | +
|
| 123 | +``` |
| 124 | + --event '{"eventName":"issue_comment","repo":{"owner":"sst","repo":"hello-world"},"actor":"fwang","payload":{"issue":{"number":4},"comment":{"id":1,"body":"hey opencode, what is in my image "}}}' |
| 125 | +``` |
| 126 | +
|
| 127 | +Replace the image URL `https://github.com/user-attachments/assets/xxxxxxxx` with a valid GitHub attachment (you can generate one by commenting with an image in any issue). |
| 128 | +
|
| 129 | +#### PR comment event |
| 130 | +
|
| 131 | +``` |
| 132 | + --event '{"eventName":"issue_comment","repo":{"owner":"sst","repo":"hello-world"},"actor":"fwang","payload":{"issue":{"number":4,"pull_request":{}},"comment":{"id":1,"body":"hey opencode, summarize thread"}}}' |
| 133 | +``` |
0 commit comments