> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coderabbit.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Agent mode output and exit codes

> Read the structured NDJSON output of CodeRabbit CLI agent mode, handle incomplete reviews, and check process exit codes in scripts and coding agents.

Use agent mode when a coding agent or script consumes CodeRabbit CLI results. This page describes the output contract and exit codes. For the options of each command, see the [CLI command reference](/cli/reference).

## Review output

`cr review --agent` writes one JSON object per line to `stdout`. Read the stream line by line and handle events by their `type`.

Finding events use these fields:

| Field | Description |
| - | - |
| `type` | Always `finding` for review results |
| `severity` | One of: `critical`, `major`, `minor`, `trivial`, `info`, `none` |
| `fileName` | File path for the finding |
| `codegenInstructions` | Agent-oriented fix instructions |
| `suggestions` | Suggested fix commands or snippets |
| `title` | Human-readable finding title (CLI 0.9.0 or later) |
| `comment` | Human-readable review comment; CLI 0.9.0 or later retains it alongside `codegenInstructions` |
| `startLine`, `endLine` | Finding line range, when available (CLI 0.9.0 or later) |

In earlier versions, `comment` is included only when `codegenInstructions` is empty. The added fields do not change how existing consumers read fix instructions.

Other event types in the stream include `review_context`, `status`, `heartbeat`, `complete`, and `error`.

`heartbeat` events are periodic keep-alive signals — reset timeout timers on receipt and otherwise ignore them. For `finding` events, use `codegenInstructions` for agent fix logic and fall back to `comment` when it is absent.

