GitHub Actions や他の CI/CD システムで Cursor CLI を使って開発タスクを自動化しよう。

GitHub Actions への統合

基本的なセットアップ:
- name: Install Cursor CLI
  run: |
    curl https://cursor.com/install -fsS | bash
    echo "$HOME/.cursor/bin" >> $GITHUB_PATH

- name: Run Cursor Agent
  env:
    CURSOR_API_KEY: ${{ secrets.CURSOR_API_KEY }}
  run: |
    cursor-agent -p "Your prompt here" --model gpt-5

クックブックの例

実践的なワークフローはクックブックの例をチェックしてね: ドキュメントの更新CI の問題の修正

その他のCIシステム

次を満たしていれば、どんなCI/CDシステムでもCursor CLIを使えるよ:
  • シェルスクリプトの実行(bash、zsh など)
  • 環境変数での API キー設定
  • Cursor の API にアクセスできるインターネット接続

自律性レベル

エージェントの自律性レベルを選ぼう:

フル自律アプローチ

エージェントに git 操作、API 呼び出し、外部連携の完全な権限を与える。セットアップは簡単で、その分だけ信頼が必要。 例: Update Documentation クックブックでは、最初のワークフローでエージェントが次を実行できる:
  • PR の変更を分析
  • git ブランチの作成と管理
  • 変更のコミットとプッシュ
  • プルリクエストへのコメント投稿
  • あらゆるエラーシナリオの処理
- name: Update docs (full autonomy)
  run: |
    cursor-agent -p "You have full access to git, GitHub CLI, and PR operations. 
    Handle the entire docs update workflow including commits, pushes, and PR comments."

制限付き自律アプローチ

本番の CI ワークフローでは、許可ベースの制限と組み合わせたこのアプローチをおすすめする。複雑な分析やファイル変更はエージェントに任せつつ、クリティカルな操作は決定的で監査可能な状態を保てる。
エージェントの操作を絞り、重要な手順は別のワークフローステップで処理する。コントロールしやすく、予測可能性も高い。 例: 同じクックブックの 2 つ目のワークフローでは、エージェントをファイル変更のみに制限する:
- name: Generate docs updates (restricted)
  run: |
    cursor-agent -p "IMPORTANT: Do NOT create branches, commit, push, or post PR comments. 
    Only modify files in the working directory. A later workflow step handles publishing."

- name: Publish docs branch (deterministic)
  run: |
    # 決定的な git 操作は CI が処理
    git checkout -B "docs/${{ github.head_ref }}"
    git add -A
    git commit -m "docs: update for PR"
    git push origin "docs/${{ github.head_ref }}"

- name: Post PR comment (deterministic)  
  run: |
    # 決定的な PR コメント投稿は CI が処理
    gh pr comment ${{ github.event.pull_request.number }} --body "Docs updated"

許可ベースの制限

permission configurations を使って CLI レベルで制限を適用する:
{
  "permissions": {
    "allow": [
      "Read(**/*.md)",
      "Write(docs/**/*)",
      "Shell(grep)",
      "Shell(find)"
    ],
    "deny": [
      "Shell(git)",
      "Shell(gh)", 
      "Write(.env*)",
      "Write(package.json)"
    ]
  }
}

認証

API キーを生成

まずは Cursor ダッシュボードでAPI キーを生成しよう。

リポジトリのシークレットを設定する

Cursor の API キーをリポジトリに安全に保存しよう:
  1. GitHub の対象リポジトリに移動
  2. SettingsSecrets and variablesActions をクリック
  3. New repository secret をクリック
  4. 名前を CURSOR_API_KEY にする
  5. 値に API キーを貼り付ける
  6. Add secret をクリック

ワークフローで使う

CURSOR_API_KEY 環境変数を設定しよう:
env:
  CURSOR_API_KEY: ${{ secrets.CURSOR_API_KEY }}