---
title: Claude Code GitHub Actions | RunAPI
description: 使用 RunAPI secret、模型、permissions、触发事件和最小 workflow 配置 Claude Code GitHub
  Actions。
url: https://runapi.ai/zh-CN/docs/resources/tool-integrations/claude-code-github-actions.md
canonical: https://runapi.ai/zh-CN/docs/resources/tool-integrations/claude-code-github-actions
locale: zh-CN
---

> HTML version: https://runapi.ai/zh-CN/docs/resources/tool-integrations/claude-code-github-actions
> Site index for agents: https://runapi.ai/llms.txt

# Claude Code GitHub Actions

## 概览

官方 `anthropics/claude-code-action` 可在 GitHub Actions workflow 中运行 Claude
Code。本指南将 RunAPI key 保存为 GitHub Secret，在 Claude Code settings 中设置非敏感的
Base URL，选择模型，并响应经过授权的 `@claude` comment。

## 开始前准备

* 你需要 repository administrator 权限，以安装 Claude GitHub App、创建 Actions
  secrets 和添加 workflow。
* 在[身份验证指南](https://runapi.ai/zh-CN/docs/guides/authentication)中创建标准 RunAPI API key。
* 从[模型目录](https://runapi.ai/zh-CN/models)复制支持 Anthropic Messages 的 model identifier。
* 查看 [Claude Code GitHub Actions 官方设置说明][1]和组织的 workflow policy。



[1]: https://code.claude.com/docs/en/github-actions

## 安装

在目标 repository 中打开 Claude Code，运行 `/install-github-app` 并按提示安装 GitHub
App。当命令准备创建 Anthropic credential 时先停止保存：本指南改用 RunAPI repository 或
organization secret。

如需手动设置，请安装 [Claude GitHub App][1]，然后把下方 workflow 添加到
`.github/workflows/claude.yml`。



[1]: https://github.com/apps/claude

## 配置 RunAPI

创建名为 `RUNAPI_API_KEY` 的 repository 或 organization Actions secret。只通过
action 的 secret input 传入：

```yaml
anthropic_api_key: ${{ secrets.RUNAPI_API_KEY }}
```

不要把 key 写入 workflow 文件或 action 的 `settings` JSON。action 会单独处理
settings；其中只应放非敏感的 Base URL。

以下最小交互式 workflow 监听新建的 issue comment 和 pull request review comment：

```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
      id-token: write
      actions: read
    steps:
      - uses: actions/checkout@v6
        with:
          fetch-depth: 1
      - uses: anthropics/claude-code-action@v1
        with:
          anthropic_api_key: ${{ secrets.RUNAPI_API_KEY }}
          settings: |
            {
              "env": {
                "ANTHROPIC_BASE_URL": "https://runapi.ai"
              }
            }
          claude_args: "--model YOUR_RUNAPI_MODEL_ID"
```

### Secrets

GitHub 不会向 fork pull request 或 Dependabot event 触发的 workflow 提供普通
Actions secrets。如果 run 中没有 credential，请先确认 event 来源，不要直接轮换 RunAPI
key。Repository 和 organization scope 请查看 GitHub 的 [Actions secrets
指南][1]。



[1]: https://docs.github.com/en/actions/how-tos/write-workflows/choose-what-workflows-do/use-secrets

### Permissions

* `contents: write` 允许 action 提交代码变更。
* `pull-requests: write` 和 `issues: write` 允许读取并回复触发对话。
* `id-token: write` 支持 action 默认的 GitHub App authentication。
* `actions: read` 允许读取 workflow 结果。

请使用这些明确 permissions，不要使用 `write-all`。移除 workflow 不需要的权限。

### 触发事件

`issue_comment` 覆盖 issue 和 pull request conversation 中的
comment；`pull_request_review_comment` 覆盖 diff line
comment。`issue_comment` 能触发前，workflow 文件必须已存在于 default branch。action
还会检查触发者身份；完整规则以[官方安全行为][1]为 canonical reference。



[1]: https://code.claude.com/docs/en/github-actions#who-can-trigger-runs

## 选择模型

将 `claude_args` 中的 `YOUR_RUNAPI_MODEL_ID` 替换为[模型目录](https://runapi.ai/zh-CN/models)中的准确
identifier。将模型选择放在 `settings.env` 外，可让 workflow 选用的模型直接显示在 action 配置中。

## 验证

1.  确认 `RUNAPI_API_KEY` secret 存在，但不要打印其值。
2.  将 workflow 合入 default branch，并确认 Actions 已启用。
3.  使用有 repository write access 的账号，在 issue comment 中发送 `@claude
    用一句话描述这个仓库`。
4.  打开 workflow run，确认 action 成功，并检查 Claude 是否在同一 issue 中回复。

## 排查问题

* **workflow 没有启动：** 确认文件位于 default branch、comment event 匹配且 Actions
  已启用。
* **job 被跳过：** 确认 comment 包含 `@claude`，且触发账号拥有所需 repository access。
* **身份验证失败：** 确认 workflow 引用
  `secrets.RUNAPI_API_KEY`；必要时通过[身份验证指南](https://runapi.ai/zh-CN/docs/guides/authentication)轮换密钥。
* **fork pull request 无法使用 key：** GitHub 会有意阻止 fork-triggered run 读取普通
  secrets。不要把 secret 改成 literal。
* **模型不可用：** 从[模型目录](https://runapi.ai/zh-CN/models)复制准确 identifier。
* **Claude commit 没有启动另一个 workflow：** 查看官方 action 的 [GitHub token
  排障说明][1]。



[1]: https://code.claude.com/docs/en/github-actions#ci-not-running-on-claudes-commits

## 下一步

协议行为请查看 [LLM API 快速开始](https://runapi.ai/zh-CN/docs/guides/llm-api/quickstart)，请求字段请查看
[Anthropic Messages API 参考](https://runapi.ai/zh-CN/docs/api/anthropic/messages)。更多触发方式和
action inputs 请查看[官方 examples][1]和[配置 reference][2]。



[1]: https://github.com/anthropics/claude-code-action/tree/main/examples
[2]: https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md

---

## More from RunAPI

- [Home](https://runapi.ai/.md)
- [模型](https://runapi.ai/zh-CN/models.md)
- [AI 视频 API 对比](https://runapi.ai/zh-CN/ai-video-api-comparison.md)
- [OpenClaw 集成](https://runapi.ai/zh-CN/openclaw.md)
- [OpenClaw 最佳 API](https://runapi.ai/zh-CN/best-api-for-openclaw.md)
- [OpenClaw 图片生成](https://runapi.ai/zh-CN/openclaw-image-generation.md)
- [Hermes 智能体集成](https://runapi.ai/zh-CN/hermes-agent.md)
- [定价](https://runapi.ai/zh-CN/pricing.md)
- [Claude API 定价](https://runapi.ai/zh-CN/claude-api-pricing.md)
- [ChatGPT API 定价](https://runapi.ai/zh-CN/chatgpt-api-pricing.md)
- [OpenAI API 定价](https://runapi.ai/zh-CN/openai-api-pricing.md)
- [Gemini API 定价](https://runapi.ai/zh-CN/gemini-api-pricing.md)
- [Claude Code 定价](https://runapi.ai/zh-CN/claude-code-pricing.md)
- [Claude Code API](https://runapi.ai/zh-CN/claude-code-api.md)
- [Claude Code 对比 Cursor](https://runapi.ai/zh-CN/claude-code-vs-cursor.md)
- [Claude Max 对比 API](https://runapi.ai/zh-CN/claude-max-vs-api.md)
- [Requesty 替代方案](https://runapi.ai/zh-CN/requesty-alternative.md)
- [文档](https://runapi.ai/zh-CN/docs/guides)
- [SDK](https://runapi.ai/zh-CN/sdk.md)
- [Skills](https://runapi.ai/zh-CN/skills.md)
- [MCP Server](https://runapi.ai/zh-CN/mcp.md)
- [CLI](https://runapi.ai/zh-CN/cli.md)
- [反馈](https://runapi.ai/)
- [联系](mailto:support@runapi.ai)
- [服务条款](https://runapi.ai/zh-CN/terms.md)
- [隐私政策](https://runapi.ai/zh-CN/privacy.md)
- [Site index for agents](https://runapi.ai/llms.txt)

Contact: contact@runapi.ai

## Structured data

```json
[
  {
    "@context": "https://schema.org",
    "inLanguage": "zh-CN",
    "@type": "WebSite",
    "name": "RunAPI",
    "url": "https://runapi.ai/zh-CN",
    "potentialAction": {
      "@type": "SearchAction",
      "target": {
        "@type": "EntryPoint",
        "urlTemplate": "https://runapi.ai/zh-CN/models?q={search_term_string}"
      },
      "query-input": "required name=search_term_string"
    }
  },
  {
    "@context": "https://schema.org",
    "inLanguage": "zh-CN",
    "@type": "Organization",
    "name": "RunAPI",
    "url": "https://runapi.ai/zh-CN",
    "logo": {
      "@type": "ImageObject",
      "url": "https://runapi.ai/zh-CNicon.svg"
    },
    "sameAs": [
      "https://github.com/runapi-ai"
    ]
  },
  {
    "@context": "https://schema.org",
    "inLanguage": "zh-CN",
    "@type": "TechArticle",
    "headline": "Claude Code GitHub Actions",
    "description": "使用 RunAPI secret、模型、permissions、触发事件和最小 workflow 配置 Claude Code GitHub Actions。",
    "url": "https://runapi.ai/zh-CN/docs/resources/tool-integrations/claude-code-github-actions",
    "mainEntityOfPage": "https://runapi.ai/zh-CN/docs/resources/tool-integrations/claude-code-github-actions"
  }
]
```
