AAnvio
Runtimes & Model Routing

Vendor CLI Runtimes

Claude Code, Cursor, Codex, and Antigravity runtime providers — OAuth via the official vendor CLI, not API keys.

5 min read

Anvio supports four vendor-native coding-agent runtimes. Each authenticates through the official vendor CLI's own OAuth/login flow — not through an Anvio-managed API key — so agents run on subscription quota (Claude Pro/Max, ChatGPT Plus, Cursor session) instead of billing per-token API usage.

This design exists because Anthropic (and similarly other vendors) prohibit third-party products from hosting their own login UI or reselling subscription rate limits. Anvio delegates login entirely to the official CLI and only stores the resulting token locally, encrypted. See ADR 0009.

The four runtimes

Runtime IDVendor CLIAuth commandProvider class
claude-code@anthropic-ai/claude-agent-sdkclaude setup-token (wrapped)ClaudeCodeRuntimeProvider
cursorCursor agent CLI / ACPagent login (wrapped)CursorRuntimeProvider
codexOpenAI Codex CLIcodex login (wrapped)CodexRuntimeProvider
antigravityAntigravity CLI (agy)agy auth login (wrapped, auto-installs)AntigravityRuntimeProvider

All four are implemented — none of this is a stub. RuntimeFactory (packages/runtimes/src/runtime-factory.ts) instantiates all four unconditionally.

Unified login: anvio setup-token

Log in per vendor

anvio setup-token --claude
anvio setup-token --cursor
anvio setup-token --codex
anvio setup-token --antigravity
anvio setup-token --list       # show supported vendors

Each flag wraps the official CLI: claude setup-token, agent login, codex login, agy auth login respectively. Legacy alias: anvio connect login claude-code → anvio setup-token --claude.

Bind a runtime to an agent

# workspace/agents/architect.yaml
spec:
  runtime:
    provider: claude-code
    fallback: local        # or fallbacks: [cursor, codex, local] for a full chain
  model:
    provider: anthropic     # used only if fallback reaches `local`
    model: claude-sonnet-4-20250514

Verify the runtime is reachable

anvio runtime test claude-code
anvio runtime test codex
anvio runtime test antigravity

Optional flags across all vendors: --token TOKEN (claude/codex/antigravity/nous — paste a token directly instead of interactive login), --binary NAME (custom CLI path), --no-install (skip Antigravity's auto-install step).

Per-vendor notes

ClaudeCodeRuntimeProvider (packages/runtimes/src/claude-code/claude-code-runtime.ts) drives @anthropic-ai/claude-agent-sdk's query() function directly — it is a real SDK integration, not a subprocess wrapper.

Auth resolution order:

  1. Encrypted connection broker payload (service: claude-code)
  2. CLAUDE_CODE_OAUTH_TOKEN environment variable
  3. Interactive CLI cache (SDK fallback if the user already ran claude login)

isConfigured() returns true if any of these resolve. ANTHROPIC_API_KEY is never passed into the SDK subprocess env when OAuth mode is active — an API key present alongside OAuth would shadow the subscription auth and silently bill API credits instead.

anvio setup-token --claude
anvio setup-token --claude --user alice    # per-user, multi-tenant workspace
anvio runtime test claude-code

CursorRuntimeProvider uses the Cursor agent CLI (agent -p) by default, or the Agent Client Protocol (ACP) when ANVIO_ACP_ENDPOINT (or spec.runtime.providers.cursor.acp.endpoint) is set.

anvio setup-token --cursor
spec:
  runtime:
    providers:
      cursor:
        enabled: true
        acp:
          endpoint: http://localhost:8765

CodexRuntimeProvider runs codex exec with an isolated auth home, and strips OPENAI_API_KEY from the subprocess environment for the same reason Claude Code strips ANTHROPIC_API_KEY — OAuth via codex login writes to ~/.codex/auth.json, and Anvio's broker stores a snapshot of that file.

anvio setup-token --codex
anvio runtime test codex

AntigravityRuntimeProvider runs agy -p (Google Antigravity CLI). anvio setup-token --antigravity wraps agy auth login, auto-installing the CLI via Google's official install script if agy isn't found on PATH (skip with --no-install). Strips GEMINI_API_KEY; supports ANTIGRAVITY_TOKEN for CI/headless use.

anvio setup-token --antigravity

CLI reference: github.com/google-antigravity/antigravity-cli.

Runtime fallback chain

buildAgentRuntimeChain() (packages/runtimes/src/runtime-fallback-chain.ts) builds an ordered chain from spec.runtime.provider + spec.runtime.fallbacks (or the fallback: local shorthand for a single hop), always deduped and always ending in local if not already present:

spec:
  runtime:
    provider: claude-code
    fallbacks: [cursor, codex, local]   # claude-code -> cursor -> codex -> local

Fallback triggers on two conditions:

TriggerBehavior
Primary not configured (isConfigured() is false)Skip straight to the next runtime in the chain
Primary auth failure mid-run (OAuth expired, 401, "login required")Retry the next runtime in the chain
Any other errorFail immediately — no runtime-level retry

The auth-failure classifier is a single regex (isRuntimeFailoverRetryableMessage in runtime-fallback-chain.ts) matching patterns like oauth, 401, 403, token expired, login required, setup-token, API key shadows.

Per-user OAuth on one workspace

export ANVIO_CONNECTION_ENCRYPTION_KEY=your-secret
anvio setup-token --claude --user alice
anvio setup-token --codex  --user bob
anvio setup-token --antigravity --user carol

Each user's token is stored under a connection broker key scoped by channel:userId:service, so architect bound to claude-code can serve Alice on her Claude OAuth and Bob on his Codex OAuth from the same agent definition, as long as sessions carry the matching userId.

Docker, server, and headless OAuth

Vendor OAuth flows expect a browser, which most servers/containers don't have. The supported patterns, in order of recommendation:

  1. Provision offline, mount workspace — run anvio setup-token on a laptop/bastion with a browser, then rsync workspace/connections/ to the server. Recommended for production.
  2. Environment variables — inject CLAUDE_CODE_OAUTH_TOKEN / CODEX_ACCESS_TOKEN via a secrets manager. Single-tenant only.
  3. Headless vendor CLI — codex login --device-auth (device code flow), NO_OPEN_BROWSER=1 agent login (paste URL manually), or run claude setup-token on a bastion and copy the token.
  4. local runtime + API key — simplest for Docker: skip vendor OAuth entirely, use runtime.fallback: local with ANTHROPIC_API_KEY set. No subscription quota, but no browser dependency either.
  5. Mount vendor credential dirs (dev/staging only) — -v ${HOME}/.codex:/root/.codex:ro. Weak isolation, not for multi-tenant production.

Full walkthrough with docker-compose snippets: ADR 0009 — Docker, server, and headless OAuth.

Never commit ANVIO_CONNECTION_ENCRYPTION_KEY or OAuth tokens to git. Rotating the encryption key without a migration plan makes existing stored connections unreadable.

Edit on GitHub

Last updated on

On this page