Cursor cli in nodejs

Describe the Bug

cannot find output in nodejs

Steps to Reproduce

const child = spawn('cursor-agent', ['-p', '--api-key', 'xxx', '"hello"', '-m', 'claude-4-sonnet'], {
    shell: true
  });
  let output = '';
  child.stdout.on('data', (data) => {
    const str = data.toString();
    output += str;
    console.log('stdout: ', str);
  });
  child.stderr.on('data', (data) => {
    const str = data.toString();
    output += str;
    console.log('stderr: ', str);
  });
  child.on('close', (code) => {
    console.log('close: ', code);
  });

  child.on('error', (err) => {
    console.error('error:', err);
  });

there no any console output in cmd.
if i remove apiKey

const child = spawn('cursor-agent', ['-p', '"hello"', '-m', 'claude-4-sonnet'], {
    shell: true
  });

I will get the output


            +i":;;
        [?+<l,",::;;;I
      {[]_~iI"":::;;;;II
  )){↗↗↗↗↗↗↗↗↗↗↗↗↗↗↗↗↗↗↗↗↗ll          …  Cursor Agent
  11{[#M##M##M#########*ppll
  11}[]-+############oppqqIl             Press any key to sign in...
  1}[]_+<il;,####bpqqqqwIIII
  []?_~<illi_++qqwwwwww;IIII
  ]?-+~>i~{??--wwwwwww;;;III
  -_+]>{{{}}[[[mmmmmm_<_:;;I
  r\\|||(()))))mmmm)1)111{?_
   t/\\\\\|||(|ZZZ||\\\/tf^
        ttttt/tZZfff^>
            ^^^O>>
              >>

Then i run this cmd in shell, it works

cursor-agent -p --api-key xxx -f "hello" -m claude-4-sonnet

i dont know how to use cursor cli in nodejs

Operating System

MacOS

Current Cursor Version (Menu → About Cursor → Copy)

Mac: Apple M1 Pro
cursor-agent -v
2025.08.09-d8191f3
node -v
v20.18.1

Does this stop you from using Cursor

Yes - Cursor is unusable

Thanks for reporting this. The issue might be that your API key authentication isn’t working properly in Node.js, causing the CLI to fail silently.

Please try these steps:

• First, update to the latest CLI version: cursor-agent update (your version is older than current)

• Verify your API key works directly in terminal:

cursor-agent -p --api-key xxx "hello" -m claude-4-sonnet

• If that fails, generate a new API key from your Cursor dashboard under Integrations > User API Keys, then try again.

• In your Node.js code, try using the environment variable approach instead:


const child = spawn('cursor-agent', ['-p', 'hello', '-m', 'claude-4-sonnet'], {     shell: true,     env: { ...process.env, CURSOR_API_KEY: 'xxx' } });

Please let us know if this still happens after these steps.

This topic was automatically closed 22 days after the last reply. New replies are no longer allowed.