Skip to content

Repository files navigation

claude-proxy

A local proxy that sits between Claude Code and Anthropic's API. When you hit your daily Claude Max token limit, it automatically fails over to OpenRouter so you keep working without interruption.

How it works

Claude Code → localhost:8462 → Anthropic API
                             ↘ OpenRouter (on 429)
  • Transparent to Claude Code — just set ANTHROPIC_BASE_URL=http://localhost:8462
  • On a 429 rate limit, instantly reroutes to your chosen OpenRouter fallback model
  • Tracks spend separately for Anthropic vs OpenRouter
  • macOS notifications on failover and recovery
  • /pick-model Claude Code skill to switch fallback model mid-session

Setup

git clone https://github.com/swillinger/claude-proxy
cd claude-proxy
cp .env.example .env
# Edit .env with your API keys
./start.sh

Add to your shell profile:

export ANTHROPIC_BASE_URL=http://localhost:8462

Persistent (launchd — auto-restart on crash)

cp com.stevenwillinger.claude-proxy.plist ~/Library/LaunchAgents/
launchctl load ~/Library/LaunchAgents/com.stevenwillinger.claude-proxy.plist

Fallback model picker

Install the Claude Code skill:

cp pick-model.md ~/.claude/commands/pick-model.md

Then run /pick-model from any Claude Code session to switch the fallback model.

Models are ranked by the Aider polyglot coding leaderboard — the closest public benchmark to how Claude Code actually works. Pricing sourced live from OpenRouter.

Admin endpoints

# Status + spend
curl http://localhost:8462/status

# Force fallback for N seconds (testing)
curl -X POST "http://localhost:8462/admin/force-fallback?seconds=60"

# Switch fallback model
curl -X POST "http://localhost:8462/admin/set-model?model=openai/o3"

# Clear fallback, return to Anthropic
curl -X POST http://localhost:8462/admin/clear-fallback

Environment variables

Variable Required Default Description
ANTHROPIC_API_KEY Your Anthropic API key
OPENROUTER_API_KEY Your OpenRouter API key
FALLBACK_MODEL openai/gpt-5 OpenRouter model ID to use on failover
PROXY_PORT 8462 Local port
DAILY_RESET_HOUR UTC hour when your Anthropic daily limit resets
NOTIFY true macOS notifications on failover/recovery

About

Local proxy for Claude Code with automatic OpenRouter failover when Anthropic rate limits hit

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages