Skip to main content

cli-relay

CI PyPI Python License

One worker interface over several coding-agent CLIs, with automatic fallback when a subscription hits its limit.

Русская версия

You pay for Claude, ChatGPT and Google subscriptions, and each comes with its own agent CLI and its own usage window. cli-relay runs a task on the first provider that can take it. If that provider runs out of quota mid-task, the relay hands the work to the next one with a briefing on what was already done.

cli-relay run "fix the failing test in tests/test_api.py" --cwd ~/code/app --permission edit

[cli-relay] claude started (claude-opus-5-5)
...
[cli-relay] claude failed [rate_limit]: You've hit your limit · resets 3pm
[cli-relay] switching claude -> antigravity (rate_limit)
[cli-relay] antigravity started
...
[cli-relay] done by antigravity

Why

  • The official CLIs, unmodified. cli-relay launches claude, agy and codex exactly as you would, under your own login. It never extracts, proxies or reuses OAuth tokens. You keep each tool's own permissions, hooks, CLAUDE.md / AGENTS.md, skills and MCP servers.
  • Limit-aware. Claude Code reports its five-hour and weekly windows in its event stream. cli-relay records them and skips a provider before it fails when a window is nearly used up. A provider that failed on a limit is skipped until its reset time.
  • Handoff, not restart. When it switches providers mid-task, the next agent gets the original task, the actions already taken and the last output. It is also told to check git status / git diff before continuing.
  • One event stream. Every provider is normalised to the same events (started, text_delta, tool_activity, quota_info, completed, failed, plus the relay's skipped / waiting / switched). Use --format ndjson to drive it from another program, such as a voice assistant.
  • MCP server. cli-relay mcp exposes relay_run and relay_status, so any MCP client can delegate work and get fallback for free.
  • Small and dependency-free. The core uses only the Python standard library. That matters for a tool that runs next to all your credentials.

Providers

Type CLI / endpoint Status Session resume Quota telemetry
claude Claude Code claude -p --output-format stream-json verified live --resume five-hour / weekly windows
antigravity Google Antigravity agy -p --output-format stream-json verified live --conversation from error text
codex OpenAI Codex codex exec --json (also finds the copy bundled with the Codex desktop app on Windows) command layout and limit path verified live on 0.167; success path from docs exec resume from error text, incl. "try again at 11:05 AM"
openai any OpenAI-compatible /chat/completions (OpenRouter, vLLM, Ollama, LM Studio…) tested with a local server — HTTP 429 + Retry-After

The openai type is a text-only fallback: it has no tools and cannot edit files.

Install

pipx install cli-relay            # or: uv tool install cli-relay
pipx install "cli-relay[mcp]"     # with the MCP server

Requires Python 3.11+. Install and log in to the agent CLIs you want to use first.

Usage

cli-relay status                                   # what is installed / limited
cli-relay run "explain src/auth.py"                # read-only by default
cli-relay run - < task.md --cwd ./repo --permission edit
cli-relay run "continue" --resume claude=SESSION_ID
cli-relay run "..." --providers antigravity,claude --format ndjson
cli-relay reset [provider]                         # forget recorded limits

Permissions

--permission is mapped to each CLI's own permission system. Non-interactive runs never wait for a prompt: anything that would ask is denied.

--permission Claude Code Antigravity Codex
read_only (default) --permission-mode dontAsk --mode plan --sandbox read-only
edit --permission-mode acceptEdits --mode accept-edits --sandbox workspace-write
full --permission-mode auto --mode auto workspace-write + --approve-for-me

A provider's permission setting is an upper bound, so a task never gets more than that. cli-relay never uses "skip all permission checks" flags.

Configuration

cli-relay looks for its config file in this order:

  1. --config PATH
  2. $CLI_RELAY_CONFIG
  3. ./cli-relay.toml
  4. %APPDATA%\cli-relay\config.toml on Windows, ~/.config/cli-relay/config.toml elsewhere

Without a file the chain is claude → antigravity → codex. See examples/cli-relay.toml:

order = ["claude", "antigravity", "codex", "openrouter", "local"]

[relay]
wait_if_reset_within_s = 900      # wait for a provider that resets within 15 min
skip_above_utilization = 0.97     # skip Claude when a usage window is ≥ 97 %
default_cooldown_s = 1800         # when a limit error carries no reset time
write_handoff_file = false        # also write HANDOFF.md into --cwd on a switch

[providers.claude]
model = "opus"
permission = "edit"               # upper bound for this provider

[providers.openrouter]
type = "openai"
base_url = "https://openrouter.ai/api/v1"
model = "vendor/model-id"          # any OpenRouter model id
api_key_env = "OPENROUTER_API_KEY"

[providers.local]
type = "openai"
base_url = "http://127.0.0.1:8000/v1"   # vLLM / Ollama / LM Studio
model = "your-served-model-name"

Recorded limits live in %LOCALAPPDATA%\cli-relay\state.json on Windows and ~/.local/state/cli-relay/state.json elsewhere. Override the path with $CLI_RELAY_STATE.

As an MCP server

claude mcp add cli-relay -- cli-relay mcp

The server exposes two tools:

  • relay_run(prompt, cwd?, providers?, permission?) returns {ok, provider, text, session_id, switches, skipped}.
  • relay_status() returns installed providers and their known limits.

By default an MCP client can only request read_only work, whatever it asks for. Otherwise a sandboxed agent could escalate by delegating to another one. To allow more, set this in the config:

[mcp]
max_permission = "edit"

As a library

import asyncio
from cli_relay import Relay, Task, TextDelta, Completed
from cli_relay.config import load

async def main() -> None:
    cfg = load()
    relay = Relay(cfg.adapters(), cfg.quota(), cfg.policy)
    async for event in relay.run(Task(prompt="summarise README.md")):
        if isinstance(event, TextDelta):
            print(event.text, end="")
        elif isinstance(event, Completed):
            print(f"\n-- by {event.provider}")

asyncio.run(main())

Terms of service

cli-relay is meant for your own subscriptions on your own machine. It runs each vendor's official CLI as a normal user would, and the vendors' terms still apply. For unattended automation, the vendors recommend API keys over subscription logins. Do not use cli-relay to share one subscription between several people.

Security notes

  • Agent processes are started from an argument list, never through a shell.
  • On Windows, claude and codex are npm .cmd shims, which cmd.exe re-parses. Prompts and system prompts are therefore always sent through stdin or a temp file. cli-relay refuses to put cmd.exe metacharacters on such a command line.
  • Corrupted or interleaved NDJSON lines are salvaged rather than crashing a long run.

See SECURITY.md for how to report a vulnerability.

Roadmap

  • Voice and push approvals for permission prompts (Claude Code PermissionRequest hook, Codex app-server approvals)
  • Codex app-server adapter with first-class rate-limit telemetry
  • Git worktree per task with automatic WIP checkpoints
  • Same-harness fallback (Claude Code against an Anthropic-compatible endpoint)

License

Apache-2.0

Metadata

Release files for cli-relay 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cli-relay 0.1.1
File Size Uploaded Provenance Actions
cli_relay-0.1.1.tar.gz 45.7 kB With provenance Details for cli_relay-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cli-relay 0.1.1
File Interpreter ABI Platform Actions
cli_relay-0.1.1-py3-none-any.whl Python 3 none any Details for cli_relay-0.1.1-py3-none-any.whl

Total release size: 85.7 kB

Release files / cli_relay-0.1.1.tar.gz

Download URL cli_relay-0.1.1.tar.gz
Size 45.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ef3481989f57a155ac84379afbb94e5aa7b32abf93605cf7f305c1541b627ae1
BLAKE2b-256 checksum
How to use checksums
7097c07a190bc813d17e1e074ce0f4522fb6245f45ee20e1afeb9b108a221e63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Release files / cli_relay-0.1.1-py3-none-any.whl

Download URL cli_relay-0.1.1-py3-none-any.whl
Size 40.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4b1bf88b884dd894376bc6168b0c4e7ef32ec8b7f5eeb058f2dcdac8f286978b
BLAKE2b-256 checksum
How to use checksums
3038940ad747188cae660c483e69c83e81dc06176675b776b2dc07780d2713e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Security for cli-relay 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cli_relay-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page