Cursor CLI Passthrough
Spawn Cursor's agent in a PTY background session and relay its output and the user's inputs as a silent passthrough.
Spawning
CODEBLOCK0
- - Always set
workdir to the project directory the user wants to work in (not the OpenClaw workspace). - If the user doesn't specify a directory, ask before spawning.
- Note:
agent requires workspace trust on first run in a directory — relay the trust prompt and send the user's choice (e.g. a, w, or q) via process send-keys.
Relaying output
After spawning or sending input, poll for output:
CODEBLOCK1
- - Strip ANSI escape codes mentally, but relay the content faithfully and verbatim.
- Do not wrap output in code blocks or quote formatting.
- Do not add preamble, postamble, interpretation, or commentary — relay exactly what Cursor outputs.
- If you need to add context or a note, prefix that line with your name in brackets (e.g.
[YourName]) so it's clearly distinguished from Cursor's output. - Permission prompts: When Cursor shows a "Run this command?" or any approval dialog, relay it verbatim to the user and wait for their response. Never approve or deny on the user's behalf.
- After relaying the agent's response, append a single prompt line:
cursor @ <workdir> — use ~ in place of the user's home directory (e.g. ~/repos/myproject not /home/username/repos/myproject).
Sending user input
For single-line prompts:
CODEBLOCK2
For multi-line prompts:
CODEBLOCK3
Then submit with Enter:
CODEBLOCK4
For other special keys (arrow keys, Escape, etc.):
CODEBLOCK5
Use @filename or @directory/ in interactive prompts to add more context.
Ending the session
Send /quit or Ctrl+D (double-press):
CODEBLOCK6
Notes
- -
agent is Cursor's CLI binary. cursor-agent is a backward-compatible alias. - The binary must be on
PATH. If not found, check TOOLS.md for custom binary paths. - One session at a time is typical; use
process list to check for orphaned sessions.
Cursor CLI 透传
在PTY后台会话中启动Cursor的agent,并将其输出和用户输入作为静默透传进行中继。
启动
json
{ tool: exec, command: agent, pty: true, background: true, workdir: <项目目录>, yieldMs: 3000 }
- - 始终将workdir设置为用户想要工作的项目目录(而非OpenClaw工作区)。
- 如果用户未指定目录,请在启动前询问。
- 注意:agent在目录中首次运行时需要工作区信任——请中继信任提示,并通过process send-keys发送用户的选择(例如a、w或q)。
中继输出
在启动或发送输入后,轮询输出:
json
{ tool: process, action: poll, sessionId: , timeout: 15000 }
- - 在心理上剥离ANSI转义码,但忠实且逐字地中继内容。
- 不要将输出包裹在代码块或引用格式中。
- 不要添加前言、后记、解释或评论——完全按照Cursor输出的内容进行中继。
- 如果需要添加上下文或注释,请在该行前加上方括号中的您的名字(例如[您的名字]),以便与Cursor的输出清晰区分。
- 权限提示:当Cursor显示运行此命令?或任何批准对话框时,请逐字中继给用户并等待其响应。切勿代表用户批准或拒绝。
- 在中继agent的响应后,附加一行提示:cursor @ <工作目录>——使用~代替用户的主目录(例如~/repos/myproject而非/home/username/repos/myproject)。
发送用户输入
对于单行提示:
json
{ tool: process, action: submit, sessionId: , data: <文本> }
对于多行提示:
json
{ tool: process, action: paste, sessionId: , text: <文本> }
然后按回车提交:
json
{ tool: process, action: send-keys, sessionId: , keys: [Enter] }
对于其他特殊键(方向键、Escape等):
json
{ tool: process, action: send-keys, sessionId: , keys: [ArrowUp] }
在交互式提示中使用@文件名或@目录/来添加更多上下文。
结束会话
发送/quit或Ctrl+D(双击):
json
{ tool: process, action: submit, sessionId: , data: /quit }
备注
- - agent是Cursor的CLI二进制文件。cursor-agent是向后兼容的别名。
- 该二进制文件必须在PATH中。如果未找到,请检查TOOLS.md以获取自定义二进制路径。
- 通常一次只运行一个会话;使用process list检查是否有孤儿会话。