github.mdx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. ---
  2. title: GitHub
  3. description: Use opencode in GitHub issues and pull-requests.
  4. ---
  5. opencode integrates with your GitHub workflow. Mention `/opencode` or `/oc` in your comment, and opencode will execute tasks within your GitHub Actions runner.
  6. ---
  7. ## Features
  8. - **Triage issues**: Ask opencode to look into an issue and explain it to you.
  9. - **Fix and implement**: Ask opencode to fix an issue or implement a feature. And it will work in a new branch and submits a PR with all the changes.
  10. - **Secure**: opencode runs inside your GitHub's runners.
  11. ---
  12. ## Installation
  13. Run the following command in a project that is in a GitHub repo:
  14. ```bash
  15. opencode github install
  16. ```
  17. This will walk you through installing the GitHub app, creating the workflow, and setting up secrets.
  18. ---
  19. ### Manual Setup
  20. Or you can set it up manually.
  21. 1. **Install the GitHub app**
  22. Head over to [**github.com/apps/opencode-agent**](https://github.com/apps/opencode-agent). Make sure it's installed on the target repository.
  23. 2. **Add the workflow**
  24. Add the following workflow file to `.github/workflows/opencode.yml` in your repo. Make sure to set the appropriate `model` and required API keys in `env`.
  25. ```yml title=".github/workflows/opencode.yml" {24,26}
  26. name: opencode
  27. on:
  28. issue_comment:
  29. types: [created]
  30. jobs:
  31. opencode:
  32. if: |
  33. contains(github.event.comment.body, '/oc') ||
  34. contains(github.event.comment.body, '/opencode')
  35. runs-on: ubuntu-latest
  36. permissions:
  37. id-token: write
  38. steps:
  39. - name: Checkout repository
  40. uses: actions/checkout@v4
  41. with:
  42. fetch-depth: 1
  43. - name: Run opencode
  44. uses: sst/opencode/github@latest
  45. env:
  46. ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
  47. with:
  48. model: anthropic/claude-sonnet-4-20250514
  49. # share: true
  50. # github_token: xxxx
  51. ```
  52. 3. **Store the API keys in secrets**
  53. In your organization or project **settings**, expand **Secrets and variables** on the left and select **Actions**. And add the required API keys.
  54. ---
  55. ## Configuration
  56. - `model`: The model to use with opencode. Takes the format of `provider/model`. This is **required**.
  57. - `share`: Whether to share the opencode session. Defaults to **true** for public repositories.
  58. - `token`: Optional GitHub access token for performing operations such as creating comments, committing changes, and opening pull requests. By default, opencode uses the installation access token from the opencode GitHub App, so commits, comments, and pull requests appear as coming from the app.
  59. Alternatively, you can use the GitHub Action runner's [built-in `GITHUB_TOKEN`](https://docs.github.com/en/actions/tutorials/authenticate-with-github_token) without installing the opencode GitHub App. Just make sure to grant the required permissions in your workflow:
  60. ```yaml
  61. permissions:
  62. id-token: write
  63. contents: write
  64. pull-requests: write
  65. issues: write
  66. ```
  67. You can also use a [personal access tokens](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)(PAT) if preferred.
  68. ---
  69. ## Examples
  70. Here are some examples of how you can use opencode in GitHub.
  71. - **Explain an issue**
  72. Add this comment in a GitHub issue.
  73. ```
  74. /opencode explain this issue
  75. ```
  76. opencode will read the entire thread, including all comments, and reply with a clear explanation.
  77. - **Fix an issue**
  78. In a GitHub issue, say:
  79. ```
  80. /opencode fix this
  81. ```
  82. And opencode will create a new branch, implement the changes, and open a PR with the changes.
  83. - **Review PRs and make changes**
  84. Leave the following comment on a GitHub PR.
  85. ```
  86. Delete the attachment from S3 when the note is removed /oc
  87. ```
  88. opencode will implement the requested change and commit it to the same PR.