在 GitHub issue 里描述 bug,评论 @claude fix this,几分钟后 PR 出来了——这是 Claude Code GitHub Actions 的日常场景。
能做什么?
在任何 PR 或 issue 里 @claude 一下:
@claude fix the null pointer exception in auth.ts@claude implement the feature described in this issue@claude add unit tests for the new endpoint@claude refactor this to use async/await@claude write a PR description for these changes
Claude 读取代码库上下文、遵循 CLAUDE.md 规范,创建 PR 或直接提交修改。
快速配置(2 步)
第一步:添加 API Key
GitHub 仓库 Settings → Secrets and variables → Actions,添加:
ANTHROPIC_API_KEY = your_api_key
第二步:创建 Workflow 文件
.github/workflows/claude.yml:
yaml
name: Claude Code
on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
jobs:
claude:
if: contains(github.event.comment.body, '@claude')
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
steps:
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}完成。现在在任何 issue/PR 评论里 @claude 即可触发。
3 个实用工作流
1. 自动实现 issue 功能
yaml
jobs:
claude:
if: |
github.event.comment.body == '@claude implement' &&
github.event.comment.author_association == 'OWNER'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
prompt: |
Read this issue and implement the feature.
Follow CLAUDE.md coding standards.
Create a PR with your changes.Issue 里评论 @claude implement,AI 自动实现 + 创建 PR。
2. 自动生成 PR 描述
yaml
on:
pull_request:
types: [opened]
jobs:
claude:
runs-on: ubuntu-latest
steps:
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
prompt: |
Analyze the PR changes and write a clear description:
- Summary of changes
- Why these changes
- Testing notes
Update the PR description.3. 使用 Opus 做复杂任务
yaml
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
model: claude-opus-4-6 # 默认 Sonnet,复杂任务换 Opus安全设置
只允许仓库成员触发(防外部滥用):
yaml
if: |
contains(github.event.comment.body, '@claude') &&
(github.event.comment.author_association == 'OWNER' ||
github.event.comment.author_association == 'COLLABORATOR')常见问题
@claude 没有响应
- 确认 workflow 文件已提交到默认分支
- 检查
ANTHROPIC_API_KEY是否正确 - 查看 GitHub Actions 日志找报错
Claude 的 commit 没有触发 CI
GitHub 限制防止循环触发。解决:
yaml
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
use_github_app_token: true来源:Claude Code GitHub Actions 文档 | 整理:ClaudeEagle