Claude Code Actionをv1にアップグレードしました

に公開

はじめに

先日claude code actionからbetaが外れ、v1がリリースされましたね🎉

https://github.com/anthropics/claude-code-action/releases/tag/v1

自分は日頃からこのGithub Actionsに大変お世話になっており、今回もリリース早々バージョンアップグレードを試しました!
、、が、ちゃんと動作する状態にするのに若干苦労しました🥹

この記事では自分がclaude code actionをbetaからv1にアップグレードするまでに行ったことや参照した資料について記述します。

まずはマーグレーションガイドからスタート!しかし、、

claude code actionのbetaからv1へのアップグレードには多数のbreaking changesが含まれるため、公式がマイグレーションガイドを公開しています。大変ありがたいです🙏

https://docs.anthropic.com/ja/docs/claude-code/github-actions#ベータ版からのアップグレード

自分もまずはこのマイグレーションガイドに従ってアップグレードを行いました。

  1. アクションバージョンを更新: @beta@v1に変更
  2. モード設定を削除: mode: "tag"またはmode: "agent"を削除(現在は自動検出)
  3. プロンプト入力を更新: direct_promptpromptに置き換え
  4. CLIオプションを移動: max_turnsmodelcustom_instructionsなどをclaude_argsに変換

下記がこの時点でのコード(一部マスキング・編集しています)

claude-code-review.yml
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のリポジトリを確認したところ、偶然リポジトリ側にもマイグレーションガイドが存在するのを確認しました😳

https://github.com/anthropics/claude-code-action/blob/main/docs/migration-guide.md

そして、こちらの内容はwebドキュメント側のマイグレーションガイドより内容が充実していました、、!

timeout_minutes

claude code actionのtimeout_minutesオプションは消えました。今後はgithub actions側のtimeout-minutesを使うと良いようです。

(下記は公式からの引用)

Before (v0.x)
- uses: anthropics/claude-code-action@beta
  with:
    timeout_minutes: 30
    anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
After (v1.0)
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の特定に失敗します
自分は一度ここでハマり、後ほどこの記述に気づきました😇

プロンプトを下記のように修正する必要があります(公式からの引用)。

Before (v0.x)
- 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"
After (v1.0)
- 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の設定を追加する必要があります。

(下記は公式より引用)

(v0.x with tracking)
- uses: anthropics/claude-code-action@beta
  with:
    mode: "agent"
    direct_prompt: "Review this PR for security issues"
    anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
(v1.0 with tracking)
- 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のテンプレートは下記のようになりました。

claude-code-review.yml
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