用途:为在 GitHub Actions 中创建和配置 anthropics/claude-code-action@v1 工作流提供参考,覆盖认证、仓库配置、触发模式、权限、工具白名单、输入参数、MCP 配置与安全实践。
认证:可选 OAuth Token(claude_code_oauth_token,推荐,需 Claude Pro 或 Max)、API Key(anthropic_api_key)、AWS Bedrock(aws_access_key_id + aws_secret_access_key)、GCP Vertex(gcp_project_id + gcp_region + gcp_workload_identity_provider)。获取 OAuth Token 需 Claude Pro/Max 订阅,本地运行 claude setup-token,复制输出并执行 gh secret set CLAUDE_CODE_OAUTH_TOKEN 添加为仓库密钥;macOS 上凭据存于加密 Keychain,setup-token 是官方提取方式。
仓库配置:CLAUDE_CODE_OAUTH_TOKEN 为 Secret,所有 Claude 工作流必需;ENABLE_CLAUDE_NIGHTLY 为 Variable,夜间工作流可选启用,命令 gh variable set ENABLE_CLAUDE_NIGHTLY --body "true"。
工作流模式:交互式(评论、评审或 issue 中提及 @claude 触发);CI 自动修复(CI 工作流失败时触发,需用条件防止无限循环,排除 claude-auto-fix- 分支及 main、staging、dev);夜间/定时(cron 调度,如 '0 3 * * 1-5',配合 vars.ENABLE_CLAUDE_NIGHTLY == 'true' 守卫)。标准权限块包含 contents、pull-requests、issues、actions、id-token 的 write/read 设置。
工具白名单:标准 allowedTools 为 Edit,MultiEdit,Write,Read,Glob,Grep,Bash(git:),Bash(npm:),Bash(npx:),Bash(bun:),Bash(yarn:),Bash(pnpm:),Bash(gh:*),覆盖文件操作、Git、包管理器与 GitHub CLI。
关键输入:prompt、claude_code_oauth_token、claude_args(--allowedTools、--max-turns、--system-prompt、--mcp-config)、branch_prefix、additional_permissions、max_turns、track_progress、allowed_bots、allowed_non_write_users。MCP 配置通过 claude_args 传入 --mcp-config .mcp.json,密钥经环境变量传递。
模式与成本:夜间工作流前可用 actions/github-script@v7 检查是否已有同名开放 PR 以避免重复;用 --max-turns 控制用量,建议 CI 自动修复 25 轮、夜间 40 轮,交互式不限制。安全上禁止硬编码密钥,使用 ${{ secrets.* }},清理提示中的动态内容防注入,并用 allowed_bots 限制触发机器人。
限制:资料未提供具体价格、平台支持范围或效果数据。