GitHub
在 GitHub Issue 和 Pull Request 中使用 OpenCtrlC。
OpenCtrlC 在你自己的 GitHub Actions 运行器中执行。在 Issue 或 Pull Request 评论中提及 /openctrlc 或 /oc,它就可以读取上下文、修改代码,并创建 Pull Request。
使用前准备
- GitHub 仓库已启用 Actions。
- 工作流拥有
contents、issues和pull-requests的写权限。 - 你准备好了要使用的模型及其提供商 API 密钥。
OpenCtrlC 不需要 GitHub App,也不需要 OpenCtrlC 托管账号。工作流直接使用 GitHub 内置的 GITHUB_TOKEN 和你自己的提供商密钥。
配置
在仓库中创建 .github/workflows/openctrlc.yml:
name: OpenCtrlC
on: issue_comment: types: [created] pull_request_review_comment: types: [created]
jobs: openctrlc: if: | contains(github.event.comment.body, '/oc') || contains(github.event.comment.body, '/openctrlc') runs-on: ubuntu-latest permissions: contents: write issues: write pull-requests: write steps: - name: 检出仓库 uses: actions/checkout@v6 with: fetch-depth: 1 persist-credentials: false
- name: 运行 OpenCtrlC uses: ponponon/openctrlc/github@latest env: GITHUB_TOKEN: ${{ github.token }} ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} with: model: anthropic/claude-sonnet-4-20250514 use_github_token: true根据你实际使用的模型替换 model 和提供商密钥。API 密钥请保存到仓库的 Settings → Secrets and variables → Actions,不要提交到代码仓库。
如果你在本地有 OpenCtrlC 源码,也可以运行下面的命令生成基础 workflow:
openctrlc github install这个命令只会写入 workflow 文件并打印所需的密钥名称,不会安装 GitHub App。
配置项
model:必填,格式为provider/model。agent:选择主代理;未配置时使用默认代理。prompt:覆盖评论内容,适用于定时、Issue 和 Pull Request 工作流。use_github_token:默认为true,直接使用运行器的 GitHub Token。share:默认为false。分享需要通过SHARE_URL配置外部服务,OpenCtrlC 不托管会话分享服务。oidc_base_url:仅适用于自建 Token 交换服务,并且需要显式设置use_github_token: false。
支持的事件
issue_comment:响应 Issue 或 Pull Request 中的/openctrlc、/oc评论。pull_request_review_comment:结合被评论代码和 diff 上下文进行审查。issues、pull_request、schedule、workflow_dispatch:需要显式提供prompt。
来自 fork 的 Pull Request 可能受到 GitHub 写权限限制。启用自动修改前,请检查仓库及 Actions 的 fork 权限设置。
安全建议
把提供商密钥放在 GitHub Actions Secrets 中,只授予工作流所需的最小权限,并审查第三方 workflow 的变更。不要对不可信的 Pull Request 代码直接授予写权限。
查看 GitHub Action 源码 和 GitHub Discussions 获取更多信息。