AnyRouter CLI
Launch Claude Code, Codex, and other coding agents through AnyRouter with one command.
anyr launches your coding agents through the AnyRouter gateway: one key, automatic failover, unified billing. It is a native binary (alias anyrouter), with no Node required. Source: github.com/anyrouter-dev/cli; product page.
curl -fsSL https://anyr.dev/cli.sh | bash
anyr auth login # browser, device code, or paste
anyr claude # Claude Code
anyr codex # Codex
anyr opencode # OpenCode
anyr grok # Grok BuildBinaries cover Linux (x86_64, arm64), macOS (Intel, Apple Silicon), and Windows x86_64. The older per-tool npm packages (@anyr/claude, @anyr/codex) are deprecated.
Install
The installer puts anyr in ~/.local/bin with an anyrouter alias. It checks the download against the release's checksums.txt, then runs anyr --version and prints the result, so you know the binary starts. It does not need sudo. If you run it with sudo anyway, it installs for your own user. If ~/.local/bin is not on your PATH, it prints the line to add.
curl -fsSL https://anyr.dev/cli.sh | bash # latest stable
curl -fsSL https://anyr.dev/cli.sh | bash -s -- --channel beta # newest beta
curl -fsSL https://anyr.dev/cli.sh | bash -s -- --version 0.1.43 # a specific version
curl -fsSL https://anyr.dev/cli.sh | bash -s -- --bin-dir ~/bin # another directoryIf the installer reports that anyr was killed on launch (macOS can do this to a replaced binary), remove the file and install again:
rm -f ~/.local/bin/anyr ~/.local/bin/anyrouter
curl -fsSL https://anyr.dev/cli.sh | bashIf it still fails, open an issue with your macOS version and the installer output.
Targets
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 (cursor, cline, windsurf) can't be launched from a terminal, so the CLI prints the base URL (https://anyrouter.dev/api/v1) and a $ANYROUTER_API_KEY placeholder to paste into the editor's OpenAI-compatible provider settings. Use a key from the Keys dashboard; the CLI never prints your key.
With no flags, a spawn target opens an interactive launcher (arrows to move, Enter to select, m model, q quit).
The CLI never edits a tool's config files. It sets the gateway URL and key only in the child process environment:
| 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 gets a custom AnyRouter provider via OPENCODE_CONFIG_CONTENT so context windows size correctly; see OpenCode setup. Use --dry-run to see what a launch sets. If you previously ran grok login, run grok logout first; an existing session overrides the gateway key.
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 if missing
anyr chat --model z-ai/glm-5.2 # streaming chat TUI (/help, /model, /clear, /exit)First run
With no saved config, a launcher or auth login signs you in. With a browser, the CLI opens anyrouter.dev and a key returns to the terminal. Over SSH, in CI, or if the handoff fails, it uses the device code flow. Force a path with --device, --paste, or --key sk-ar-... (Login with AnyRouter). Interactively you can also pick a default model and agent (--yes skips). Non-interactive runs never prompt: pass --key or set ANYROUTER_API_KEY.
All launchers share ~/.anyrouter/config.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_MODELCommands
anyr auth login | logout | status
anyr config # interactive TUI: key, credits, model
anyr config get # active config, secrets redacted
anyr config path # config file location
anyr config use work # switch profile
anyr setup # save a local profile
anyr usage # credits remaining, 24h spend + top models, lifetime used
anyr logs # recent requests (also <id>, sessions)
anyr transactions # credit ledger: top-ups, spend, refunds
anyr whoami # name, email, account, masked key, default model
anyr account list # multiple accounts (* = active)
anyr account use work # switch saved profiles
anyr keys list # * marks the key this machine uses
anyr byok providers # providers that accept your own keys (also add, test, rm)
anyr upgrade # install the latest GitHub Release
anyr upgrade --check --channel betaModels
anyr models # list ids for --model
anyr models --free # $0 models only
anyr models --type embedding # chat | embedding | decision
anyr models --owner nvidia --sort price # sort: price | context | new
anyr models --search glm
anyr models show z-ai/glm-4.7 # pricing per 1M tokens, context, modalities, providers
anyr models use <id> # persist default_modelA model counts as free when its platform price is $0; models you pay for through your own provider key never do. --json prints JSON.
Embeddings
anyr embed "hello world" # default model: dimensions + first 8 values
anyr embed --model <embedding-model-id> "hello"
anyr embed --file notes.txt # one input per line, one request
echo "hello" | anyr embed - # inputs from stdin
anyr embed --dimensions 256 "hello"
anyr embed --json hi | jq '.data[0].embedding | length'--json prints the full response for a vector store.
MCP in launched agents
anyr claude, codex, opencode, and grok connect the AnyRouter MCP gateway when Auto-connect in coding agents is on in the dashboard, using the session's own key. Turn it off with --no-mcp, anyr mcp auto off, or the dashboard. Pi has no MCP support.
Updates
About once a day a command checks for a release in the background, downloads it next to the binary, and verifies it against checksums.txt. The next run swaps it in and prints anyr updated 0.1.30 → 0.1.31. A running agent keeps its version. A beta build stays on beta and anyr never installs an older version. Errors are silent (anyr update --status shows the last one). For npm installs it prints the npm command instead. Auto-update stays off in CI (CI set), when output is not a terminal, with --json, and inside launched agents.
anyr update # update now
anyr update --check # show current and latest, install nothing
anyr update --status # last check, pending update, last error
anyr update --rollback # previous versionTurn it off with update: { auto: false } in ~/.anyrouter/config.yaml, or ANYR_NO_AUTO_UPDATE=1 for one shell.
AnyRouter routes requests to third-party models. Models and outputs are provided as is, with no warranty; you use them at your own risk. Disclaimer