Skip to content

AnyRouter CLI

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

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.

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.

Prefer the product page for copy-paste commands and a launcher overview. This doc is the full reference.

Aliases

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

anyr claude
anyrouter claude
ar claude

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:

TargetTool
claude (alias cc)Claude Code
codexCodex
grokGrok Build
opencodeopencode
piPi
pool (alias poolside)Poolside

Editor targets can't be launched from a terminal, so the CLI prints a copy-paste config block (base URL + key) to drop into the editor's settings:

TargetEditor
cursorCursor
clineCline
windsurfWindsurf

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:

▲ 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

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:

ToolBase URL envAuth envModel env
Claude CodeANTHROPIC_BASE_URLANTHROPIC_AUTH_TOKENANTHROPIC_MODEL
CodexOPENAI_BASE_URLOPENAI_API_KEYOPENAI_MODEL
Grok BuildGROK_MODELS_BASE_URLGROK_CODE_XAI_API_KEYpick in-CLI with Ctrl+M
Gemini CLIGOOGLE_GEMINI_BASE_URLGEMINI_API_KEYGEMINI_MODEL
OpenCodeOPENCODE_CONFIG_CONTENTOPENAI_API_KEYinline 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.

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

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 — Linux (x86_64, arm64), macOS (Intel, Apple Silicon), and Windows x86_64. No Node required.

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.

Source: 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:

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.

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.

Your profile is saved

Config is written to ~/.anyrouter/config.yaml (key on the macOS keychain when available) and reused automatically next time.

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

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:

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:

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 guide for details.