Claude Code Actionをv1にアップグレードしました
はじめに
先日claude code actionからbetaが外れ、v1がリリースされましたね🎉
自分は日頃からこのGithub Actionsに大変お世話になっており、今回もリリース早々バージョンアップグレードを試しました!
、、が、ちゃんと動作する状態にするのに若干苦労しました🥹
この記事では自分がclaude code actionをbetaからv1にアップグレードするまでに行ったことや参照した資料について記述します。
まずはマーグレーションガイドからスタート!しかし、、
claude code actionのbetaからv1へのアップグレードには多数のbreaking changesが含まれるため、公式がマイグレーションガイドを公開しています。大変ありがたいです🙏
自分もまずはこのマイグレーションガイドに従ってアップグレードを行いました。
- アクションバージョンを更新:
@beta
を@v1
に変更 - モード設定を削除:
mode: "tag"
またはmode: "agent"
を削除(現在は自動検出) - プロンプト入力を更新:
direct_prompt
をprompt
に置き換え - CLIオプションを移動:
max_turns
、model
、custom_instructions
などをclaude_args
に変換
下記がこの時点でのコード(一部マスキング・編集しています)
name: Claude Code Review
on:
pull_request:
types: [opened, synchronize]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
claude-review:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
issues: read
id-token: write
actions: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Run Claude Code Review
id: claude-review
uses: anthropics/claude-code-action@v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
allowed_bots: "claude-bot,claude"
timeout_minutes: "60"
# Direct prompt for automated review (no @claude mention needed)
prompt: |
${既存のプロンプト}
# Claude arguments (migrated from individual parameters)
claude_args: |
--model claude-opus-4-1-20250805
--allowedTools "mcp__github__create_pending_pull_request_review,
mcp__github__add_comment_to_pending_review,
mcp__github__submit_pending_pull_request_review,
mcp__github__get_pull_request_diff"
use_sticky_comment: true
そして、この時点でこのactionsは失敗しました🫠
失敗したときのログを確認すると、下記のようなwarningメッセージが出ているのが確認できました。
Warning: Unexpected input(s) 'timeout_minutes', valid inputs are ['trigger_phrase', 'assignee_trigger', 'label_trigger', 'base_branch', 'branch_prefix', 'allowed_bots', 'prompt', 'settings', 'anthropic_api_key', 'claude_code_oauth_token', 'github_token', 'use_bedrock', 'use_vertex', 'claude_args', 'additional_permissions', 'use_sticky_comment', 'use_commit_signing', 'bot_id', 'bot_name', 'track_progress', 'experimental_allowed_domains', 'path_to_claude_code_executable', 'path_to_bun_executable']
どうもtimeout_minutes
のオプションが消えたらしい、、?
しかもなんだか見覚えのないオプションが増えてるような、、?
また、エラーは上記とは別の理由が原因で発生していました。
Failed to setup GitHub token: Error: Workflow validation failed. The workflow file must exist and have identical content to the version on the repository's default branch. If you're seeing this on a PR when you first add a code review workflow file to your repository, this is normal and you should ignore this error.
実はまだあった!2つ目のマイグレーションガイド
先ほどのwarningを見ると、これまではなかった複数のオプションが追加されているのが確認できます。
「実はbreaking changesはこんなもんじゃなく存在するのでは、、?」
そう思いclaude code actionのリポジトリを確認したところ、偶然リポジトリ側にもマイグレーションガイドが存在するのを確認しました😳
そして、こちらの内容はwebドキュメント側のマイグレーションガイドより内容が充実していました、、!
timeout_minutes
claude code actionのtimeout_minutes
オプションは消えました。今後はgithub actions側のtimeout-minutes
を使うと良いようです。
(下記は公式からの引用)
- uses: anthropics/claude-code-action@beta
with:
timeout_minutes: 30
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
jobs:
claude-task:
runs-on: ubuntu-latest
timeout-minutes: 30 # Moved to job level
steps:
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
リポジトリとPR number
マイグレーションガイドに次のように書かれています
⚠️ Important: For PR reviews, always include the repository and PR context in your prompt. This ensures Claude knows which PR to review.
⚠️ 重要: PR レビューの場合は、プロンプトにリポジトリと PR コンテキストを常に含めてください。 これにより、Claude はどの PR を確認するかを確実に把握できます。
実は、諸々設定値の課題をクリアしてもreviewのCIは動作しません。GithubリポジトリとPull Requestの特定に失敗します
自分は一度ここでハマり、後ほどこの記述に気づきました😇
プロンプトを下記のように修正する必要があります(公式からの引用)。
- uses: anthropics/claude-code-action@beta
with:
mode: "agent"
direct_prompt: "Review this PR for security issues"
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
model: "claude-3-5-sonnet-20241022"
allowed_tools: "Edit,Read,Write"
- uses: anthropics/claude-code-action@v1
with:
prompt: |
REPO: ${{ github.repository }}
PR NUMBER: ${{ github.event.pull_request.number }}
Review this PR for security issues
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
claude_args: |
--model claude-4-0-sonnet-20250805
--allowedTools Edit,Read,Write
Progress Trackingがデフォルトで消滅
実は、諸々設定値の課題やプロンプトを調整してもいつものclaude is working..
みたいなメッセージは出てきません。
この設定はagent modeではデフォルトで無効になってしまいました。
自分はこの機能は不要だと感じていたためそのままにしたのですが、必要な場合は下記のようにtrack_progress
の設定を追加する必要があります。
(下記は公式より引用)
- uses: anthropics/claude-code-action@beta
with:
mode: "agent"
direct_prompt: "Review this PR for security issues"
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
- uses: anthropics/claude-code-action@v1
with:
track_progress: true # Forces tag mode with tracking comments
prompt: |
REPO: ${{ github.repository }}
PR NUMBER: ${{ github.event.pull_request.number }}
Review this PR for security issues
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
ここまでの対応を行い、CIのテンプレートは下記のようになりました。
name: Claude Code Review
on:
pull_request:
types: [opened, synchronize]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
claude-review:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
issues: read
id-token: write
actions: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Run Claude Code Review
id: claude-review
uses: anthropics/claude-code-action@v1
timeout-minutes: 60
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
allowed_bots: "claude-bot,claude"
# Direct prompt for automated review (no @claude mention needed)
prompt: |
REPO: ${{ github.repository }}
PR NUMBER: ${{ github.event.pull_request.number }}
${既存のプロンプト}
# Claude arguments (migrated from individual parameters)
claude_args: |
--model claude-opus-4-1-20250805
--allowedTools "mcp__github__create_pending_pull_request_review,
mcp__github__add_comment_to_pending_review,
mcp__github__submit_pending_pull_request_review,
mcp__github__get_pull_request_diff"
しかし、エラーはまだ発生します
Failed to setup GitHub token: Error: Workflow validation failed. The workflow file must exist and have identical content to the version on the repository's default branch. If you're seeing this on a PR when you first add a code review workflow file to your repository, this is normal and you should ignore this error.
エラーを無視してマージする
先ほどのエラーを日本語にすると
GitHub トークンのセットアップに失敗しました: エラー: ワークフローの検証に失敗しました。 ワークフロー ファイルが存在し、リポジトリの既定のブランチのバージョンと同じコンテンツを持っている必要があります。 コード レビュー ワークフロー ファイルを最初にリポジトリに追加するときに PR でこれが表示される場合、これは正常であり、このエラーは無視する必要があります。
となります。Githubトークンのセットアップに失敗しているわけです。
内容的にデフォルトブランチにマージするまで真偽が確かめられなかったためマージして動作チェックを行ったところ、無事エラーが出なくなるのを確認しました🎉
ちなみに上記のエラーはclaude code actionにgithub_token
の設定を追加することでも回避することができます。
- name: Run Claude Code Action
uses: anthropics/claude-code-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
まだ微妙に権限が足りない、、!!
ここまで設定してClaude Code Actionをコードレビューに使用していたところ、度々権限不足で動作しない問題が発生しました🫠
プロンプトなどによって必要な権限は異なるため、ログを見ながら都度作業することが必要になります。
自分の場合は下記の権限などを追加しました
mcp__github_inline_comment__create_inline_comment
mcp__github__get_pull_request
mcp__github__get_pull_request_comments
まとめ
思ってたよりハイコストで大変でしたが、無事動作するようになってよかったです😇特にリポジトリ側のマイグレーションガイドを見つけるまでは、急にProgress Trackingもコメントも出なくなったためバグを疑ってたりしました
ぜひ、お早めの対応を〜🖐️
Discussion