github.mdx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. - `prompt`: Optional custom prompt to override the default behavior. Use this to customize how opencode processes requests.
  61. - `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.
  62. 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:
  63. ```yaml
  64. permissions:
  65. id-token: write
  66. contents: write
  67. pull-requests: write
  68. issues: write
  69. ```
  70. 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.
  71. ---
  72. ## Custom prompts
  73. Override the default prompt to customize opencode's behavior for your workflow.
  74. ```yaml title=".github/workflows/opencode.yml"
  75. - uses: sst/opencode/github@latest
  76. with:
  77. model: anthropic/claude-sonnet-4-5
  78. prompt: |
  79. Review this pull request:
  80. - Check for code quality issues
  81. - Look for potential bugs
  82. - Suggest improvements
  83. ```
  84. This is useful for enforcing specific review criteria, coding standards, or focus areas relevant to your project.
  85. ---
  86. ## Examples
  87. Here are some examples of how you can use opencode in GitHub.
  88. - **Explain an issue**
  89. Add this comment in a GitHub issue.
  90. ```
  91. /opencode explain this issue
  92. ```
  93. opencode will read the entire thread, including all comments, and reply with a clear explanation.
  94. - **Fix an issue**
  95. In a GitHub issue, say:
  96. ```
  97. /opencode fix this
  98. ```
  99. And opencode will create a new branch, implement the changes, and open a PR with the changes.
  100. - **Review PRs and make changes**
  101. Leave the following comment on a GitHub PR.
  102. ```
  103. Delete the attachment from S3 when the note is removed /oc
  104. ```
  105. opencode will implement the requested change and commit it to the same PR.
  106. - **Review specific code lines**
  107. 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.
  108. ```
  109. [Comment on specific lines in Files tab]
  110. /oc add error handling here
  111. ```
  112. When commenting on specific lines, opencode receives:
  113. - The exact file being reviewed
  114. - The specific lines of code
  115. - The surrounding diff context
  116. - Line number information
  117. This allows for more targeted requests without needing to specify file paths or line numbers manually.