Skip to content

Cursor CLI

Cursor CLI 是同一套编程 Agent 的终端形态:交互会话,或给脚本 / CI 的 print 模式。二进制是 agent,不是 cursor,也不是 Origin CLI 的 origin

官方:CLI overviewInstallationUsingHeadless

CI 复制粘贴配方留在 Cookbook

先决条件

  • macOS、Linux、WSL 或 Windows PowerShell
  • 一个你愿意让它改的 git checkout
  • 脚本 / CI:Dashboard 里的 CURSOR_API_KEY

学习目标

读完本页你能:

  1. 装好 agent,交互跑一轮
  2. 和编辑器一样切换 Agent / Plan / Ask
  3. 无头用 -p,真正要写盘再加 --force
  4. & 交给 Cloud,并且不把 agentorigin 搞混

安装

bash
# macOS, Linux, WSL
curl https://cursor.com/install -fsS | bash

# Windows PowerShell
irm 'https://cursor.com/install?win32=true' | iex

agent --version

找不到 agent 就把 ~/.local/bin 加进 PATH(bash:~/.bashrc;zsh:~/.zshrc)。更新:agent update(默认会自动更新)。

交互模式

bash
agent
agent "refactor the auth module to use JWT tokens"

Agent 可以写、审、改代码。命令过来时你批准。

模式

和编辑器同一套。用斜杠命令、Shift+Tab--mode 切换。

模式干什么怎么开
Agent完整工具,做编码任务默认
Plan先设计;会问澄清问题Shift+Tab/plan--plan--mode=plan
Ask只读探索/ask--mode=ask

Debug Mode 是编辑器约束。不要编一个 CLI --mode=debug

会话附加能力(官方)

动作怎么做
交给 Cloud消息前加 &
以前的对话agent ls
最近一次agent resumeagent --continue
指定 idagent --resume="chat-id-here"
审 diffCtrl+R(再按 i 跟进)
换行Shift+Enter(tmux 里用 Ctrl+J
退出Ctrl+D 两次
@ 文件 / 文件夹和编辑器同一思路
压缩上下文/summarize/compress 是别名)
Worktreeagent --worktree "…"(名字可选;在 ~/.cursor/worktrees/ 下)
bash
# 会话中途 → Cloud Agent
& refactor the auth module and add comprehensive tests

之后在 cursor.com/agents 或手机上接着看。

沙箱:/sandbox--sandbox <mode>enabled / disabled)。设置会保留。Sudo:CLI 弹出遮罩密码框;模型看不到密码。

非交互 / CI

脚本和 CI 用 print 模式-p / --print)。

bash
export CURSOR_API_KEY=your_api_key_here

agent -p "find and fix performance issues" --model "gpt-5"
agent -p "review these changes for security issues" --output-format text

-p 会不会写文件?

脚本契约以专门的 Headless 页为准:

bash
# 只提议 — 不改文件
agent -p "Add JSDoc comments to this file"

# 不确认,直接落盘
agent -p --force "Refactor this code to use modern ES6+ syntax"

--force 才是写开关。HTML 版 Headless 还写了别名 --yolo。该页的 .md 快照只点名 --force

cli/using.md 仍写 “Cursor has full write access in non-interactive mode.” CI 请跟 Headless,要改磁盘就加 --force

脚本用 CURSOR_API_KEY 认证。输出:--output-format text-p 默认)、jsonstream-json

bash
agent -p --force --output-format text \
  "Review recent changes and write feedback to review.txt"

Rules、MCP、ACP

CLI 从 .cursor/rules 加载和编辑器同一套 rules。也会读根目录 AGENTS.mdCLAUDE.md

MCP 来自项目的 mcp.json(和编辑器同一批 server)。Cloud Agents 用 cursor.com/agents 上的团队 MCP 列表 — 来源不同。

ACP:agent acp 把 Cursor CLI 当成 ACP server,走 stdio(JSON-RPC)。JetBrains 也走 ACP — JetBrains

agentorigin

二进制产品教程
agent编程 Agent(本页)你在这里
origingit forge CLIOrigin

不要跑完 curl https://cursor.com/install 还指望得到 git 托管。那次安装是 agent

什么时候用

  • 人已经在 tmux / SSH / CI 任务里
  • 想要同一套 Rules / AGENTS.md,不想开 GUI
  • 需要 worktree(--worktree),别让 Agent 改当前 checkout

Tab、Inline Edit、Debug Mode 留在编辑器。Cloud Agents 适合笔记本该睡觉的时候。调用方是你自己的 TypeScript / Python 进程时用 SDK

常见陷阱

陷阱正确做法
终端里敲 cursor二进制是 agent
CI 里 agent -p 文件没变--force(Headless 页)
只信 using.md 的 “full write access”Headless + --force
指望 Debug Mode只有编辑器有
和 Origin CLI 搞混forge 是 origin
交给 Cloud 却忘了 && refactor …
以为用的是 Cloud 团队 MCPCLI 读的是项目 mcp.json

下一步

为前端工程师打造 · 基于 VitePress 构建