> ## 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 |
| `comment` | Human-readable review comment, included when `codegenInstructions` is empty |

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

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

## 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 without prompts or writes. They 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/reference#code-handoff) returns newline-delimited JSON for agent workflows.

## What's next

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

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

  <Card title="CodeRabbit Skills" href="/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.