Skip to main content

Command Palette

Search for a command to run...

ヘッドレス / CI

GitHub Actions

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: |    agent -p "Your prompt here" --model gpt-5

Cookbook の例

実用的なワークフローについては、ドキュメントの更新CI の問題の修正などの Cookbook の例を参照してください。

その他のCIシステム

Cursor CLIは、以下の条件を満たす任意のCI/CDシステムで使用できます。

  • シェルスクリプトの実行 (bash、zshなど)
  • APIキーの設定に使用する環境変数
  • Cursor APIへの接続に必要なインターネット接続

自律性レベル

エージェントの自律性レベルを選択してください。

完全自律アプローチ

エージェントに、Git 操作、API 呼び出し、外部とのやり取りを全面的に任せます。セットアップは簡単ですが、より高い信頼が求められます。

例:Update Documentation cookbook の最初のワークフローでは、エージェントが次を行います。

  • PR の変更を分析
  • Git ブランチを作成・管理
  • 変更をコミットしてプッシュ
  • プルリクエストにコメントを投稿
  • あらゆるエラー状況に対応
- name: Update docs (full autonomy)  run: |    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."

制限付き自律性アプローチ

重要なステップはワークフロー内で別途処理し、エージェントの操作を制限します。制御性と予測可能性が向上します。

例: 同じ cookbook の 2 つ目のワークフローでは、エージェントにフ���イルの変更のみを許可しています。

- name: Generate docs updates (restricted)  run: |    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: |    # CI が処理する決定論的な Git 操作    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: |    # CI が処理する決定論的な PR コメントの投稿    gh pr comment ${{ github.event.pull_request.number }} --body "Docs updated"

権限ベースの制限

権限設定を使用して、CLI レベルで制限を適用します。

{  "permissions": {    "allow": [      "Read(**/*.md)",      "Write(docs/**/*)",      "Shell(grep)",      "Shell(find)"    ],    "deny": ["Shell(git)", "Shell(gh)", "Write(.env*)", "Write(package.json)"]  }}

認証

API キーを生成する

まず、Cursor ダッシュボードで API キーを生成します

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

GitHub CLI を使用して、Cursor API キーをリポジトリに安全に保存します。

# リポジトリシークレットgh secret set CURSOR_API_KEY --repo OWNER/REPO --body "$CURSOR_API_KEY"# 組織シークレット(すべてのリポジトリ)gh secret set CURSOR_API_KEY --org ORG --visibility all --body "$CURSOR_API_KEY"

または、GitHubのUIで、リポジトリに移動し、SettingsSecrets and variablesActionsNew repository secret を選択します。

ワークフローでの使用

CURSOR_API_KEY 環境変数を設定します。

env:  CURSOR_API_KEY: ${{ secrets.CURSOR_API_KEY }}