Free guide
Claude Code Fallbacks & Memory Setup
Stop losing hours to rate limits and context wipes.
What You Need
- Claude Code: Installed via your terminal (requires Node.js). Free.
- API Keys: An Anthropic account and at least one backup provider (like OpenRouter or OpenAI) for fallbacks. Pay-as-you-go API usage.
- A Local Router: LiteLLM proxy or a basic routing script. Free and open-source.
Step-by-Step Guide
Step 1: Install your local router
Open your terminal and install LiteLLM to handle your multi-model routing locally.
pip install litellm[proxy]Step 2: Create your fallback configuration
Create a file named config.yaml in your project folder. Paste this exact structure to route overflow requests from Claude 3.5 Sonnet to a backup model when rate limits hit:
model_list:
- model_name: claude-3-5-sonnet
litellm_params:
model: anthropic/claude-3-5-sonnet-20241022
api_key: os.environ/ANTHROPIC_API_KEY
fallbacks: [{"model": "openai/gpt-4o"}]Step 3: Set your environment variables
In your terminal, securely load your API keys so the router can access them:
export ANTHROPIC_API_KEY="your-anthropic-key-here"
export OPENAI_API_KEY="your-backup-key-here"Step 4: Start the local proxy
Run the router locally on port 4000:
litellm --config config.yaml --port 4000Step 5: Add persistent memory
To keep your project context across restarts, create a .claudememory folder in your root directory. Claude Code reads files in this directory automatically on startup, so your project rules and state persist even if the session crashes.
Common Mistakes & Fixes
- Mistake: Claude Code keeps hitting the direct Anthropic API instead of the router.
- Fix: Update your terminal environment to point your base URL to
http://localhost:4000.
- Fix: Update your terminal environment to point your base URL to
- Mistake: Router throws an authentication error.
- Fix: Double-check that your keys are exported correctly in the active terminal window using
echo $ANTHROPIC_API_KEY.
- Fix: Double-check that your keys are exported correctly in the active terminal window using
Follow @letagentswork for more practical agent setups that save you time.
Building agents too? Ask questions and get new builds first in Agent Lab on Telegram (free).
Made by Let Agents Work — follow @letagentswork
From the reel: Stop Claude Code Rate Limits With Multi-Model Fallbacks