github-integration
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGitHub Integration
GitHub集成
Enable CLI access in Claude Code cloud and GitHub Copilot coding agent
environments so agents can create PRs, manage issues, and interact with
GitHub APIs.
gh在Claude Code云和GitHub Copilot编码代理环境中启用 CLI访问权限,让代理能够创建PR、管理议题并与GitHub API交互。
ghWhen to Use This Skill
何时使用此技能
Activate when:
- User wants cloud AI agents to use (PRs, issues, releases, API calls)
gh - User needs to install in Claude Code cloud sessions
gh - User wants to add for GitHub Copilot agents
copilot-setup-steps.yml - commands fail with auth or "not found" errors in a cloud session
gh - User wants to enable GitHub integration for any cloud-based AI coding agent
在以下场景激活:
- 用户希望云端AI代理使用(处理PR、议题、版本发布、API调用)
gh - 用户需要在Claude Code云会话中安装
gh - 用户希望为GitHub Copilot代理添加文件
copilot-setup-steps.yml - 云会话中命令因认证或“未找到”错误失败
gh - 用户希望为任何云端AI编码代理启用GitHub集成
Decision Tree
决策树
Which cloud environment?
Claude Code cloud (claude.ai/code)?
→ gh is NOT pre-installed in the default image
→ Install via setup script: apt update && apt install -y gh
→ Set GH_TOKEN as environment variable in environment settings
→ For repo-portable setup, use SessionStart hook instead
→ Use -R owner/repo flag with gh due to sandbox proxy
GitHub Copilot coding agent?
→ Add .github/copilot-setup-steps.yml to the repo
→ gh IS pre-installed; just configure GH_TOKEN
→ Commit and push — agent sessions pick it up automatically
gh commands failing?
→ "command not found" → gh not installed; add to setup script
→ HTTP 401 → GH_TOKEN not set; add to environment variables
→ HTTP 403 → Token lacks required scope; check permissions
→ "could not determine repo" → Use -R owner/repo flag
→ See references/cloud-auth.md for more
Need gh in local dev too?
→ Run: gh auth login (interactive, browser-based)
→ Or set GH_TOKEN env var for headless/CI useWhich cloud environment?
Claude Code cloud (claude.ai/code)?
→ gh is NOT pre-installed in the default image
→ Install via setup script: apt update && apt install -y gh
→ Set GH_TOKEN as environment variable in environment settings
→ For repo-portable setup, use SessionStart hook instead
→ Use -R owner/repo flag with gh due to sandbox proxy
GitHub Copilot coding agent?
→ Add .github/copilot-setup-steps.yml to the repo
→ gh IS pre-installed; just configure GH_TOKEN
→ Commit and push — agent sessions pick it up automatically
gh commands failing?
→ "command not found" → gh not installed; add to setup script
→ HTTP 401 → GH_TOKEN not set; add to environment variables
→ HTTP 403 → Token lacks required scope; check permissions
→ "could not determine repo" → Use -R owner/repo flag
→ See references/cloud-auth.md for more
Need gh in local dev too?
→ Run: gh auth login (interactive, browser-based)
→ Or set GH_TOKEN env var for headless/CI useTwo Environments, Two Approaches
两种环境,两种方案
Claude Code Cloud (claude.ai/code)
Claude Code云(claude.ai/code)
Claude Code cloud runs sessions in Anthropic-managed VMs. The CLI
is not pre-installed. You need two things:
gh- Setup script — installs when the session starts
gh - env var — authenticates
GH_TOKENwith your GitHub PATgh
Claude Code云在Anthropic管理的VM中运行会话。 CLI未预装,你需要完成两项配置:
gh- 初始化脚本 —— 会话启动时安装
gh - 环境变量 —— 使用你的GitHub PAT认证
GH_TOKENgh
Quick Start: Setup Script
快速开始:初始化脚本
In the Claude Code web UI: Environment Settings → Setup script:
bash
#!/bin/bash
apt update && apt install -y ghThen add as an environment variable with your GitHub Personal
Access Token (needs scope).
GH_TOKENrepo在Claude Code网页UI中:环境设置 → 初始化脚本:
bash
#!/bin/bash
apt update && apt install -y gh然后添加作为环境变量,值为你的GitHub个人访问令牌(需要权限范围)。
GH_TOKENrepoAlternative: SessionStart Hook (repo-portable)
替代方案:SessionStart钩子(仓库可移植)
Add to in your repo:
.claude/settings.jsonjson
{
"hooks": {
"SessionStart": [
{
"hooks": [
{
"type": "command",
"command": "if [ \"$CLAUDE_CODE_REMOTE\" = \"true\" ]; then apt update && apt install -y gh; fi",
"timeout": 120
}
]
}
]
}
}The check ensures it only runs in cloud sessions.
CLAUDE_CODE_REMOTE在仓库的中添加:
.claude/settings.jsonjson
{
"hooks": {
"SessionStart": [
{
"hooks": [
{
"type": "command",
"command": "if [ \"$CLAUDE_CODE_REMOTE\" = \"true\" ]; then apt update && apt install -y gh; fi",
"timeout": 120
}
]
}
]
}
}CLAUDE_CODE_REMOTEImportant: The -R
Flag
-R重要提示:-R
参数
-RDue to the sandbox proxy, may not auto-detect the repo. Use the
flag:
gh-R owner/repobash
gh pr create -R codervisor/myrepo --title "..." --body "..."
gh issue list -R codervisor/myrepo由于沙箱代理,可能无法自动检测仓库。请使用参数:
gh-R owner/repobash
gh pr create -R codervisor/myrepo --title "..." --body "..."
gh issue list -R codervisor/myrepoGitHub Copilot Coding Agent
GitHub Copilot编码代理
Copilot coding agents use . The CLI
is pre-installed; you just need to authenticate it.
.github/copilot-setup-steps.ymlghAdd this file at :
.github/copilot-setup-steps.ymlyaml
name: "Copilot Setup Steps"
on: repository_dispatch
jobs:
copilot-setup-steps:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Authenticate gh CLI
run: gh auth status
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}See for a full template with
dependency installation.
templates/copilot-setup-steps.ymlCopilot编码代理使用。 CLI已预装,你只需完成认证配置。
.github/copilot-setup-steps.ymlgh在路径下添加以下文件:
.github/copilot-setup-steps.ymlyaml
name: "Copilot Setup Steps"
on: repository_dispatch
jobs:
copilot-setup-steps:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Authenticate gh CLI
run: gh auth status
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}完整模板包含依赖安装,请查看。
templates/copilot-setup-steps.ymlSetup Scripts vs SessionStart Hooks vs copilot-setup-steps
初始化脚本 vs SessionStart钩子 vs copilot-setup-steps
| Setup scripts | SessionStart hooks | copilot-setup-steps.yml | |
|---|---|---|---|
| Platform | Claude Code cloud only | Claude Code (local + cloud) | GitHub Copilot agents only |
| Configured in | Environment settings UI | | |
| Runs | Before Claude launches | After Claude launches | Before Copilot agent launches |
| Runs on resume | No (new sessions only) | Yes (every session) | Yes |
| Network | Needs registry access | Needs registry access | Full GitHub Actions network |
| 初始化脚本 | SessionStart钩子 | copilot-setup-steps.yml | |
|---|---|---|---|
| 平台 | 仅Claude Code云 | Claude Code(本地+云端) | 仅GitHub Copilot代理 |
| 配置位置 | 环境设置UI | 仓库中的 | |
| 运行时机 | Claude启动前 | Claude启动后 | Copilot代理启动前 |
| 恢复会话时运行 | 否(仅新会话) | 是(每次会话) | 是 |
| 网络 | 需要访问镜像源 | 需要访问镜像源 | 完整GitHub Actions网络权限 |
Common gh Commands for Agents
代理常用gh命令
bash
undefinedbash
undefinedPRs (use -R in Claude Code cloud)
PRs(Claude Code云中需使用-R参数)
gh pr create -R owner/repo --title "..." --body "..."
gh pr list -R owner/repo
gh pr view -R owner/repo
gh pr merge -R owner/repo --squash --delete-branch
gh pr create -R owner/repo --title "..." --body "..."
gh pr list -R owner/repo
gh pr view -R owner/repo
gh pr merge -R owner/repo --squash --delete-branch
Issues
议题
gh issue list -R owner/repo
gh issue view 42 -R owner/repo
gh issue create -R owner/repo --title "..." --body "..."
gh issue list -R owner/repo
gh issue view 42 -R owner/repo
gh issue create -R owner/repo --title "..." --body "..."
API (for anything not covered by subcommands)
API(子命令未覆盖的操作)
gh api repos/owner/repo/actions/runs
undefinedgh api repos/owner/repo/actions/runs
undefinedPitfalls
常见陷阱
| Symptom | Cause | Fix |
|---|---|---|
| Not installed (Claude Code cloud) | Add |
| | Add to environment variables in settings UI |
| Token lacks | Regenerate PAT with |
| Sandbox proxy hides git remote | Use |
| No upstream branch | Push with |
| Setup script fails | No network access | Set network to "Limited" (default) or "Full" |
| 症状 | 原因 | 修复方案 |
|---|---|---|
| 未安装(Claude Code云) | 在初始化脚本中添加 |
| | 在设置UI的环境变量中添加 |
推送时出现 | 令牌缺少 | 重新生成带有 |
| 沙箱代理隐藏了git远程仓库 | 使用 |
| 无上游分支 | 先执行 |
| 初始化脚本执行失败 | 无网络访问权限 | 将网络设置为“受限”(默认)或“完全” |
References
参考资料
- — Token auth, scopes, proxy details, troubleshooting
references/cloud-auth.md - — Full guide to customizing the Copilot setup workflow
references/copilot-setup-steps.md
- —— 令牌认证、权限范围、代理细节、故障排查
references/cloud-auth.md - —— 自定义Copilot初始化工作流的完整指南
references/copilot-setup-steps.md
Setup & Activation
安装与激活
bash
npx skills add -g onsager-ai/dev-skills --skill github-integration -a claude-code -yAuto-activates when: user mentions "gh in cloud", "github integration",
"setup script", "copilot setup steps", or auth failures in cloud
environments.
ghbash
npx skills add -g onsager-ai/dev-skills --skill github-integration -a claude-code -y当用户提及“gh in cloud”、“github integration”、“setup script”、“copilot setup steps”或云环境中认证失败时,将自动激活。
gh