Enhanced Cursor CLI Agent integration for Emacs. This package provides a comprehensive interface to interact with the Cursor CLI Agent directly from Emacs.
Note: This plugin was created using Cursor - an AI-powered code editor that helped accelerate development.
- Self-contained installation - Install Cursor CLI directly from Emacs
- Installation & authentication verification - Check setup status
- Interactive and non-interactive modes - Flexible usage patterns
- Session management - Resume previous conversations
- Model selection - Choose your preferred AI model
- Output format options - Text, JSON, or stream-JSON formats
- Shell mode support - Quick command execution
- MCP server management - Manage Model Context Protocol servers
- ANSI color support - Automatic color handling in output buffers
- Terminal compatibility - Works in both GUI and terminal Emacs
- Emacs 27.1 or higher
- Cursor CLI Agent (can be installed via the package)
- Optional:
vtermpackage for better terminal emulation (falls back toshell-modeif not available)
- Clone this repository or download
cursor-agent.el - Add to your Emacs configuration:
(add-to-list 'load-path "/path/to/cursor-agent.el")
(require 'cursor-agent)M-x package-install-file RET /path/to/cursor-agent.el RET(use-package cursor-agent
:load-path "/path/to/cursor-agent"
:config
(setq cursor-agent-default-model "gpt-5"))-
Install Cursor CLI (if not already installed):
M-x cursor-agent-install -
Authenticate:
M-x cursor-agent-login -
Verify setup:
M-x cursor-agent-verify-setup -
Start using:
M-x cursor-agent-prompt
| Command | Description |
|---|---|
cursor-agent-install |
Install Cursor CLI Agent |
cursor-agent-prompt |
Run agent with a prompt |
cursor-agent-interactive |
Start interactive session |
cursor-agent-region |
Process selected region |
cursor-agent-resume |
Resume previous conversation |
cursor-agent-login |
Authenticate with Cursor |
cursor-agent-status |
Show authentication status |
cursor-agent-verify-setup |
Verify installation and auth |
| Command | Description |
|---|---|
cursor-agent-list-sessions |
List all previous sessions |
cursor-agent-list-models |
List available models |
cursor-agent-mcp-list |
List MCP servers |
cursor-agent-shell-mode |
Start shell mode |
cursor-agent-update |
Update Cursor CLI |
cursor-agent-readme |
Display the README file |
- Select a region of code
- Run
M-x cursor-agent-region - The agent will process the code and display results
- Run
M-x cursor-agent-interactive - Type your prompts directly in the terminal
- Use standard terminal navigation
Customize the package behavior:
;; Set default model
(setq cursor-agent-default-model "gpt-5")
;; Set default output format
(setq cursor-agent-default-output-format "json") ; or "text", "stream-json"
;; Enable --force flag for file modifications
(setq cursor-agent-use-force t)
;; Change the command name (if different)
(setq cursor-agent-command "my-agent")The package does not define keybindings by default. Add your own:
;; Example keybindings
(global-set-key (kbd "C-c a a") 'cursor-agent-prompt)
(global-set-key (kbd "C-c a i") 'cursor-agent-interactive)
(global-set-key (kbd "C-c a r") 'cursor-agent-region)
(global-set-key (kbd "C-c a I") 'cursor-agent-install)
(global-set-key (kbd "C-c a L") 'cursor-agent-login)
(global-set-key (kbd "C-c a s") 'cursor-agent-status)Or with use-package:
(use-package cursor-agent
:bind (("C-c a a" . cursor-agent-prompt)
("C-c a i" . cursor-agent-interactive)
("C-c a r" . cursor-agent-region)
("C-c a I" . cursor-agent-install)
("C-c a L" . cursor-agent-login)
("C-c a s" . cursor-agent-status)))For better terminal emulation in interactive mode (GUI Emacs only):
M-x package-install RET vterm RETImportant Notes:
- vterm requires GUI Emacs and will not work in terminal mode
- In terminal mode, the package automatically uses
shell-mode(built-in) - The fallback is seamless - no configuration needed
- All functions work identically with or without vterm
Doom Emacs users: If you have the :term vterm module enabled, vterm is already available.
This package works seamlessly with Doom Emacs. Here are recommended integration methods:
Place cursor-agent.el in your Doom config directory and load it:
-
Copy the file to your Doom config:
cp cursor-agent.el ~/.config/doom/ -
Add to
~/.config/doom/config.el:;; Load cursor-agent (load! "cursor-agent") ;; Optional: Configuration (setq cursor-agent-default-model "gpt-5") ;; Keybindings using Doom's map! macro (map! :leader (:prefix "c" ; Code prefix (:prefix ("A" . "cursor-agent") :desc "Cursor Agent Install" "I" #'cursor-agent-install :desc "Cursor Agent Prompt" "a" #'cursor-agent-prompt :desc "Cursor Agent Interactive" "i" #'cursor-agent-interactive :desc "Cursor Agent Region" "r" #'cursor-agent-region :desc "Cursor Agent Resume" "R" #'cursor-agent-resume :desc "Cursor Agent List Sessions" "l" #'cursor-agent-list-sessions :desc "Cursor Agent Status" "s" #'cursor-agent-status :desc "Cursor Agent Login" "L" #'cursor-agent-login :desc "Cursor Agent List Models" "m" #'cursor-agent-list-models :desc "Cursor Agent MCP List" "M" #'cursor-agent-mcp-list :desc "Cursor Agent Shell Mode" "S" #'cursor-agent-shell-mode :desc "Cursor Agent Update" "u" #'cursor-agent-update :desc "Cursor Agent Verify Setup" "v" #'cursor-agent-verify-setup)))
-
Restart Emacs - No
doom syncneeded for local files!
If you want to track the package via Git and get updates:
-
Add to
~/.config/doom/packages.el:(package! cursor-agent :recipe (:host github :repo "chocoelho/cursor-agent.el" :files ("cursor-agent.el")))
-
Run
doom syncto install -
Add configuration to
~/.config/doom/config.el— useafter! cursor-agentonly forsetqand keybindings. Do notunload-featureorloadthe package inafter!; that causes recursive load errors (see Known issues):(after! cursor-agent (setq cursor-agent-default-model "gpt-5") ;; Keybindings (map! :leader (:prefix "c" (:prefix ("A" . "cursor-agent") "a" #'cursor-agent-prompt "i" #'cursor-agent-interactive "r" #'cursor-agent-region "I" #'cursor-agent-install "L" #'cursor-agent-login "s" #'cursor-agent-status)))
If you're developing or want to keep it in a separate directory:
-
Add to
~/.config/doom/packages.el:(package! cursor-agent :recipe (:local-repo "/path/to/cursor-agent.el" ; or "~/workspaces/personal/cursor-agent.el" :files ("cursor-agent.el") :build (:not compile))) ; optional: faster iteration when not byte-compiling
-
Run
doom sync -
Configure in
~/.config/doom/config.elas in Method 2. Do notunload-featureorloadcursor-agent inafter!— it causes recursive load errors.
With :local-repo, Doom/Straight may only autoload a few commands at startup. Run M-x cursor-agent-install (or any autoloaded command) once to load the full file; after that, all commands are available. See Known issues.
The recommended keybinding layout for Doom Emacs:
SPC c A I- Install Cursor CLISPC c A a- PromptSPC c A i- Interactive sessionSPC c A r- Process regionSPC c A R- Resume sessionSPC c A l- List sessionsSPC c A s- StatusSPC c A L- LoginSPC c A m- List modelsSPC c A M- MCP serversSPC c A S- Shell modeSPC c A u- Update CLISPC c A v- Verify setup
Why SPC c A?
SPC cis Doom's code prefix (already used for code actions)A(capital) keeps AI-related commands organized- Nested within code prefix for logical grouping
- No
doom syncneeded for Method 1 (local file) - just restart Emacs - Use
after!macro for package configuration when usingpackage!— only forsetqand keybindings, not forunload-featureorloadof cursor-agent (causes recursive load) - Use
map!macro for keybindings (Doom's DSL) - vterm module: If you have Doom's
:term vtermmodule enabled, vterm will be available automatically
With Doom and Straight (package! with :local-repo or :host github), only a subset of commands may appear in M-x at startup. Run M-x cursor-agent-install (or any other autoloaded command) once to load the full package; after that, all commands are available. This comes from how Doom/Straight generate and apply autoloads; the package itself has ;;;###autoload on all commands.
Do not use unload-feature and load (or load-file) of cursor-agent.el inside an after! cursor-agent block. That causes a recursive load between the Straight build path and your source path (e.g. workspace or :local-repo). Use after! cursor-agent only for configuration (setq, keybindings). The package is already loaded by Doom/Straight.
This package is designed and tested primarily for vanilla Emacs. It uses only standard Emacs features and has no distribution-specific dependencies.
- Vanilla Emacs 27.1+ (primary target)
- GUI Emacs (X11, macOS, Windows)
- Terminal Emacs (interactive and non-interactive sessions)
- Emacs distributions (compatible but not specifically targeted)
- Doom Emacs (see Doom Emacs Integration section above)
- Spacemacs
- Any other Emacs distribution
- Vanilla-first: All code is written and tested against vanilla Emacs
- Standard features only: Uses only built-in Emacs functionality
- No distribution assumptions: Does not rely on features from Doom Emacs, Spacemacs, or other distributions
- Universal compatibility: Works in both GUI and terminal Emacs environments
- Graceful fallbacks: Automatically falls back to standard Emacs features when optional packages (like
vterm) are unavailable
Based on official Cursor CLI documentation:
- Run
M-x cursor-agent-installto install - Ensure
~/.local/binis in your PATH - Restart Emacs after installation
- Run
M-x cursor-agent-loginto authenticate - Check status with
M-x cursor-agent-status - Verify setup with
M-x cursor-agent-verify-setup
The package will automatically fall back to shell-mode. For better experience, install vterm:
M-x package-install RET vterm RETTests are included in cursor-agent-test.el using ERT (Emacs Lisp Regression Testing). Run tests locally:
M-x load-file RET cursor-agent-test.el RET
M-x ert RET cursor-agent-test-.* RETOr from the command line:
emacs --batch -l ert -l cursor-agent.el -l cursor-agent-test.el \
--eval "(ert-run-tests-batch-and-exit 'cursor-agent-test-.* t)"Tests run automatically on GitHub Actions for all pushes and pull requests.
Contributions are welcome! Please feel free to submit a Pull Request.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
See LICENSE file for details.
- chocoelho - GitHub
- Based on Cursor CLI documentation
- Inspired by the need for better Emacs integration with AI tools
- This plugin was created using Cursor - an AI-powered code editor