Claude CodeでGithub Actionを使う
自分用のメモも兼ねてGithub ActionでClaude Codeを使う方法を書きます。
Claude Codeからコマンドでも設定可能。
コマンドは以下。自分はこれだと失敗して出来なかった。
/install-github-app
準備
Claude API Keyの取得
-
Claudeのページから、アカウントを作成しておくこと
-
Claude ConsoleからAPI Keyを取得する。
このページにアクセスして、Create Keyをクリックする。
WorkspaceはDefaultを選択する(Claude Codeは自分のターミナルなどからClaude Codeを実行するときにClaudeにログインする度に自動的に発行されるKeyなので、画面からこのKeyは作成できない)
- 生成されたキーをコピーしておく(一回closeするとこのキーは取得できません)
Githubの設定
-
今回使うProjectのリポジトリが作成済みであること
-
GithubのアプリにClaudeを入れる
こちらのページからClaudeのAppをGithubにインストールする。
・All repositories
・Only select repositories
のどちらかを選択する。
- Github Action用のSecretを設定する。
リポジトリのSettingsから「Secrets and Variables」の「Actions」へ。
Repository Secretsの「New Repository Secret」ボタンをクリックして、先ほどのkeyをコピペする。
3. Github Actionの権限設定をする
Settings内のActions > Generalを選択。
Workflow permissionsで「Read and write permissions」を選択してsaveする。
- Project内にClaude Code Action用の設定ファイルを置く。
/.github/workflows/claude.yml
こちらに記載する内容は公式のこちらをコピー。
name: Claude PR Assistant
on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
issues:
types: [opened, assigned]
pull_request_review:
types: [submitted]
jobs:
claude-code-action:
if: |
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
(github.event_name == 'issues' && contains(github.event.issue.body, '@claude'))
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
issues: read
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Run Claude PR Action
uses: anthropics/claude-code-action@beta
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
timeout_minutes: "60"
Claude Code Actionでオフライン開発する
ここまでの設定が終わったら、GithubのIssueを立てる。
@claude
でclaudeに向けて、やって欲しいことを書くと...
しばらくすると、Claudeがチェックリスト形式でやったことを書いてくれる。
Claudeがやってくれた返信から、Create PR
をし、手元などで確認してからマージすればOK!
外出先などでPCがなくても、Issueでやりたいことをバンバン立てていけば、あとは帰ってからPR内容をチェックしてマージするだけで開発できちゃう。
Discussion