平时做技术实践时,很多问题不是概念不会,而是细节没串起来。拿“Claude Code接入Github的实现方式步骤”来说,它看着像小点,放到项目里常会牵出环境、配置、兼容性和维护成本。下面按实际使用顺序,把思路、关键写法和容易踩坑的地方讲清楚,方便你直接对照操作。
目前AI编程工具可以分为3种类别:
- 1.本地IDE,代表产品有cursor、windsurf
- 2.在线网站,代表产品有lovable、bolt.new
- 3.命令行,代表产品有claude code、codex
实际处理时,claude code这种命令行工具可以很便于地集成到各种平台中,本篇文章就是介绍如何把claude code更快接入到github中,在开发流程中嵌入AI能力。
从实现思路看,claude code 接入github,我们不需重复造轮子,anthropic官方提供同时开源了名为claude code action((链接已移除))的工具,claude code action更新很频繁,前段时间刚发布了正式版本v1,借助它可以更快把claude code集成到github中。

结合项目来看,接下来按照设置api key、在github安装claude、让claude code参与开发3个步骤,分享一下如何把claude code集成到github。
设置api key
从实现思路看,claude对国内账号封控很严重,我们很难用到claude官方的api,好在国产模型进步很快,同时且都原生提供anthropic接口格式了,可以作为sonnet的平替接入claude code。我测试glm-4.6和kimi-k2都能够驱动claude code正常运行。可以在 (链接已移除) 新建glm的api key,在 (链接已移除) 新建kimi的api key,然后在你期望接入claude code的github仓库中设置api key。
理解这一步时,进入github仓库中,点击settings,随后选择secrets and variables中的actions,点击new repository secret按钮。

实际处理时,在新打开的页面中填写Name:ANTHROPIC_API_KEY,Secret:你刚刚新建的glm 或 kimi api key,最后点击add secret设置成功。

在github安装claude
落到代码里,接下来,需在GitHub中安装claude。在浏览器打开 (链接已移除),进入claude github app页面,点击install按钮安装claude应用,如果按钮位置显示的不是install而是configure,表示已经安装过该应用。

落到代码里,随后在接下来的安装确认页面中,可以设置安装到所有仓库或者指定仓库中,点击install & authorize按钮确认安装。

实际处理时,在安装成功后,如果你的github仓库还没有.github/workflows目录,你需先新建该目录,随后在该目录中添加claude.yml和claude-review.yml文件。

claude.yml文件内容如下所示
name: Claude Code
on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
issues:
types: [opened, assigned]
pull_request_review:
types: [submitted]
jobs:
claude:
if: |
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
(github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
id-token: write
actions: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Run Claude Code
id: claude
uses: anthropics/claude-code-action@v1
env:
# ANTHROPIC_BASE_URL: https://api.moonshot.cn/anthropic
ANTHROPIC_BASE_URL: https://open.bigmodel.cn/api/anthropic
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
claude_args: |
--allowedTools "mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh issue:*),Bash(gh search:*),Bash(gh label:*)"claude-review.yml文件内容如下所示
name: Claude Review
on:
pull_request:
types: [opened, synchronize]
# Optional: Only run on specific file changes
# paths:
# - "src/**/*.ts"
# - "src/**/*.tsx"
# - "src/**/*.js"
# - "src/**/*.jsx"
jobs:
claude-review:
# Optional: Filter by PR author
# if: |
# github.event.pull_request.user.login == 'external-contributor' ||
# github.event.pull_request.user.login == 'new-developer' ||
# github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR'
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run Claude Review
id: claude-review
uses: anthropics/claude-code-action@v1
env:
# ANTHROPIC_BASE_URL: https://api.moonshot.cn/anthropic
ANTHROPIC_BASE_URL: https://open.bigmodel.cn/api/anthropic
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
track_progress: true
prompt: |
REPO: ${{ github.repository }}
PR NUMBER: ${{ github.event.pull_request.number }}
Please review this pull request with a focus on:
- Code quality and best practices
- Potential bugs or issues
- Security implications
- Performance considerations
Provide detailed feedback using inline comments for specific issues.
Please respond in Simplified Chinese.
claude_args: |
--allowedTools "mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*)"从实现思路看,注意在上面两个文件中有 ANTHROPIC_BASE_URL 设置,默认设置的是glm网址,如果采用的kimi模型,需更改为 (链接已移除)。另外在设置文件最后有--allowedTools参数,claude code采用的是工具白名单,如果需某个特定的工具,需设置到该参数中。
理解这一步时,可能有人不熟悉.github/workflows目录,它是github中的保留目录,用来保存自动化工作流程的设置文件,可以设置当触发某些事件时执行哪些操作。比如可以在此目录中设置实现当提交新的代码时自动运行打包镜像、测试代码等功能。claude code action也是借助此机制实现的让claude回答用户提问、自动审阅代码等功能。
让claude code参与开发
从实现思路看,执行完上述步骤,claude code就已经接入到你的github仓库中了。你可以在github中issue中评论@claude,让ai回答你的问题甚至可以让ai直接提交代码完成你的需求。接下来是一些例子
落到代码里,我新建了python包管理方案讨论的issue,在评论中询问claude,让claude建议一个方案。

在这个场景下,在一个后端接口需求中直接让claude实现该需求,claude code能够提交代码到某个分支,点击Create PR链接可以手动新建代码合同时。

理解这一步时,除了可以在issue/pr中@claude以外,claude-review.yml工作流还兼容自动审阅代码。提交pr后,claude可以自动审阅提交的代码,查看代码中的问题,同时给出改进建议。

结合项目来看,总的来说,Claude这部分内容适合结合实际项目边做边理解。先抓住核心思路,再逐步补上细节和边界处理,最后效果会更稳定,也更容易复用。
