The Cursor CLI provides powerful command-line tools to integrate Cursor with your development workflow. Open files and folders, manage projects, and streamline your coding process directly from the terminal.

Installation

Install the CLI commands through Cursor’s Command Palette:
  1. Open the Command Palette (Cmd/Ctrl + Shift + P)
  2. Type “Install” to filter installation commands
  3. Select and run Shell Command: Install ‘cursor’ command in PATH
  4. Optionally, also run Shell Command: Install ‘code’ command in PATH for VS Code compatibility
The installation adds the commands to your system’s PATH, making them available in any terminal session.

Basic Usage

Opening Files and Folders

# Open a single file
cursor file.js

# Open a folder/project
cursor ./my-project

# Open current directory
cursor .

# Open multiple files
cursor file1.js file2.js folder/

# Open with VS Code compatible command
code file.js

Command Options

The Cursor CLI supports various options to customize how files and folders are opened:
OptionShortDescription
--new-window-nOpen in a new window
--wait-wWait for the window to close before returning
--add-aAdd folder(s) to the last active window
--goto-gGo to line and column (e.g., file.js:10:5)
--diff-dCompare two files side by side
--merge-mPerform a three-way merge
--reuse-window-rForce to open a file or folder in an already opened window
--help-hShow help information
--version-vShow version information

Advanced Usage

Opening Files at Specific Lines

Navigate directly to specific lines and columns in your files:
# Go to line 42
cursor file.js:42

# Go to line 42, column 10
cursor file.js:42:10

# Using the --goto flag
cursor --goto 42:10 file.js

Working with Multiple Windows

# Open in a new window
cursor -n project-folder/

# Add folder to existing window
cursor -a additional-folder/

# Reuse existing window
cursor -r file.js

File Comparison and Merging

# Compare two files
cursor --diff file1.js file2.js

# Three-way merge
cursor --merge base.js modified1.js modified2.js

Waiting for Editor to Close

Useful for git commit messages and other workflows:
# Wait for editor to close before continuing
cursor --wait commit-message.txt

# Use in git configuration
git config --global core.editor "cursor --wait"

Integration Examples

Git Integration

Configure Cursor as your default Git editor:
# Set as default editor
git config --global core.editor "cursor --wait"

# Set as diff tool
git config --global diff.tool cursor
git config --global difftool.cursor.cmd 'cursor --wait --diff "$LOCAL" "$REMOTE"'

# Set as merge tool
git config --global merge.tool cursor
git config --global mergetool.cursor.cmd 'cursor --wait --merge "$REMOTE" "$LOCAL" "$BASE" "$MERGED"'

Shell Aliases

Create convenient aliases for common operations:
# Add to your .bashrc, .zshrc, or equivalent
alias c='cursor'
alias co='cursor .'
alias cn='cursor -n'

# Open current directory in new window
alias cwd='cursor -n .'

Project Scripts

Integrate with package.json scripts:
{
  "scripts": {
    "edit": "cursor .",
    "edit:config": "cursor package.json tsconfig.json",
    "edit:src": "cursor src/"
  }
}

Environment Variables

Cursor CLI respects these environment variables:
VariableDescription
CURSOR_PATHOverride the path to the Cursor executable
CURSOR_USER_DATA_DIRSet custom user data directory
CURSOR_EXTENSIONS_DIRSet custom extensions directory

Troubleshooting

VS Code Compatibility

The code command provides full compatibility with VS Code CLI usage:
# These commands work identically
code file.js
cursor file.js

# All VS Code CLI patterns are supported
code --goto 10:5 file.js
code --diff file1.js file2.js
code --new-window project/
This makes it easy to switch from VS Code to Cursor without changing your existing scripts and workflows.

Tips and Best Practices

Quick Project Access

Create shell functions for frequently accessed projects:
function work() {
  cursor ~/work/$1
}

Batch Operations

Open multiple related files at once:
cursor src/**/*.{js,ts,jsx,tsx}

Integration Scripts

Use the CLI in build scripts and automation:
npm run build && cursor dist/

Remote Development

Combine with SSH for remote editing:
ssh server "cursor /path/to/project"

See Also

  • Shell Commands - Basic shell command installation
  • Context - Working with files and projects in Cursor
  • Settings - Configuring Cursor preferences