Control Cursor IDE programmatically. Use for editing files, running AI prompts (Cmd+K), inline editing, and managing Cursor projects. Integrates with Cursor's AI features for autonomous code editing.
Control Cursor IDE from the command line. Edit files, run AI prompts, and automate your workflow.
cursor command in PATH# Open file in Cursor
python3 {baseDir}/scripts/cursor.py open src/main.ts
# Edit specific lines
python3 {baseDir}/scripts/cursor.py edit src/main.ts --line 10 --insert "console.log('debug');"
# Run AI prompt (Cmd+K)
python3 {baseDir}/scripts/cursor.py ai "Add error handling to this function"
# Inline edit with AI
python3 {baseDir}/scripts/cursor.py inline "Refactor this to use async/await"
cursor.py open <file> [--line <num>]
Opens file in Cursor at specific line.
cursor.py edit <file> [options]
--line <n> Line number
--insert <text> Insert text
--replace <text> Replace line
--delete Delete line
cursor.py ai "<prompt>" [--file <file>]
Sends prompt to Cursor's AI (Chat).
cursor.py inline "<instruction>" --file <file> --line <n>
Inline editing with AI at specific location.
# Insert import at line 1
cursor.py edit src/app.ts --line 1 --insert "import { useState } from 'react';"
# Replace function
cursor.py edit src/utils.ts --line 25 --replace "const newFunction = () => {};"
# Delete line
cursor.py edit src/temp.ts --line 10 --delete
# Add JSDoc comments
cursor.py ai "Add JSDoc comments to all exported functions" --file src/api.ts
# Generate tests
cursor.py ai "Create unit tests for this component" --file src/Button.tsx
# Refactor
cursor.py inline "Convert to TypeScript interface" --file src/types.js --line 5
# Apply change across files
cursor.py ai "Update all console.log to logger.info" --glob "src/**/*.ts"
# Find and replace with AI understanding
cursor.py ai "Replace axios with fetch API in all files"
# Edit then test
terminal.run("npm run build")
cursor.open("src/error.ts", line=error_line)
# Make AI changes, then commit
cursor.ai("Optimize this function")
git.commit("Optimize function using AI suggestions")
# Auto-fix errors
error = debug.parse_error(log)
cursor.inline(f"Fix: {error.message}", file=error.file, line=error.line)
# 1. Open file
cursor.py open src/feature.ts
# 2. AI generates code
cursor.py ai "Add a login function with JWT validation"
# 3. Review and edit
cursor.py edit src/feature.ts --line 20 --replace "// Improved version"
# 4. Save and test
terminal.py run "npm test"
# 1. Find files to refactor
terminal.py run "find src -name '*.js'"
# 2. Open and refactor each
cursor.py ai "Convert to TypeScript" --file src/old.js
# 3. Check results
terminal.py run "npx tsc --noEmit"
In ~/.cursor/settings.json:
{
"cursor.cmdk.enabled": true,
"cursor.ai.model": "claude-3.5-sonnet"
}
result = cursor.edit("file.ts", line=10, insert="code")
if result.success:
print("✅ Edit successful")