Claude Code: Git ワークフローと GitHub Actions
最終更新:2026-08-31
Claude Code はコードを書くだけでなく — Git ワークフローに統合し、コミット規約から PR レビューまで、CI 統合から自動修正まで。
💡 ヒント: Git ワークフロー統合の核心は「human-in-the-loop」です — Claude Code は支援し、人間が決定します。自動化(CI/CD)にはヘッドレスモード、日常開発にはインタラクティブモードを使用します。
📋 前提条件: 第22章 - 環境変数と開発設定
1. 学ぶ内容
- Claude Code と Git の連携
- コミット規約の自動化
- GitHub Actions 統合
- PR 自動レビュー
- CI/CD パイプラインでの Claude Code
2. Git ワークフロー統合
(1) 一般的な Git 統合コマンド
| 操作 | コマンド | 説明 |
|---|---|---|
| 変更をコミット | /commit |
コミットメッセージを自動生成 |
| 変更を確認 | /diff |
現在のセッションの修正を確認 |
| 操作を取り消し | /undo |
最後の操作を取り消し |
▶ 例1:Claude Code 支援 Git フロー
TEXT
📖 参照専用
> Complete user registration feature development
Claude Code: ファイルを作成、テスト合格 ✅
> /commit
Claude Code が自動生成:
feat: add user registration service
- Create registration.service.ts with email/password signup
- Add POST /api/register endpoint
- Add input validation
- Write 6 unit tests (all passing)
Allow commit? [y/n] y
✅ Committed: feat: add user registration service
3. コミット規約の自動化
(1) Conventional Commits 統合
| 変更タイプ | プレフィックス | 例 |
|---|---|---|
| 新機能 | feat: | feat: add user registration |
| 修正 | fix: | fix: token refresh on expiry |
| リファクタリング | refactor: | refactor: extract validation logic |
| テスト | test: | test: add registration tests |
| ドキュメント | docs: | docs: update API documentation |
| スタイル | style: | style: fix indentation |
| 設定 | chore: | chore: update dependencies |
4. GitHub Actions 統合
(1) PR 自動レビュー
YAML
# .github/workflows/ai_review.yml
name: AI Code Review
on:
pull_request:
types: [opened, synchronize]
jobs:
ai-review:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Install Claude Code
run: npm install -g @anthropic-ai/claude-code
- name: AI Review
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
claude --headless --output json \
"Review this PR: security, performance, style, test coverage" > review.json
- name: Post Review
run: |
COMMENT=$(jq -r '.result.summary' review.json)
gh pr comment ${{ github.event.pull_request.number }} --body "$COMMENT"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
(2) Lint 問題の自動修正
YAML
# .github/workflows/auto-fix.yml
name: Auto Fix Lint
on:
push:
branches: [main]
jobs:
auto-fix:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Claude Code
run: npm install -g @anthropic-ai/claude-code
- name: Fix Lint
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
claude --headless --allowed-tools Read,Write \
"Run npm run lint, fix all auto-fixable issues"
- name: Commit Fixes
run: |
git config user.name "Claude Code Bot"
git add -A
git diff --staged --quiet || git commit -m "style: auto-fix lint issues"
git push
5. PR レビューの実践
(1) Human + AI ダブルレビュー
| 次元 | AI レビュー | 人間のレビュー |
|---|---|---|
| セキュリティ脆弱性 | ✅ 得意 | 補足的 |
| コードスタイル | ✅ 得意 | 不要 |
| パフォーマンス | ✅ 一般 | 重要なシナリオ |
| ビジネスロジック | ❌ 苦手 | ✅ コア |
| アーキテクチャ設計 | ❌ 苦手 | ✅ コア |
❓ よくある質問
Q Claude Code は PR を自動マージできますか?
A 技術的には可能ですが推奨しません。CI の Claude Code はレビューと提案のみ。マージの決定は人間が行います。
Q GitHub Actions の API コストは誰が支払いますか?
A リポジトリ Secrets の API Key を使用するため、Key 所有者の負担になります。クォータ制限付きの別 CI Key を推奨します。
Q CI の無限ループを回避するには?
A 自動修正コミットが新しいワークフローをトリガーしないようにします。YAML に
if: github.actor != 'claude-code-bot' を追加してください。Q GitLab CI でも動作しますか?
A はい。Claude Code は CLI ツールなので、npm を実行できる CI 環境ならどこでも使用可能です。
📖 まとめ
/commitが Conventional Commits 形式のメッセージを自動生成- GitHub Actions はヘッドレスモードで Claude Code を統合
- PR 自動レビュー:セキュリティ、パフォーマンス、スタイル。人間:ビジネス、アーキテクチャ
- CI の Claude Code は提案のみ、決定はしない。human-in-the-loop
- 自動修正コミットによる CI 無限ループに注意
📝 練習問題
- 基本 (⭐):
/commitで変更をコミットし、自動生成メッセージの品質を確認してください。 - 応用 (⭐⭐): GitHub Actions を設定し、PR で自動セキュリティレビューを実行させてください。
- 高度 (⭐⭐⭐): 完全な AI レビューパイプライン(セキュリティ+品質+カバレッジ)を構築し、自動 PR コメントを実装してください。