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

**URL:** <https://forum.cursor.com/t/cursor-agent-print-doesnt-exit-after-completing/150296>\
**Category:** Bug Reports\
**Tags:** terminal, cli\
**Created:** [January 29, 2026, 5:21pm UTC](https://forum.cursor.com/t/cursor-agent-print-doesnt-exit-after-completing/150296 "2026-01-29T17:21:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ragnoroct](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/ragnoroct/32/83937_2.png) [@ragnoroct](https://forum.cursor.com/u/ragnoroct)\
**Post date:** [January 29, 2026, 5:21pm UTC](https://forum.cursor.com/t/cursor-agent-print-doesnt-exit-after-completing/150296/1 "2026-01-29T17:21:10Z")

</div>

### 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

---

<div class="post-metadata">

**Author:** ![deanrie](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/deanrie/32/1263_2.png) [@deanrie](https://forum.cursor.com/u/deanrie)\
**Post date:** [January 30, 2026, 10:44am UTC](https://forum.cursor.com/t/cursor-agent-print-doesnt-exit-after-completing/150296/3 "2026-01-30T10:44:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/system/32/99069_2.png) [@system](https://forum.cursor.com/u/system)\
**Post date:** [February 21, 2026, 10:45am UTC](https://forum.cursor.com/t/cursor-agent-print-doesnt-exit-after-completing/150296/4 "2026-02-21T10:45:36Z")

</div>

Closed on February 21, 2026, 10:45am UTC

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/colin/32/90452_2.png) [@Colin](https://forum.cursor.com/u/Colin)\
**Post date:** [May 5, 2026, 10:32am UTC](https://forum.cursor.com/t/cursor-agent-print-doesnt-exit-after-completing/150296/9 "2026-05-05T10:32:10Z")

</div>

Opened on May 5, 2026, 10:32am UTC



---

<div class="post-metadata">

**Author:** ![Colin](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/colin/32/90452_2.png) [@Colin](https://forum.cursor.com/u/Colin)\
**Post date:** [May 5, 2026, 10:32am UTC](https://forum.cursor.com/t/cursor-agent-print-doesnt-exit-after-completing/150296/10 "2026-05-05T10:32:41Z")

</div>

Hi @ragnoroct!

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

---

<div class="post-metadata">

**Author:** ![ragnoroct](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/ragnoroct/32/83937_2.png) [@ragnoroct](https://forum.cursor.com/u/ragnoroct)\
**Post date:** [May 5, 2026, 10:01pm UTC](https://forum.cursor.com/t/cursor-agent-print-doesnt-exit-after-completing/150296/11 "2026-05-05T22:01:04Z")

</div>

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

```bash
$ 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

```

---

<div class="post-metadata">

**Author:** ![Corey\_Szopinski](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/corey_szopinski/32/113952_2.png) [@Corey\_Szopinski](https://forum.cursor.com/u/Corey_Szopinski)\
**Post date:** [July 8, 2026, 11:18pm UTC](https://forum.cursor.com/t/cursor-agent-print-doesnt-exit-after-completing/150296/12 "2026-07-08T23:18:16Z")

</div>

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

- **CLI:** `2026.07.08-0c04a8a` (installer on 2026-07-08)
- **Host:** self-hosted GitHub Actions runner, Linux ARM64, Docker
- **Use case:** automated PR review via `agent --print --plan --trust` in GitHub Actions
- **Repo (public workflow):** [https://github.com/core-industries-com/core-openclaw-docker](https://github.com/core-industries-com/core-openclaw-docker)

### Symptoms (0/N success over ~9 runs)

```bash
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 --trust` → **54s** , **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

```bash
# 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.
