# CLI reference

The `rastrata` command-line tool exposes every bookkeeping workflow in Rastrata as deterministic commands that output JSON or plain text. It is open source under MIT and built for Claude Code, Codex, opencode, and shell automation.

## Global flags and environment variables

Pass global flags before or after any subcommand:

| Flag | Environment variable | Description |
| --- | --- | --- |
| `--workspace SLUG` | `RASTRATA_WORKSPACE` | Target a connected workspace by alias, slug, ID, or name. |
| `--endpoint URL` | `RASTRATA_API_URL` | Override the API endpoint (`https://app.rastrata.com` or local `http://127.0.0.1:7278`). |
| `--book ID` | `RASTRATA_BOOK_ID` | Target book ID on a self-hosted service (default `local-book`). |
| `--format json\|text\|csv` | | Output format (`json` is default; `csv` applies to report exports). `--json` is shorthand for `--format json`. |
| `--input FILE\|-` | | Read JSON request payload from a file or stdin (`-`). |
| `--operation-id UUID` | | Explicit idempotency key for write operations. |
| `--as-of YYYY-MM-DD` | | Report valuation date. |
| `--revision N` | | Read a report as of a specific ledger revision. |
| `--help`, `-h` | | Show help for the CLI or a specific subcommand. |

Authentication resolves in order: `RASTRATA_TOKEN` (scoped agent token), `RASTRATA_OWNER_KEY_FILE` (local self-hosted service), or the workspace credential saved by `rastrata connect`.

> **Caution:** Never commit credentials or paste `RASTRATA_TOKEN` or `RASTRATA_STRIPE_KEY` into a chat prompt or git repository. Export environment variables in your shell before starting your agent.
## Exit codes

| Code | Meaning |
| --- | --- |
| `0` | Success. |
| `2` | Usage error, unknown flag, invalid input, or command unavailable in CLI-only install. |
| `3` | Business rule or verification gate failure (unbalanced entry, closed period, failed intake gate, service stopped). |
| `4` | Network, connection, or local request-journal failure. |
| `5` | Unresolved write operation after interruption. Run `rastrata operations resume OPERATION_ID` to check outcome safely. |

## Connecting and workspaces

| Command | Description |
| --- | --- |
| `rastrata connect CODE [--alias SLUG] [--name TEXT] [--agent claude\|codex\|opencode\|all\|none]` | Exchange a 10-minute workspace code for a 90-day scoped credential and write agent instructions. |
| `rastrata workspaces` | List connected workspaces and show the active workspace for the current directory. |
| `rastrata disconnect [--workspace SLUG\|ID] [--all]` | Remove saved workspace credentials from this machine. |
| `rastrata agent status` | Display active principal, granted permissions, and token expiration. |
| `rastrata agent init --agent claude\|codex\|opencode\|all` | Write or update Rastrata's agent runbook and guide in the current folder. |
| `rastrata agent guide [--topics] [--topic NAME]` | Print built-in bookkeeping workflows for the installed CLI version. |
| `rastrata version` | Print CLI and API contract version. |

## Transactions, rules, and imports

| Command | Description |
| --- | --- |
| `rastrata import FILE --account ID [--profile NAME] [--dry-run=true]` | Preview or import a CSV, XLSX, OFX, QFX, or QBO bank statement. |
| `rastrata inbox list` / `show` / `categorize` / `accept` / `post` / `exclude` | Inspect, categorize, accept, post, or exclude items in **For review**. |
| `rastrata inbox undo` | Reverse and return an imported transaction back to **For review**. |
| `rastrata inbox recategorize --journal=ID,ID --account=ID [--from-account=ID] [--reason=TEXT]` | Reclassify posted entries in bulk with an auditable reversal trail. |
| `rastrata rules list` / `create` / `test` / `delete` | Manage deterministic categorization rules for recurring merchants. |
| `rastrata drafts list` / `get ID` / `create` / `save` / `discard` | Create and manage unposted journal drafts. |
| `rastrata journal list` / `get ID` / `prepare` / `prepare-reverse` | Inspect posted entries, prepare commits, or prepare linked reversals. |
| `rastrata operations commit PLAN_ID PLAN_HASH` | Commit a prepared write plan atomically. |
| `rastrata operations requests` / `resume OPERATION_ID` | Inspect or safely resume interrupted write operations without duplicates. |

