Skip to content

ArchitectVS7/switch-ex

Repository files navigation

Claude Code Fallback Monitor

Simple tool to extend Claude Code usage with automatic API fallbacks and commit tracking for code review.

What It Does

  1. Automatic Fallbacks: When Claude hits rate limits, automatically switches to Gemini → DeepSeek → local models
  2. Commit Tracking: Tags commits with which model did the work for easy rollback
  3. Code Review Workflow: Script to review and merge/rollback work from fallback models

Quick Start

1. Install Dependencies

pip install -r requirements.txt

2. Set Environment Variables

export ANTHROPIC_API_KEY="sk-ant-..."
export GOOGLE_API_KEY="..."           # Optional: Gemini fallback
export OPENROUTER_API_KEY="..."       # Optional: DeepSeek fallback
export DISCORD_WEBHOOK_URL="..."      # Optional: notifications

3. Start LiteLLM Proxy

litellm --config litellm_config.yaml --port 8000

4. Start Monitor (in another terminal)

python monitor.py

5. Configure Claude Code

In Claude Code settings or via CLI:

# Point Claude Code at the proxy
export ANTHROPIC_API_BASE="http://localhost:8000"

Or in Claude Code web app: Settings → LLM Gateway → http://localhost:8000

Usage Workflow

Normal Development

  1. Start the proxy and monitor
  2. Work in Claude Code as usual
  3. When rate limits hit, the proxy automatically switches models
  4. Monitor creates tagged commits for each model switch

Code Review Phase

When Claude usage returns:

# Review what each model did
python review.py --analyze

# Keep good work from a model
python review.py --accept gemini-flash

# Rollback bad work from a model
python review.py --rollback deepseek-r1

How It Works

Claude Code → LiteLLM Proxy → Anthropic API (T0)
                ↓ (rate limit)
              Google API (T1)
                ↓ (rate limit)
              OpenRouter API (T2)

When a model switches:

  1. LiteLLM sends webhook to monitor
  2. Monitor commits current work with tag model:gemini-flash
  3. Discord notification sent (if configured)
  4. Work continues on fallback model

Configuration

Edit litellm_config.yaml to:

  • Change model priority order
  • Add/remove fallback models
  • Adjust rate limit handling
  • Configure notifications

Troubleshooting

Proxy won't start: Check API keys are set correctly

Claude Code not using proxy: Verify ANTHROPIC_API_BASE or LLM Gateway setting

No commits on switch: Check monitor is running and webhook URL in config

Models not falling back: Check LiteLLM logs for errors: litellm --config litellm_config.yaml --debug

Architecture

  • LiteLLM Proxy: Handles API routing and fallbacks
  • Monitor: Webhook listener that creates commit tags
  • Review Script: Git-based workflow for code review

Total code: ~150 lines Python. No databases, no complex state management.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •