Cursor-agent --print doesn't exit after completing

Where does the bug appear (feature/product)?

Cursor CLI

Describe the Bug

cursor-agent --print returns output correctly but the process never exits. The worker subprocess continues running after the task completes, requiring manual termination or a timeout wrapper.

Steps to Reproduce

~/.local/bin/cursor-agent --print text “what is 2+2” --model grok

Expected Behavior

Process prints response and exits.

Operating System

Linux

Version Information

CLI Version 2026.01.28-fd13201
Model Grok
OS linux (x64)
Terminal konsole
Shell bash

Additional Information

  • Happens with all models tested (grok, gemini-3-flash)
  • --list-models works fine and exits normally
  • Did some strace debugging - looks like a worker subprocess keeps running after the main task completes

Happy to provide more details or logs if helpful.

Does this stop you from using Cursor

No - Cursor works, but with this issue

Hey, thanks for the detailed strace report, it’s really helpful.

This looks like a known type of issue with the CLI hanging. I’ve shared it with the team.

For now, the timeout workaround is the best option. If you spot anything interesting in the strace output, like which exact subprocess is stuck, drop it here, it could help with debugging.

Hi @ragnoroct!

Please give the latest version of the CLI a try and let us know if the problem persists.

I tested it a few times and it exits now. Still odd that it takes 30-55 seconds to do 2+2.

$ time agent -p 'what is 2+2?' --model composer-2-fast
**4**

beep boop 🤖

real    0m55.439s
user    0m3.070s
sys     0m1.078s
willy@workinux:~
$ time agent -p 'what is 2+2?' --model composer-2-fast
Four.

beep boop 🤖

real    0m36.261s
user    0m3.020s
sys     0m0.971s
willy@workinux:~
$ time agent --version
2026.05.05-84a231c

real    0m0.506s
user    0m0.611s
sys     0m0.077s

Following up on this thread with a CI/automation case that looked like the same
-p hangs with zero output” bug but had a different root cause and a workable fix.

Environment

Symptoms (0/N success over ~9 runs)

agent --print --plan --trust --output-format text --api-key "$KEY" "$BIG_PROMPT"
  • Wall time ~5–6 minutes (roughly constant regardless of PR size)
  • Exit code 0
  • Empty stdout and stderr
  • ss during failure showed ESTAB connections to GitHub/Azure — not stuck SYN-SENT

So this was not TerryZ’s TCP-retry pattern (we had working connections) and not
Silas’s “no TCP at all” IPC hang — though the user-visible symptom is identical:
silent freeze, then exit 0 with nothing printed.

What did work

Smoke tests on the same runner, same CLI, same API key:

Command Result
agent --list-models OK (~1s)
agent -p --trust "Say hello" OK (~12–25s) → Hello.
agent -p --plan --trust + tiny one-line prompt OK (~11s) → APPROVE

So basic headless --print works. Only the full review prompt failed.

Root cause (our case)

The prompt told the agent to:

  1. Read multiple repo files (CLAUDE.md, .github/codex/review-prompt.md, …)
  2. Run git diff origin/main...HEAD itself

In --print mode the agent appears unable to complete that self-service workflow
reliably — it runs for minutes and returns exit 0 with empty stdout.

Fix: pre-compute everything CI needs and embed it in the initial prompt:

  • git diff --stat + unified diff (capped at 120KB)
  • Inlined review rubric (no “read this file” instructions)
  • PR title/body

No file reads or shell git diff required from the agent.

Proof after fix

First successful automated review on the same PR that previously failed:

  • Prompt size: 85,930 bytes (diff 61,710 bytes)
  • agent -p --plan --trust54s, 3,924 bytes stdout, full code review posted

Workflow + scripts:

  • .github/workflows/cursor-review.yml
  • scripts/infra/github-runners/assemble-cursor-review-prompt.sh
  • scripts/infra/github-runners/run-cursor-review-agent.sh

Suggested improvements for the CLI (if this is a product bug)

  1. Non-zero exit or stderr when --print completes with zero output after tool/file work
  2. Progress indicator during long runs (even “reading files…” / “running git diff…”)
  3. Docs clarifying what --print can/can’t rely on (file access, shell, git) in headless CI

Minimal repro for others

# Works
agent -p --trust "Say hello"

# Often fails silently (exit 0, empty stdout) — ask agent to self-serve diff
agent -p --plan --trust "Read CLAUDE.md and run git diff origin/main...HEAD, then review."

# Works — embed diff in prompt
DIFF="$(git diff origin/main...HEAD)"
agent -p --plan --trust "Review this diff:\n$DIFF"

Happy to share more logs or the smoke-test script (cursor-agent-smoke.sh) if useful.