## Reconciliation, periods, and activity

| Command | Description |
| --- | --- |
| `rastrata reconcile start` / `select` / `show` / `complete` / `void` | Start, select lines, inspect, complete (requires $0.00 difference), or void account reconciliations. |
| `rastrata periods list` / `prepare` / `extend` / `year-end YEAR` | Inspect fiscal periods, lock closed months, or close a full fiscal year. |
| `rastrata changes [--since last-review\|last-close\|DATE]` | List chronological audit trail of human and agent changes. |
| `rastrata changes review` | Mark activity log reviewed up to the current revision (human owner/admin only). |

## Reports and taxes

| Command | Description |
| --- | --- |
| `rastrata reports profit-loss` / `balance-sheet` / `cash-flow` / `trial-balance` / `general-ledger` | Generate live statements in JSON, text, or CSV (`--from`, `--to`, `--as-of`, `--format`). |
| `rastrata tax worksheet --year YYYY [--form scheduleC\|form1120S\|form1065]` | Aggregate account totals by IRS form line. |
| `rastrata tax checks --year YYYY` | Run pre-filing readiness checks across reconciliations, unreviewed items, and unmapped accounts. |
| `rastrata tax vendors` / `tax vendor` / `tax accounts` | Track 1099 contractor totals, W-9 status, and reportable expense accounts. |
| `rastrata tax sales` | Summarize Stripe-reported and tracked sales tax liability. |
| `rastrata tax cpa-packet` / `tax pack` / `tax verify-pack` | Build and verify the year-end CPA archive. |
| `rastrata tax accountant` / `tax adjustments` | Import and review adjusting journal entries from your CPA. |

## Stripe, migration, and plugins

| Command | Description |
| --- | --- |
| `rastrata stripe configure` / `pull` / `sync` / `status` / `payouts` | Configure Stripe account roles, pull payouts with a local restricted key, and verify balance parity. |
| `rastrata intake scan` / `plan` / `recipe test` / `recipe save` / `verify` / `trial-balance` / `status` | Run agent-driven statement migrations with deterministic verification gates. |
| `rastrata xero chart` / `trial-balance` / `transactions` / `reconciled` / `tie-out` / `status` | Import Xero exports and run parallel period tie-outs. |
| `rastrata history status` / `preview` / `import` / `tie-out` | Import historical multi-year journals and verify against closing trial balances. |
| `rastrata opening review` / `plan` and `rastrata cutover set` / `show` / `checklist` | Record cutover dates, post opening balances, and verify cutover readiness. |
| `rastrata plugin init` / `test` / `search` / `list` | Scaffold, test, and discover MIT data-source plugins. |

## Self-hosted service management

Available when running the local self-hosted installation (`rastrata-service`):

| Command | Description |
| --- | --- |
| `rastrata start` / `stop` / `status` / `logs` / `open` | Manage the local service on `http://127.0.0.1:7278`, view logs, and open the web app. |
| `rastrata doctor` | Run health checks across service status, owner lock, disk space, and verified backups. |
| `rastrata backup create` / `verify` / `drill` / `folder PATH` | Create, replay-verify, drill-restore, or relocate local SQLite backups. |
| `rastrata restore BACKUP --to PATH` | Verify and restore an offline backup to a database file. |
| `rastrata tokens create` / `list` / `revoke` / `activity` | Manage local scoped agent tokens (`--preset read-only\|draft\|auto`). |

> **Tip:** Run `rastrata schema` or `rastrata help <command>` at any time to inspect the exact JSON request and response schema for your installed version.
