# AnyRouter CLI

> Launch Claude Code, Codex, and other coding agents through AnyRouter with one command — one key, automatic failover, unified billing.


# AnyRouter CLI

Run your coding agents through the AnyRouter gateway with a single command — one key fronts every provider, with automatic failover and unified billing. Install the native `anyr` binary (aliases `anyrouter`, `ar`) with no Node required; first run still configures you once, and every run after that goes straight into the tool.

```bash
curl -fsSL https://anyrouter.dev/setup.sh | bash
anyr claude     # Claude Code
anyr codex      # Codex
anyr opencode   # OpenCode
anyr grok       # Grok Build
```

The binary is `anyr` (short alias `ar`). Prefer `anyr` in docs and scripts; `ar` is fine in short examples.

:::tip
Prefer the [product page](https://anyrouter.dev/cli) for copy-paste commands and a launcher overview. This doc is the full reference.
:::

::::cards

:::card{href="#targets" icon="🎯"}
**Targets** — Every tool you can launch or configure through the CLI.
:::

:::card{href="#first-run" icon="🔑"}
**First run** — Browser sign-in by default; device code on SSH.
:::

:::card{href="/cli/claude-code" icon="🤖"}
**Claude Code** — One command or manual env vars.
:::

:::card{href="/cli/opencode" icon="📂"}
**OpenCode** — One command or `opencode.json` provider.
:::

:::card{href="/guides/grok-bot-herdr-anyr" icon="🖥️"}
**Grok Bot + Herdr** — Fleet coding with Anyr CLI when cloud is blocked.
:::

:::card{href="/hub" icon="📦"}
**Skills & Knowledge Hub** — Sync skills and plugins into a session.
:::

::::

## Aliases

`setup.sh` installs several names for the same binary — use whichever reads best:

```bash
anyr claude
anyrouter claude
ar claude
```

:::note
Older per-tool npm packages (`@anyr/claude`, `@anyr/codex`, and similar) are deprecated. Prefer `anyr <tool>` from the native install above.
:::

## Targets

Run `anyr <target>`. There are two kinds.

**Spawn targets** launch the tool as a child process pointed at the gateway:

| Target | Tool |
|---|---|
| `claude` (alias `cc`) | Claude Code |
| `codex` | Codex |
| `grok` | Grok Build |
| `opencode` | opencode |
| `pi` | Pi |
| `pool` (alias `poolside`) | Poolside |

**Editor targets** can't be launched from a terminal, so the CLI prints a copy-paste block for the editor's OpenAI-compatible provider settings: the base URL (`https://anyrouter.dev/api/v1`) and a `$ANYROUTER_API_KEY` placeholder. Replace the placeholder with your `sk-ar-` key from the [Keys dashboard](https://anyrouter.dev/dashboard/keys) — the CLI never prints your key:

| Target | Editor |
|---|---|
| `cursor` | Cursor |
| `cline` | Cline |
| `windsurf` | Windsurf |

The CLI never edits a tool's own config files or stores credentials inside them. For spawn targets it sets the gateway base URL and auth token **only in the environment of the child process it launches** — quit the tool and nothing about your global setup has changed.

## What you see

Run a spawn target with no flags and the CLI shows an interactive launcher:

```text
▲ AnyRouter  v0.2.x
  account default · sk-ar-v1-ab…yz · render sync-gpu

  [ Claude Code ]  Codex  Grok Build  OpenCode  Poolside  Chat

  ────────────────────────────────────────
    Model            auto
    Effort           —
    Preset           @preset/coding-stack
    API key          sk-ar-v1-ab…yz
  ────────────────────────────────────────
  ◆ ▶  Launch Claude Code  ↵  ‹ ›
     Full info

  ↑↓ move  ←→ agent  ↵ select  m model  ? help  q quit
```

Use arrow keys to navigate and Enter to select. Press `x` or `q` to exit without launching. GPU-class terminals (Kitty, Ghostty, WezTerm, iTerm) redraw without flicker.

## Chat

```bash
anyr chat
anyr chat --model z-ai/glm-5.2
```

Opens a streaming chat TUI against the gateway. Slash commands: `/help`, `/model [id]`, `/clear`, `/exit`. Esc clears the input; Ctrl-C quits.

## What it does

The AnyRouter CLI is a thin launcher. It never changes how your tools work — it just injects the right environment so each one talks to AnyRouter:

| Tool | Base URL env | Auth env | Model env |
|---|---|---|---|
| Claude Code | `ANTHROPIC_BASE_URL` | `ANTHROPIC_AUTH_TOKEN` | `ANTHROPIC_MODEL` |
| Codex | `OPENAI_BASE_URL` | `OPENAI_API_KEY` | `OPENAI_MODEL` |
| Grok Build | `GROK_MODELS_BASE_URL` | `GROK_CODE_XAI_API_KEY` | pick in-CLI with `Ctrl+M` |
| Gemini CLI | `GOOGLE_GEMINI_BASE_URL` | `GEMINI_API_KEY` | `GEMINI_MODEL` |
| OpenCode | `OPENCODE_CONFIG_CONTENT` | `OPENAI_API_KEY` | inline `model` |

OpenCode does not rely on flat `OPENAI_BASE_URL` / `OPENAI_MODEL` — the CLI injects a custom AnyRouter provider via `OPENCODE_CONFIG_CONTENT` so context windows size correctly. `OPENAI_API_KEY` stays set so `{env:OPENAI_API_KEY}` in that config resolves. See [OpenCode setup](/cli/opencode).

Use `--dry-run` to see exactly what gets set before launching.

:::note
**Grok Build** reads its base URL from `GROK_MODELS_BASE_URL` and has no model env var — choose a model from the in-session picker (`Ctrl+M`), which lists the full AnyRouter catalog. If you previously ran `grok login`, run `grok logout` first; an existing session takes precedence over the gateway key.
:::

## Install

Primary path is a native Rust binary from public [GitHub Releases](https://github.com/anyrouter-dev/cli/releases) — Linux (x86_64, arm64), macOS (Intel, Apple Silicon), and Windows x86_64. No Node required.

```bash
curl -fsSL https://anyrouter.dev/setup.sh | bash
anyr auth login            # browser, device code, or paste (`login` still works)
anyr claude                # launch Claude Code through the gateway
anyr claude --yolo --model anyrouter/auto[1m]   # auto-route ≥1M context
anyr claude --model anyrouter/auto[500k]        # auto-route ≥500k context
anyr claude --install --ok # install Claude Code first if it is missing
anyr upgrade               # pull the latest GitHub Release
anyr upgrade --check --channel beta
```

Install and docs: [anyrouter.dev/cli](https://anyrouter.dev/cli).

Source: [github.com/anyrouter-dev/cli](https://github.com/anyrouter-dev/cli). Do not auto-merge release-please PRs on that repo.

## First run

The first time you run a launcher or `auth login` with no saved config, the CLI signs you in automatically — no multi-option menu:

::::steps

:::step{title="Sign in"}
With a browser, the CLI opens anyrouter.dev, you approve, and a key is returned to the terminal. Over SSH, in CI, or if the browser handoff fails, it switches to the **device code** flow. Force a path with `--device`, `--paste`, or `--key sk-ar-...` — see [Login with AnyRouter](/cli/login).
:::

:::step{title="Optional defaults"}
Interactively, you can pick a **default model** (top-ranked catalog first) and a **default coding agent**. Pass `--yes` to skip. Choices are saved under your profile.
:::

:::step{title="Your profile is saved"}
Config is written to `~/.anyrouter/config.yaml` (key on the macOS keychain when available) and reused automatically next time.
:::

::::

:::note
Non-interactive environments (CI, no TTY) never prompt — pass `--key sk-ar-...` or set `ANYROUTER_API_KEY`. Use `--device` / `--device-code` for headless sign-in when a human can approve a code on another device.
:::

## Shared config

All launchers share `~/.anyrouter/config.yaml`, so you log in once and every tool reuses the same key. (A profile from an older CLI at `~/.config/anyrouter/config.yaml` is migrated forward automatically on first run.)

```yaml
active_profile: default
profiles:
  default:
    base_url: https://anyrouter.dev/api
    pinned_preset: "@preset/coding-stack"
    default_model: auto
    timeout_ms: 3000000
tools:
  claude:
    command: claude
    base_url_env: ANTHROPIC_BASE_URL
    auth_env: ANTHROPIC_AUTH_TOKEN
    model_env: ANTHROPIC_MODEL
  codex:
    command: codex
    base_url_env: OPENAI_BASE_URL
    auth_env: OPENAI_API_KEY
    model_env: OPENAI_MODEL
  grok:
    command: grok
    base_url_env: GROK_MODELS_BASE_URL
    auth_env: GROK_CODE_XAI_API_KEY
```

## Management commands

Beyond the launch targets, the CLI has a handful of management commands:

```bash
anyr auth login         # sign in (browser → device code fallback)
anyr auth logout
anyr auth status
anyr config             # interactive TUI: key, credits, model
anyr usage              # credits remaining, 24h spend + top models, lifetime used
anyr logs               # recent requests: status, model, tokens, cost, latency
anyr transactions       # credit ledger: top-ups, spend, bonuses
anyr whoami             # active account + masked credentials
anyr account list       # multiple accounts (* = active)
anyr account use work   # switch saved profiles
anyr keys list          # switch with: anyr keys use
anyr models             # list catalog model ids for --model
anyr models use <id>    # persist default_model
anyr upgrade            # install the latest GitHub Release
anyr audit              # effective config, key storage, injected env (redacted), launch history
anyr setup              # save a local profile (same auto sign-in)
anyr config get         # show the active config (secrets redacted)
anyr config path        # print the config file location
anyr config use work    # switch to the "work" profile
anyr skills sync        # sync your Skills & Knowledge Hub locally
```

## Skills & Knowledge Hub

`anyr skills` downloads the skills, knowledge, and plugins from the hubs your account or org can see into `~/.anyrouter/hubs/<slug>/{skills,plugins}`. Load one at launch with `--hub`:

```bash
anyr skills list        # hubs + items available to you
anyr skills sync        # sync every hub you can see
anyr claude --hub myhub # launch Claude Code with that hub loaded
```

When you pass `--hub`, the CLI loads the hub via `claude --plugin-dir` — its skills plus any plugins — without touching your own `~/.claude/skills`. See the [Skills & Knowledge Hub](/hub) guide for details.

## Related

- [Claude Code setup](/cli/claude-code) — one command or manual env vars
- [Codex setup](/cli/codex) — one command or manual env vars
- [OpenCode setup](/cli/opencode) — one command or `opencode.json` provider
- [Grok Bot, Herdr, and Anyr CLI](/guides/grok-bot-herdr-anyr) — fleet coding with Herdr spaces
- [Configuration reference](/cli/configuration) — `anyrouter.yaml` fields, JSON schema, profiles
- [Login with AnyRouter](/cli/login) — auto browser sign-in, device code, `--paste` / `--key`
- [Grok Build](https://docs.x.ai/build/overview) — install with `curl -fsSL https://x.ai/cli/install.sh | bash`, then `anyr grok`
- [Skills & Knowledge Hub](/hub) — sync skills and plugins into any session
