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

# CLI

> finalsay ask --wait: ask a person from any shell, and branch on the exit code.

Use the `finalsay` CLI when your agent or script runs shell commands: coding agents (Claude Code, Codex, Cursor, Aider),
CI jobs, git hooks, cron, deploy scripts. `finalsay ask` creates an approval and, with `--wait`, blocks until someone
answers in the mobile app or web dashboard. The **exit code** tells the caller what they decided.

```sh theme={"theme":{"light":"github-light","dark":"vesper"}}
finalsay ask "Deploy v2.3 to production?" \
  -c "3 commits since v2.2 (auth fix, two dependency bumps). Rollback: \`make rollback\`." \
  --wait && ./deploy.sh
```

## Install and sign in

```sh theme={"theme":{"light":"github-light","dark":"vesper"}}
npm install -g finalsay   # Node.js 20+
finalsay login            # paste a workspace API key, pick an agent
```

Or run it without installing: `npx finalsay ask …`. For CI and agents, skip `login` and set environment variables:

```sh theme={"theme":{"light":"github-light","dark":"vesper"}}
export FINALSAY_API_KEY=hitl_…   # workspace API key
export FINALSAY_AGENT_ID=…       # `finalsay agents` lists the ids your key can use
```

| Setting | Flag | Environment | Saved by `login` |
| - | - | - | - |
| API key | (none) | `FINALSAY_API_KEY` | yes |
| Agent ID | `-a`, `--agent` | `FINALSAY_AGENT_ID` | yes |
| API URL | `--api-url` | `FINALSAY_API_URL` | only if not the default (`https://api.finalsay-hitl.com`) |
| Config file | | `FINALSAY_CONFIG` | |

Flags override environment variables, which override the saved login. The login is saved to
`$XDG_CONFIG_HOME/finalsay/config.json` (usually `~/.config/finalsay/config.json`), readable only by you. There is
deliberately no flag for the API key, so it never lands in shell history. `login` needs an interactive terminal.

## Ask

```sh theme={"theme":{"light":"github-light","dark":"vesper"}}
git diff --stat main | finalsay ask "Merge this branch?" --context-file - \
  -o "Merge=merge" -o "Hold=hold" --wait --json
```

| Flag | Maps to | Notes |
| - | - | - |
| `<question>` | `question` | Required, up to 500 characters |
| `-c, --context <markdown>` / `--context-file <path\|->` | `context_markdown` | Required, up to 2500 characters. `-` reads stdin |
| `-o, --option <label[=value]>` | `options[]` | Repeat 1–4 times. The value defaults to the label in snake\_case, and values must be distinct. Without `-o`: **Approve** / **Reject** |
| `--summary <text>` | `notification_summary` | Push notification title, up to 120 characters |
| `--request-id <id>` | `request_id` | Idempotency key: retrying with the same id is safe |
| `--correlation-id <id>` | `correlation_id` | Your own run or ticket id, returned with the result |
| `--expires-in <seconds>` | `timeout.expires_in_seconds` | 30–86400. Default: the agent's setting |
| `--expire-instruction <text>` | `timeout.mode` + `predefined_instruction` | Return this instruction (up to 1000 characters) if nobody answers |
| `--callback-url <url>` | `callback.url` | Also POST the result to this URL. Callback secrets stay on the agent's Callback security tab |
| `-w, --wait` | | Block until answered |
| `--max-wait <seconds>` | | Stop waiting after this long (1 or more; implies `--wait`) |
| `--approve-value <value>` | | Which option exits 0. Default: the first option |
| `--json` | | Print JSON on stdout |

Limits are checked before anything is sent, with the same schema the API uses. A payload over a limit exits `2`.
Without `--wait`, `ask` prints the request ID and exits `0` once the approval is created.

## Other commands

| Command | What it does |
| - | - |
| `finalsay wait <request_id>` | Block until an existing approval is answered. Takes `--max-wait` and `--approve-label`. |
| `finalsay status <request_id>` | Check once. Takes `--approve-label`. |
| `finalsay agents` | List the agents your key can act as. |
| `finalsay login` | Save a key and default agent. Takes `--agent`. |
| `finalsay mcp` | Run a local MCP server over stdio for MCP clients. Takes `--agent`. See [MCP](https://docs.finalsay-hitl.com/integrations/mcp.md#local-server-stdio). |
| `finalsay help [command]`, `--version` | Help and version. |

Every command takes `--api-url`, and every command except `mcp` takes `--json`.

## Exit codes

| Code | Meaning |
| - | - |
| `0` | The approving option was chosen (the first option unless `--approve-value` / `--approve-label` is set). `ask` without `--wait` also exits 0. |
| `1` | Error: network, authentication, not found, rate limit, plan limit, idempotency conflict, server error |
| `2` | Usage error: bad flags, missing configuration, payload over a limit |
| `3` | A different option was chosen |
| `4` | The reviewer wrote their own answer (`custom_instruction`) |
| `5` | Expired with no answer |
| `6` | Still pending (`status`, or `--max-wait` reached) |
| `130` | Interrupted with Ctrl-C. The approval stays open; resume with `finalsay wait` |

These codes are stable. Scripts and hooks can rely on them.

## JSON output

With `--json`, `ask --wait`, `wait` and `status` print the [approval result](https://docs.finalsay-hitl.com/api-reference/approval-object.md#result)
plus two fields:

* `outcome`: `approved`, `other_option`, `custom_instruction`, `expired` or `pending`
* `exit_code`

For an expired approval with a fallback instruction, `custom_instruction` holds the fallback. Errors print
`{ "error", "message", "exit_code" }`.

## Waiting and polling

`--wait` polls every 2 seconds at first, backing off by 1.5× to every 15 seconds. It stops at the approval's
`expires_at` (plus 30 seconds for the server to mark it expired) or at `--max-wait`, whichever comes first. Network
errors, `429` and server errors are retried; it gives up after 10 errors in a row. Each request times out after 30
seconds.

Many agent shells time out long-running commands. Either run `finalsay ask --wait` in the background, or create
without `--wait` and call `finalsay wait <request_id>` later.

## Next

* [Claude Code and Codex](https://docs.finalsay-hitl.com/integrations/claude-code.md): the skill file, `AGENTS.md`, and a hook that gates risky
  commands.
* [CI and GitHub Actions](https://docs.finalsay-hitl.com/integrations/ci.md): gate a deploy job.


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