Skip to content

SOP-013: CLI Installation

Document Control

FieldValue
SOP IDSOP-013
Version1.0
StatusActive
Last Updated2024-12

Purpose

This SOP provides detailed instructions for installing and using Cursor CLI (cursor-agent) for terminal-based AI coding assistance.

Scope

  • CLI installation
  • Interactive mode
  • Non-interactive/headless mode
  • Session management

Prerequisites

  • macOS, Linux, or Windows (WSL)
  • Internet connection
  • Cursor account

Procedure

CLI Overview

ModeCommandFeatures
Interactivecursor-agentConversational interface, review/approve changes, persistent context
Non-Interactivecursor-agent -p "prompt"Single-shot execution, CI/CD friendly, structured output

Step 1: Install CLI

One-liner Installation:

bash
curl https://cursor.com/install -fsS | bash

This downloads the cursor-agent binary to ~/.local/bin/.

Step 2: Configure PATH

If cursor-agent isn't found after install:

For Bash:

bash
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

For Zsh:

bash
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

Step 3: Verify Installation

bash
cursor-agent --version

Should output version number like cursor-agent 1.x.x

Step 4: Start Interactive Session

bash
# Start in current directory
cursor-agent

# Start with initial prompt
cursor-agent "explain the main.go file"

# Start in specific directory
cd /path/to/project && cursor-agent

Interactive Session Commands:

ActionHow To
Send messageType and press Enter
New lineShift+Enter
CancelCtrl+C
ExitType exit or Ctrl+D

Step 5: Non-Interactive Mode

For scripts, CI/CD, and automation:

bash
# Basic usage
cursor-agent -p "find and fix security issues"

# Specify model
cursor-agent -p "review code for performance" --model "gpt-5"

# Include git changes for review
cursor-agent -p "review these changes" --output-format text

# JSON output for parsing
cursor-agent -p "list all functions" --output-format json

Step 6: Session Management

List Previous Sessions:

bash
cursor-agent ls

Resume Latest Session:

bash
cursor-agent resume

Resume Specific Session:

bash
cursor-agent --resume="session-id-here"

Shell Mode

For continuous terminal interaction:

bash
cursor-agent shell

Shell Mode Features:

  • Persistent context across commands
  • Command history
  • Rule integration
  • MCP support

MCP in CLI

Use MCP servers from the command line:

bash
# List available MCP tools
cursor-agent --list-mcp-tools

# Configure MCP in project
# Create .cursor/mcp.json as described in SOP-012

GitHub Actions Integration

Example Workflow:

yaml
name: Code Review
on: pull_request

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install Cursor CLI
        run: curl https://cursor.com/install -fsS | bash

      - name: Review Changes
        env:
          CURSOR_API_KEY: ${{ secrets.CURSOR_API_KEY }}
        run: |
          ~/.local/bin/cursor-agent -p "Review this PR for security issues" \
            --output-format text > review.txt

      - name: Comment on PR
        uses: actions/github-script@v7
        with:
          script: |
            const fs = require('fs');
            const review = fs.readFileSync('review.txt', 'utf8');
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: review
            });

CLI Reference

CommandDescription
cursor-agentStart interactive session
cursor-agent "prompt"Start with initial prompt
cursor-agent -p "prompt"Non-interactive single prompt
cursor-agent lsList sessions
cursor-agent resumeResume latest session
cursor-agent shellStart shell mode
cursor-agent updateUpdate to latest version
cursor-agent --versionShow version
cursor-agent --helpShow help

Common Flags:

FlagDescription
-p, --promptPrompt to execute
--modelAI model to use
--output-formatOutput format (text, json)
--resumeResume session by ID

Updating CLI

bash
# Auto-update (happens automatically)
# Or manually:
cursor-agent update
# or
cursor-agent upgrade

Verification Checklist

  • [ ] CLI installed successfully
  • [ ] cursor-agent --version works
  • [ ] Interactive session starts
  • [ ] Can send prompts and receive responses
  • [ ] Session resume works
  • [ ] Non-interactive mode executes

Troubleshooting

IssueSolution
Command not foundAdd ~/.local/bin to PATH
Permission deniedCheck file permissions
Network errorCheck internet, firewall
Session not foundUse cursor-agent ls to find ID
Authentication failedRe-run install script

See Also

Built with VitePress | Powered by Claude AI