For a [remote review](/cli/index#review-without-a-local-checkout), `review_context` includes `remote`, `currentBranch`, and `baseBranch` and omits `workingDirectory`.

### Duration and repeated reviews

In CLI 0.9.0 or later, `review_context.expectedDuration` tells the caller how long to wait. Allow at least 15 minutes or run the command in the background, and keep reading heartbeat events. If a signal interrupts an active review, the CLI attempts to emit an `error` record with `errorType: "interrupted"`, `elapsedSeconds`, and retry guidance before exiting.

When the server reuses an existing review, the `complete` event includes `reused: true`. Treat this as a reused result rather than proof that a new review ran.

After a rate limit with a known wait time, rerunning the command can return the same rate-limit error and remaining wait without reconnecting. The local wait is capped at 15 minutes. Wait for the reported time instead of retrying in a loop. Eligible usage-based reviews with `--use-credits` bypass this local wait; the flag still authorizes paid work under your organization's billing settings.

### Reviews with too many files

When the selected review scope is skipped because it contains too many files, the review fails with an `error` event. The event can include these optional, additive fields:

| Field | Description |
| - | - |
| `candidates` | Mutually exclusive narrower-scope suggestions computed from the submitted files. Suggestions can use `--committed`, `--uncommitted`, or up to five `--dir` scopes, and include an estimated local file count and a fit indicator relative to the server-reported limit. The estimate is intentionally conservative, so a candidate marked over the limit may still fit after server-side filtering. |
| `candidatesNote` | Guidance that accompanies the narrower-scope suggestions. |

These fields do not change the existing error contract, so integrations do not need to handle them. Candidates are alternatives, not an automatic partition of the full change set. The CLI does not select a candidate or retry the review. The user or agent must choose one suggestion and rerun the narrower command manually.

In plain mode, the same failure can print a **Narrower scopes found in this diff** block with concrete commands, estimated file counts, and fit indicators. The CLI does not increase the limit, split the review, or retry automatically; choose one command and rerun it manually.

### Reviews with no changes

When the selected review scope has no file changes, `cr review --agent` still emits the `review_context` event, then emits a `status` event with `status: "review_skipped"` and a `complete` event with `status: "review_skipped"`, `findings: 0`, and `message: "No changes detected"`. Plain mode prints a no-changes message and exits without starting a review.

### Failed or incomplete reviews

Starting with CLI 0.7.7, failed or incomplete reviews exit with code `1`. Treat the process exit code and completion outcome as part of the result; receiving findings does not prove that the whole review completed.

An agent `complete` event can still have `status: "review_completed"` when the review failed or missed files. Inspect its `outcome`, `message`, and `unreviewedFileCount` when present: `outcome: "failed"` or a positive `unreviewedFileCount` means the run was incomplete. `outcome: "completed_with_warnings"` with no files left to review does not by itself indicate failure.

For local reviews, findings received before a failure remain available, and the last successful incremental checkpoint is preserved. Retry after resolving the reported error. A no-change result with `status: "review_skipped"` remains a successful skip.

### Results that could not be saved locally

In CLI 0.9.0 or later, a `complete` event can include `persistence` with `status: "failed"` and an `errorCode`. Keep the findings from the current stream: they may not be available through `cr review findings`. Check local storage permissions and free space before the next review. A local save failure does not by itself mean the server review failed; continue to check the completion outcome and exit code.

## Exit codes

| Command | Exit code `1` means |
| - | - |
| [`cr review`](/cli/reference#review) | The review failed or was incomplete (CLI 0.7.7 or later), even if findings were already emitted |
| [`cr review findings --clear`](/cli/reference#review-findings) | Some stored findings could not be dismissed; the findings that were dismissed stay dismissed |
| [`cr doctor`](/cli/reference#doctor) | Any check failed; warnings are shown in the report but do not cause a non-zero exit code |

A review that is skipped because the selected scope has no changes is a successful run and does not exit with code `1`.

## Agent-friendly authentication

| Command | Description |
| - | - |
| [`cr auth login --agent`](/cli/reference#auth-login) | Browser-based OAuth login with structured JSON events for agents |
| [`cr auth logout --agent`](/cli/reference#auth-logout) | Log out with structured JSON events for agents |
| [`cr auth status --agent`](/cli/reference#auth-status) | Return authentication status as structured JSON |
| [`cr auth org --agent`](/cli/reference#auth-org) | Return organization data, or `workspace_billing` with `billingWorkspaceId` for workspace-based SSO, as structured JSON; requires an existing browser-based login |

`cr auth login --agent` applies to the browser-based OAuth login flow and is not used with `--self-hosted` or `--api-key` login.

For GitHub Actions and other non-interactive environments, use `cr auth login --api-key "<key>"` and follow the [Headless CLI integration](/cli/headless-cli-integration) guide.

## Structured output from other commands

Several other commands accept `--agent` for structured output. Most are described in the [CLI command reference](/cli/reference):

* [`cr config --agent`](/cli/reference#config) inspects repository configuration. See [agent-guided setup](/cli/index#agent-guided-setup).
* [`cr skills --agent`](/cli/reference#skills) previews skill installation for approval. See [CodeRabbit Skills](/cli/skills#set-up-skills-from-an-agent).
* [`cr usage --agent`](/cli/reference#usage) returns one usage event.
* [`cr pullrequest --agent`](/cli/reference#pullrequest) returns newline-delimited JSON for pull request output.
* [`cr code handoff --agent`](/cli/cloud-tasks#continue-a-local-session-in-the-cloud) returns newline-delimited JSON for agent workflows.
* With CLI 0.9.0 or later, the cloud task commands under `cr code`, such as `cr code ls`, `cr code new`, and `cr code resume`, return newline-delimited JSON. Pass `--agent` explicitly, and before `--plan` for `cr code new`, so that argument errors are also JSON. Several of these commands change state: `cr code new` starts a billed task, and `cr code push` pushes changes. See [drive tasks from scripts and coding agents](/cli/cloud-tasks#drive-tasks-from-scripts-and-coding-agents).

## What's next

<CardGroup cols={1}>
  <Card title="Headless CLI integration" href="/https/docs.coderabbit.ai/cli/headless-cli-integration" icon="workflow" horizontal>
    Authenticate non-interactively in GitHub Actions and other automation
  </Card>

  <Card title="CLI Command Reference" href="/https/docs.coderabbit.ai/cli/reference" icon="terminal" horizontal>
    Look up every command, option, and example generated from the CLI help output
  </Card>

  <Card title="CodeRabbit Skills" href="/https/docs.coderabbit.ai/cli/skills" icon="wand-sparkles" horizontal>
    Install skills that run CodeRabbit reviews from your coding agent
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.