Authentication
Cursor CLI supports two authentication methods: browser-based login (recommended) and API keys.
Browser authentication (recommended)
Use the browser flow for the easiest authentication experience:
# Log in using browser flowagent login# Check authentication statusagent status# Log out and clear stored authenticationagent logoutThe login command opens your default browser and prompts you to authenticate with your Cursor account. Set NO_OPEN_BROWSER=1 to print the login URL without opening a browser. Once complete, your credentials are securely stored locally.
API key authentication
For automation, scripts, or CI environments, use API key authentication:
Step 1: Generate an API key
Generate a user API key from Cursor Dashboard → API Keys.
Step 2: Set the API key
You can provide the API key in two ways:
Option 1: Environment variable (recommended)
export CURSOR_API_KEY=your_api_key_hereagent "implement user authentication"Option 2: Command line flag
agent --api-key your_api_key_here "implement user authentication"Authentication status
Check your current authentication status:
agent statusThis command will display:
- Whether you're authenticated
- Your account information
- Current endpoint configuration
Troubleshooting
- "Not authenticated" errors: Run
agent loginor ensure your API key is correctly set - Browser doesn't open: Run
NO_OPEN_BROWSER=1 agent loginand open the printed URL manually