github.mdx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. pull_request_review_comment:
  31. types: [created]
  32. jobs:
  33. opencode:
  34. if: |
  35. contains(github.event.comment.body, '/oc') ||
  36. contains(github.event.comment.body, '/opencode')
  37. runs-on: ubuntu-latest
  38. permissions:
  39. id-token: write
  40. steps:
  41. - name: Checkout repository
  42. uses: actions/checkout@v4
  43. with:
  44. fetch-depth: 1
  45. - name: Run opencode
  46. uses: sst/opencode/github@latest
  47. env:
  48. ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
  49. with:
  50. model: anthropic/claude-sonnet-4-20250514
  51. # share: true
  52. # github_token: xxxx
  53. ```
  54. 3. **Store the API keys in secrets**
  55. In your organization or project **settings**, expand **Secrets and variables** on the left and select **Actions**. And add the required API keys.
  56. ---
  57. ## Configuration
  58. - `model`: The model to use with opencode. Takes the format of `provider/model`. This is **required**.
  59. - `share`: Whether to share the opencode session. Defaults to **true** for public repositories.
  60. - `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.
  61. 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:
  62. ```yaml
  63. permissions:
  64. id-token: write
  65. contents: write
  66. pull-requests: write
  67. issues: write
  68. ```
  69. 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.
  70. ---
  71. ## Examples
  72. Here are some examples of how you can use opencode in GitHub.
  73. - **Explain an issue**
  74. Add this comment in a GitHub issue.
  75. ```
  76. /opencode explain this issue
  77. ```
  78. opencode will read the entire thread, including all comments, and reply with a clear explanation.
  79. - **Fix an issue**
  80. In a GitHub issue, say:
  81. ```
  82. /opencode fix this
  83. ```
  84. And opencode will create a new branch, implement the changes, and open a PR with the changes.
  85. - **Review PRs and make changes**
  86. Leave the following comment on a GitHub PR.
  87. ```
  88. Delete the attachment from S3 when the note is removed /oc
  89. ```
  90. opencode will implement the requested change and commit it to the same PR.
  91. - **Review specific code lines**
  92. Leave a comment directly on code lines in the PR's "Files" tab. opencode automatically detects the file, line numbers, and diff context to provide precise responses.
  93. ```
  94. [Comment on specific lines in Files tab]
  95. /oc add error handling here
  96. ```
  97. When commenting on specific lines, opencode receives:
  98. - The exact file being reviewed
  99. - The specific lines of code
  100. - The surrounding diff context
  101. - Line number information
  102. This allows for more targeted requests without needing to specify file paths or line numbers manually.