# Ask from the CLI

> Authenticate for AI, ask about selected repositories and control output, continuation and cancellation.

Source: https://docs.corfedo.ai/connect/cli/ask/

`corfedo ask` sends one message to Corfedo AI. The connection needs both **Ask Corfedo AI** and **Search and read code**, which `auth login` requests. If you cleared either on the **Authorize** page, `ask` exits with `missing_scope`.

```sh
corfedo auth login --api https://corfedo.example.com/
corfedo ask "How are search requests routed?" --repo acme/search
corfedo ask "Which modules call that code?" --continue
```

Use your workspace URL in place of the example. To sign in again to an existing profile, pass `--profile NAME --replace`.

An API key with **Ask Corfedo AI** also works with a CLI profile. Corfedo AI answers only while an administrator has turned it on for the API. See [Request access to Corfedo AI](https://docs.corfedo.ai/connect/authentication/#request-access-to-corfedo-ai).

## Select a conversation and sources

```sh
corfedo ask "Explain the next step" --conversation 11111111-1111-4111-8111-111111111111
corfedo ask "Explain indexing" --repo acme/search --repo 'acme/web-*'
```

`--continue` uses the last conversation remembered for the selected CLI profile. It cannot be combined with `--conversation`. A CLI profile with no remembered conversation reports `no_previous_conversation`.

Repeat `--repo` to restrict sources by name or glob. Quote globs to keep your shell from expanding them. Corfedo AI answers the CLI with the AI profile chosen for the API, see [AI profiles](https://docs.corfedo.ai/connect/api/ai/profiles/). `--profile NAME` picks the CLI connection, not the AI profile.

## Output

| Option | Output |
| --- | --- |
| Default text | Provisional progress on a terminal, replaced by the final answer |
| `--json` or `--format jsonl` | Events as JSON lines, followed by a `result` record |
| `--format json` | Only the result envelope |
| `--no-stream` | Wait without streaming progress |

When output is redirected, only the answer is printed. JSON results retain the answer, rendered citations, revisions, outcome and usage.

```sh
corfedo ask "Where is request validation?" --json
corfedo ask "Summarize validation" --format json --no-stream
```

## Timeouts and cancellation

`--timeout` limits each request, not the whole answer. A long answer can end with `reauthorization_required` when the sign-in can no longer be renewed. Sign in again with `--replace`.

The first Ctrl+C cancels the answer and exits 130. A second exits at once.

## Exit codes

| Code | Meaning |
| --- | --- |
| 0 | Completed answer |
| 7 | Answer cut short by the run's budget, time or cost limit |
| 11 | Run ended in failure |
| 130 | Cancelled |
| 2 | Usage error or conflict, including `conversation_busy`, `client_message_conflict`, `other_source`, `profile_unavailable` or an ambiguous repository |
| 3 | Sign in again (`authentication_required`, `reauthorization_required`) |
| 4 | Missing permission (`missing_scope`), named in the message, or Corfedo AI turned off for the CLI (`permission_denied`) |
| 5 | Repository not found |
| 6 | Monthly AI spending limit reached, or the answer stream failed |

`--allow-partial` changes a limited outcome's exit 7 to 0 and preserves the outcome in output. `spending_limit_reached` reports the limit reset time. Repository resolution errors include candidate names. See [conversation management](https://docs.corfedo.ai/connect/cli/conversations/) to inspect previous answers.
