> ## Documentation Index
> Fetch the complete documentation index at: https://code.claude.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Claude Code 与 GitHub Enterprise Server

> 将 Claude Code 连接到自托管的 GitHub Enterprise Server 实例，用于网络会话、代码审查和插件市场。

<Note>
  GitHub Enterprise Server 支持适用于 Team 和 Enterprise 计划。
</Note>

GitHub Enterprise Server (GHES) 支持让您的组织使用 Claude Code 处理托管在自管理 GitHub 实例上的存储库，而不是 github.com。一旦所有者连接您的 GHES 实例，开发人员可以运行网络会话、获得自动化代码审查，并从内部市场安装插件，无需任何按存储库的配置。

对于 github.com 上的存储库，请参阅 [网络上的 Claude Code](/zh-CN/claude-code-on-the-web) 和 [代码审查](/zh-CN/code-review)。要在您自己的 CI 基础设施中运行 Claude，请参阅 [GitHub Actions](/zh-CN/github-actions)。

<h2 id="what-works-with-github-enterprise-server">
  GitHub Enterprise Server 支持的功能
</h2>

下表显示了哪些 Claude Code 功能支持 GHES 以及与 github.com 行为的任何差异。

| 功能                | GHES 支持 | 备注                                                                                       |
| :---------------- | :------ | :--------------------------------------------------------------------------------------- |
| 网络上的 Claude Code  | ✅ 支持    | 所有者连接 GHES 实例一次；开发人员像往常一样使用 `claude --remote` 或 [claude.ai/code](https://claude.ai/code) |
| 代码审查              | ✅ 支持    | 与 github.com 相同的自动化 PR 审查                                                                |
| Claude Security   | ✅ 支持    | 在 [claude.ai/security](https://claude.ai/security) 为 Enterprise 计划提供公开测试版                |
| Teleport 会话       | ✅ 支持    | 使用 `--teleport` 在网络和终端之间移动会话                                                             |
| 插件市场              | ✅ 支持    | 使用完整的 git URL 而不是 `owner/repo` 简写                                                        |
| 贡献指标              | ✅ 支持    | 通过 webhook 传递到 [分析仪表板](/zh-CN/analytics)                                                 |
| GitHub Actions    | ✅ 支持    | 需要手动工作流设置；`/install-github-app` 仅适用于 github.com                                          |
| GitHub MCP server | ❌ 不支持   | GitHub MCP server 不适用于 GHES 实例                                                           |

<h2 id="admin-setup">
  管理员设置
</h2>

一个所有者将您的 GHES 实例连接到 Claude Code 一次。之后，您组织中的开发人员可以使用 GHES 存储库，无需任何额外配置。您需要在 Claude 组织中具有所有者或主要所有者角色，以及在 GHES 实例上创建 GitHub App 的权限。

引导式设置生成 GitHub App 清单，并将您重定向到 GHES 实例以一键创建应用。如果您的环境阻止重定向流，可以使用 [替代手动设置](#manual-setup)。

<Steps>
  <Step title="打开 Claude Code 管理员设置">
    转到 [claude.ai/admin-settings/claude-code](https://claude.ai/admin-settings/claude-code) 并找到 GitHub Enterprise Server 部分。
  </Step>

  <Step title="启动引导式设置">
    点击 **连接**。输入连接的显示名称和您的 GHES 主机名，例如 `github.example.com`。如果您的 GHES 实例使用自签名或私有证书颁发机构，请在可选字段中粘贴 CA 证书。
  </Step>

  <Step title="创建 GitHub App">
    点击 **继续到 GitHub Enterprise**。您的浏览器重定向到您的 GHES 实例，并显示预填充的应用清单。审查配置并点击 **创建 GitHub App**。GHES 将您重定向回 Claude，应用凭证自动存储。
  </Step>

  <Step title="在您的存储库上安装应用">
    从您的 GHES 实例上的 GitHub App 页面，在您希望 Claude 访问的存储库或组织上安装应用。您可以从一个子集开始，稍后添加更多。
  </Step>

  <Step title="启用功能">
    返回 [claude.ai/admin-settings/claude-code](https://claude.ai/admin-settings/claude-code) 并为您的 GHES 存储库启用 [代码审查](/zh-CN/code-review#set-up-code-review)、Claude Security 和 [贡献指标](/zh-CN/analytics#enable-contribution-metrics)，使用与 github.com 相同的配置。
  </Step>
</Steps>

<h3 id="github-app-permissions">
  GitHub App 权限
</h3>

清单使用 Claude 在网络会话、代码审查、Claude Security 和贡献指标中需要的权限和 webhook 事件配置 GitHub App：

| 权限               | 访问 | 用途              |
| :--------------- | :- | :-------------- |
| Contents         | 读写 | 克隆存储库和推送分支      |
| Pull requests    | 读写 | 创建 PR 和发布审查评论   |
| Issues           | 读写 | 响应问题提及          |
| Checks           | 读写 | 发布代码审查检查运行      |
| Actions          | 读  | 读取 CI 状态以进行自动修复 |
| Repository hooks | 读写 | 接收贡献指标的 webhook |
| Metadata         | 读  | GitHub 对所有应用的要求 |

应用订阅 `pull_request`、`issue_comment`、`pull_request_review_comment`、`pull_request_review` 和 `check_run` 事件。

<h3 id="manual-setup">
  手动设置
</h3>

如果引导式重定向流被您的网络配置阻止，请点击 **手动添加** 而不是连接。在您的 GHES 实例上创建 GitHub App，具有 [上述权限和事件](#github-app-permissions)，然后在表单中输入应用凭证：主机名、OAuth 客户端 ID 和密钥、GitHub App ID、客户端 ID、客户端密钥、webhook 密钥和私钥。

<h3 id="network-requirements">
  网络要求
</h3>

您的 GHES 实例必须可从 Anthropic 基础设施访问，以便 Claude 可以克隆存储库和发布审查评论。如果您的 GHES 实例在防火墙后面，请将 [Anthropic API IP 地址](https://platform.claude.com/docs/en/api/ip-addresses) 加入白名单。

<h2 id="developer-workflow">
  开发人员工作流
</h2>

一旦您的管理员连接了 GHES 实例，就不需要开发人员端的配置。Claude Code 从您工作目录中的 git 远程自动检测您的 GHES 主机名。

像往常一样从您的 GHES 实例克隆存储库：

```bash theme={null}
git clone git@github.example.com:platform/api-service.git
cd api-service
```

然后启动网络会话。Claude 从您的 git 远程检测 GHES 主机，并通过您组织的配置实例路由会话：

```bash theme={null}
claude --remote "Add retry logic to the payment webhook handler"
```

会话在 Anthropic 基础设施上运行，从 GHES 克隆您的存储库，并将更改推送回分支。使用 `/tasks` 或在 [claude.ai/code](https://claude.ai/code) 监控进度。有关完整的远程会话工作流（包括差异审查、自动修复和例程），请参阅 [网络上的 Claude Code](/zh-CN/claude-code-on-the-web)。

<h3 id="teleport-sessions-to-your-terminal">
  将会话 Teleport 到您的终端
</h3>

使用 `claude --teleport` 将网络会话拉入您的本地终端。Teleport 在获取分支和加载会话历史之前验证您在同一 GHES 存储库的检出中。有关详细信息，请参阅 [teleport 要求](/zh-CN/claude-code-on-the-web#teleport-requirements)。

<h2 id="plugin-marketplaces-on-ghes">
  GHES 上的插件市场
</h2>

在您的 GHES 实例上托管插件市场，以在您的组织中分发内部工具。市场结构与 github.com 托管的市场相同；唯一的区别是您如何引用它们。

<h3 id="add-a-ghes-marketplace">
  添加 GHES 市场
</h3>

`owner/repo` 简写始终解析为 github.com。对于 GHES 托管的市场，使用完整的 git URL：

```bash theme={null}
/plugin marketplace add git@github.example.com:platform/claude-plugins.git
```

HTTPS URL 也可以工作：

```bash theme={null}
/plugin marketplace add https://github.example.com/platform/claude-plugins.git
```

有关构建市场的完整指南，请参阅 [创建和分发插件市场](/zh-CN/plugin-marketplaces)。

<h3 id="allowlist-ghes-marketplaces-in-managed-settings">
  在托管设置中将 GHES 市场加入白名单
</h3>

如果您的组织使用 [托管设置](/zh-CN/settings) 来限制开发人员可以添加哪些市场，请使用 `hostPattern` 源类型来允许来自您的 GHES 实例的所有市场，而无需枚举每个存储库：

```json theme={null}
{
  "strictKnownMarketplaces": [
    {
      "source": "hostPattern",
      "hostPattern": "^github\\.example\\.com$"
    }
  ]
}
```

您也可以为开发人员预注册市场，以便它们无需手动设置即可显示。此示例使内部工具市场在整个组织中可用：

```json theme={null}
{
  "extraKnownMarketplaces": {
    "internal-tools": {
      "source": {
        "source": "git",
        "url": "git@github.example.com:platform/claude-plugins.git"
      }
    }
  }
}
```

有关完整的架构，请参阅 [strictKnownMarketplaces](/zh-CN/settings#strictknownmarketplaces) 和 [extraKnownMarketplaces](/zh-CN/settings#extraknownmarketplaces) 设置参考。

<h2 id="limitations">
  限制
</h2>

一些功能在 GHES 上的行为与 github.com 上不同。[功能表](#what-works-with-github-enterprise-server) 总结了支持；本部分涵盖了解决方法。

* **`/install-github-app` 命令**：改为在 claude.ai 上遵循 [管理员设置](#admin-setup) 流程。如果您还想在 GHES 上使用 GitHub Actions 工作流，请手动调整 [示例工作流](https://github.com/anthropics/claude-code-action/blob/main/examples/claude.yml)。
* **GitHub MCP server**：改为使用为您的 GHES 主机配置的 `gh` CLI。运行 `gh auth login --hostname github.example.com` 进行身份验证，然后 Claude 可以在会话中使用 `gh` 命令。

<h2 id="troubleshooting">
  故障排除
</h2>

<h3 id="web-session-fails-to-clone-repository">
  网络会话无法克隆存储库
</h3>

如果 `claude --remote` 因克隆错误而失败，请验证 Owner 已完成您的 GHES 实例的设置，并且 GitHub App 已安装在您正在处理的存储库上。与连接该实例的 Owner 确认在 Claude 设置中注册的主机名与您的 git 远程中的主机名匹配。

<h3 id="marketplace-add-fails-with-a-policy-error">
  市场添加因策略错误而失败
</h3>

如果 `/plugin marketplace add` 因您的 GHES URL 而被阻止，您的组织已限制市场源。要求您的管理员在 [托管设置](#allowlist-ghes-marketplaces-in-managed-settings) 中为您的 GHES 主机名添加 `hostPattern` 条目。

<h3 id="ghes-instance-not-reachable">
  GHES 实例无法访问
</h3>

如果审查或网络会话超时，您的 GHES 实例可能无法从 Anthropic 基础设施访问。确认您的防火墙允许来自 [Anthropic API IP 地址](https://platform.claude.com/docs/zh-CN/api/ip-addresses) 的入站连接。

<h2 id="related-resources">
  相关资源
</h2>

这些页面更深入地涵盖了本指南中引用的功能：

* [网络上的 Claude Code](/zh-CN/claude-code-on-the-web)：在云基础设施上运行 Claude Code 会话
* [代码审查](/zh-CN/code-review)：自动化 PR 审查
* [插件市场](/zh-CN/plugin-marketplaces)：构建和分发插件目录
* [分析](/zh-CN/analytics)：跟踪使用情况和贡献指标
* [托管设置](/zh-CN/settings)：组织范围的策略配置
* [网络配置](/zh-CN/network-config)：防火墙和 IP 白名单要求
