claude-code-action
アプリケーションanthropics/claude-code-action
GitHub Action に Claude Code を統合し、コードレビューと自動修正を実現します。
概要
汎用的な GitHub Action で、Claude Code を PR や issue のワークフローに組み込み、質問への回答、コードレビュー、変更の直接実装が可能です。ワークフローのコンテキストに応じて実行モードを自動的に選択し、Anthropic API、Amazon Bedrock、Google Vertex AI、Microsoft Foundry をサポートします。完全に自前の Runner 上で動作し、構造化された JSON 結果を出力できます。
README プレビュー
\n\n# Claude Code Action\n\nA general-purpose [Claude Code](https://claude.ai/code) action for GitHub PRs and issues that can answer questions and implement code changes. This action intelligently detects when to activate based on your workflow context—whether responding to @claude mentions, issue assignments, or executing automation tasks with explicit prompts. It supports multiple authentication methods including Anthropic direct API (API key or workload identity federation), Amazon Bedrock, Google Vertex AI, and Microsoft Foundry.\n\n## Features\n\n- 🎯 **Intelligent Mode Detection**: Automatically selects the appropriate execution mode based on your workflow context—no configuration needed\n- 🤖 **Interactive Code Assistant**: Claude can answer questions about code, architecture, and programming\n- 🔍 **Code Review**: Analyzes PR changes and suggests improvements\n- ✨ **Code Implementation**: Can implement simple fixes, refactoring, and even new features\n- 💬 **PR/Issue Integration**: Works seamlessly with GitHub comments and PR reviews\n- 🛠️ **Flexible Tool Access**: Access to GitHub APIs and file operations (additional tools can be enabled via configuration)\n- 📋 **Progress Tracking**: Visual progress indicators with checkboxes that dynamically update as Claude completes tasks\n- 📊 **Structured Outputs**: Get validated JSON results that automatically become GitHub Action outputs for complex automations\n- 🏃 **Runs on Your Infrastructure**: The action executes entirely on your own GitHub runner (Anthropic API calls go to your chosen provider)\n- ⚙️ **Simplified Configuration**: Unified `prompt` and `claude_args` inputs provide clean, powerful configuration aligned with Claude Code SDK\n\n## 📦 Upgrading from v0.x?\n\n**See our [Migration Guide](./docs/migration-guide.md)** for step-by-step instructions on updating your workflows to v1.0. The new version simplifies configuration while maintaining compatibility with most existing setups.\n\n## Quickstart\n\n
FAQ (5)
トラブル対応Claude Code Action がレビューを実行する前に "subtype: success" と "is_error: true" で断続的に失敗するのはなぜですか?
これは通常、コードレビューが完了した上で失敗したのではなく、Claudeプロセスが起動時に失敗したことを意味します。claude-execution-output.jsonを調べ、resultフィールドを確認してください。報告されたケースでは、そこにCredit balance is too lowが含まれていました。Anthropic APIアカウントの請求/クレジット残高を確認し、クレジットを追加して、ワークフローを再実行することで修正してください。起動に失敗した場合は通常、レビューの集約や指摘がなく、is_error: trueが示され、例えばspawned: 0のようになります。これは、指摘を報告する完了したレビューとは異なります。
トラブル対応Claude Code Action の tag モードで `files` パラメータと `paths` パラメータの不一致が原因で発生する `delete_files` のスキーマ検証エラーは、どうすれば修正できますか?
mcp__github_file_ops__delete_files ツールスキーマは paths を受け付けますが、タグモードのプロンプト例では誤って files が使われています。このため、use_commit_signing: true が有効な場合、Zod バリデーションが最初の削除試行を拒否します。
src/create-prompt/index.ts(827行目付近)のプロンプト例を修正してください:
- mcp__github_file_ops__delete_files: {"files": ["path/to/old.js"], "message": "chore: remove deprecated file"}
+ mcp__github_file_ops__delete_files: {"paths": ["path/to/old.js"], "message": "chore: remove deprecated file"}
その後、アクションを再ビルド/リリースするか、その修正を含むリリースを使用してください。既存の実行では、paths を指定してツール呼び出しを再試行することで、失敗した呼び出しを回避できます:
{"paths": ["path/to/old.js"], "message": "chore: remove deprecated file"}
なお、commit_files は引き続き files を使用します。paths を使用するのは delete_files のみです。回帰テストでは、MCP ツールスキーマをインポートし、プロンプト例内のパラメータ名が対応するスキーマと一致することを検証する必要があります。
トラブル対応claude_args 経由で渡されたカスタム Bash ツールが、Claude のプルリクエストレビュー中に無視されるのはなぜですか?
pull_request イベントでは、このアクションが tag モードを自動検出します。このモードでは、mcp__github_ で始まるユーザー指定の MCP ツールのみがデフォルトの許可リストにマージされます。Bash(npx markdownlint:*) や Bash(gh pr:*) などのカスタムルールは解析されますが、フィルタリングにより除外されます。
カスタム Bash ツールを使用するには、ワークフローで mode: agent を明示的に設定してください:
- uses: anthropics/claude-code-action@v1
with:
mode: agent
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
prompt: |
Run `npx markdownlint *.md` to check markdown files.
claude_args: |
--allowedTools "Bash(npx markdownlint:*),Read,Glob"
キャメルケースのフラグ --allowedTools を使用してください。--allowed-tools は認識されない場合があります。この動作は claude-code-action v1.0.22 で確認されました。
トラブル対応ブランチ名に `#` が含まれている場合に GitHub のブランチリンクが壊れる問題を修正するにはどうすればよいですか?
GitHubのtreeまたはcompare URLにブランチ名を挿入する前に、ブランチ名の各パスセグメントをURLエンコードし、/はパス区切り文字として維持します:
const encodedBranch = branchName
.split("/")
.map(encodeURIComponent)
.join("/");
例えば、claude/fix#123はclaude/fix%23123になり、生成されるリンクは次のようになります:
https://github.com/owner/repo/tree/claude/fix%23123
tracking-commentやbranch-cleanupのコードを含め、ブランチURLが作成されるすべての箇所にこのエンコーディングを適用してください。一時的な回避策として、生成するブランチ名で#の使用を避けるか、リンク内の#を手動で%23に置き換えてください。
トラブル対応GitHub ActionsでClaude Opus 5またはSonnet 5が1Mではなく200kのコンテキストウィンドウに解決されてしまう問題を修正するにはどうすればよいですか?
ワークフロー設定のモデルIDに [1m] コンテキストセレクターを追加してください:
env:
ANTHROPIC_MODEL: claude-opus-5[1m]
ANTHROPIC_SMALL_FAST_MODEL: claude-sonnet-5[1m]
これは、ANTHROPIC_BASE_URL ゲートウェイによって Claude Code がネイティブな1Mコンテキストサポートを自動検出できない場合に必要です。この回避策は、action v1.0.185 と Claude Code 2.1.222 で検証されました。claude-opus-5[1m] は modelUsage.contextWindow を 1000000 に解決しますが、claude-opus-5 は 200000 に解決され、早期の auto-compaction が発生します。
解決された上限を確認するには、show_full_output: true を有効にして、ジョブログ内の modelUsage オブジェクトを確認してください:
"contextWindow": 1000000
注意:[1m] サフィックスを付けても、maxOutputTokens は引き続き 64000 と報告される場合があります。この値はコンテキストウィンドウセレクターとは別に解決されます。