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 ID | Vendor CLI | Auth command | Provider class |
|---|---|---|---|
claude-code | @anthropic-ai/claude-agent-sdk | claude setup-token (wrapped) | ClaudeCodeRuntimeProvider |
cursor | Cursor agent CLI / ACP | agent login (wrapped) | CursorRuntimeProvider |
codex | OpenAI Codex CLI | codex login (wrapped) | CodexRuntimeProvider |
antigravity | Antigravity 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 vendorsEach 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-20250514Verify the runtime is reachable
anvio runtime test claude-code
anvio runtime test codex
anvio runtime test antigravityOptional 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:
- Encrypted connection broker payload (
service: claude-code) CLAUDE_CODE_OAUTH_TOKENenvironment variable- 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-codeCursorRuntimeProvider 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 --cursorspec:
runtime:
providers:
cursor:
enabled: true
acp:
endpoint: http://localhost:8765CodexRuntimeProvider 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 codexAntigravityRuntimeProvider 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 --antigravityCLI 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 -> localFallback triggers on two conditions:
| Trigger | Behavior |
|---|---|
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 error | Fail 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 carolEach 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:
- Provision offline, mount workspace — run
anvio setup-tokenon a laptop/bastion with a browser, thenrsyncworkspace/connections/to the server. Recommended for production. - Environment variables — inject
CLAUDE_CODE_OAUTH_TOKEN/CODEX_ACCESS_TOKENvia a secrets manager. Single-tenant only. - Headless vendor CLI —
codex login --device-auth(device code flow),NO_OPEN_BROWSER=1 agent login(paste URL manually), or runclaude setup-tokenon a bastion and copy the token. localruntime + API key — simplest for Docker: skip vendor OAuth entirely, useruntime.fallback: localwithANTHROPIC_API_KEYset. No subscription quota, but no browser dependency either.- 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.
Last updated on