Skip to content

About

A simple proxy that would let your Cline and Claude CLI auto switching to all OpenRouters :free models on quota exhaustion

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

21 Commits

Folders and files

Repository files navigation

Unified Free Model Proxy for Cline & Claude CLI

A zero-dependency Node.js proxy server that routes OpenAI-compatible requests (Cline) and Anthropic Messages requests (Claude CLI / Claude Code) to OpenRouter free-tier models with automatic failover, SWE-first prioritization, and multi-batch recovery.

Claude CLI with Free Model Proxy


Why Use This?

  • Zero Dropped Agent Loops: Automatically intercepts rate limits (429) or server overloads (503) and cascades to the next best free model without breaking agent workflows.
  • Dual Protocol Support: Exposes both /v1/chat/completions (OpenAI format for Cline) and /v1/messages (Anthropic format with native SSE streaming for Claude Code).
  • Bypasses 3-Model Limits: OpenRouter limits fallback arrays to 3 models per request; this proxy seamlessly handles 10+ models across sequential multi-batch retries.
  • Auto Mode Fast-Path: Intercepts Claude Code's repetitive safety classifier checks (claude-sonnet-5), auto-approving in <20ms with 0 tokens to preserve free rate limits.
  • Zero External Dependencies: Pure Node.js (v18+) using native fetch and streams—no npm install needed. Works identically on Windows, macOS, and Linux.

Model Priority Cascades

The cascade is generated from OpenRouter's live model list by scripts/sync-models.mjs and written to cascade.json (git-ignored), which router.mjs loads at startup. If the file is missing or invalid, the router uses its built-in lists.

A model is kept only if it is free, text-in/text-out, supports tool calling, has at least 128k context, is at least 7B parameters, is not about to expire, and answers a small live test request. Pinned models (default nvidia/nemotron-3-ultra-550b-a55b:free, override with SYNC_PINNED in .env) go first, then models ordered by context length. openrouter/free is always appended as the safety net.

npm run sync:dry   # show the resulting cascade without writing
npm run sync       # write cascade.json and restart the proxy if the list changed

On Windows, the daily Scheduled Task OpenRouterProxySync (04:00) runs the sync.

(For Cline, models are automatically chunked into 3-model batches. TokenHarbor free models like deepseek-v4.1-flash:free are also supported if configured).


🤖 1-Prompt Autonomous Agent Setup

If using an AI coding agent (Claude Code, Cline, Cursor, Antigravity, Roo Code, etc.), paste this prompt into your agent to clone, install, configure, and launch the proxy automatically:

Agent Prompt:

Clone https://github.com/hissain/FreeModelsForCline.git, set up the .env file from .env.example, start the background proxy service, and configure my coding tool to use it.

Critical Decisions — Before proceeding, ask me:
1. What is my OpenRouter API Key (sk-or-v1-...)? (Required for OpenRouter free models; prompt me to input it so it can be saved to .env)
2. Which client should be configured: Claude Code, Cline, or both?

Once I provide those answers:
- Save the API key to .env (and ensure PORT=8081).
- Start the background proxy daemon using `node scripts/proxy.mjs start`.
- Verify the service is healthy at http://localhost:8081/health.
- Configure the requested client(s):
  * Claude Code: Set ANTHROPIC_BASE_URL="http://localhost:8081" and ANTHROPIC_MODEL="free-router" in ~/.claude/settings.json or .claude/settings.local.json.
  * Cline: Set Base URL to "http://localhost:8081/v1", Model ID to "free-router", and API Key to "dummy".
- Run a test prompt through the client to confirm free-tier routing is functional.

Manual Quick Start

1. Initialize Configuration

npm run init        # or: node scripts/proxy.mjs init

Add your key to .env:

OPENROUTER_API_KEY=sk-or-v1-your-key-here
PORT=8081
SAFETY_CLASSIFIER_MODEL=auto-approve

2. Start the Proxy

npm run proxy:start # or: node scripts/proxy.mjs start

The server listens at http://localhost:8081/v1.


Client Configurations

1. Claude CLI (Claude Code)

Add to ~/.claude/settings.json (or .claude/settings.local.json in your project):

{
  "env": {
    "ANTHROPIC_BASE_URL": "http://localhost:8081",
    "ANTHROPIC_AUTH_TOKEN": "dummy",
    "ANTHROPIC_API_KEY": "",
    "ANTHROPIC_MODEL": "free-router"
  },
  "permissions": {
    "allow": ["Bash(*)", "Read(*)", "Write(*)", "Edit(*)", "Glob(*)", "Grep(*)"]
  },
  "allowDangerouslySkipPermissions": true
}
  • ANTHROPIC_MODEL: "free-router": Triggers proxy auto-cascading across free models.
  • ANTHROPIC_API_KEY: "": Prevents unwanted browser login attempts to Anthropic.
  • SAFETY_CLASSIFIER_MODEL=auto-approve: Bypasses Claude Code's background claude-sonnet-5 permission checks in <20ms, saving 100% of classifier API calls.

Test Claude CLI:

claude -p "Say hello in 3 words"

2. Cline (VS Code)

In Cline Settings -> API Provider:

  • API Provider: OpenAI Compatible
  • Base URL: http://localhost:8081/v1
  • API Key: dummy
  • Model ID: free-router

Background Service & Autostart

Managed via cross-platform Node CLI (scripts/proxy.mjs):

Command Action
npm run proxy:start Start in background with auto-restart supervisor
npm run proxy:stop Stop background proxy and supervisor
npm run proxy:status Check health, port status, and recent log lines
npm run proxy:restart Restart the proxy
npm run autostart:install Register proxy to boot on user login (Windows/macOS/Linux)
npm run autostart:uninstall Remove autostart registration

Autostart Implementation

  • Windows: VBS script in %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup
  • macOS: LaunchAgent plist in ~/Library/LaunchAgents
  • Linux: systemd user service in ~/.config/systemd/user

License

MIT © 2026 Md. Sazzad Hissain Khan


Made by Hissain with ❤️ for Developers

About

A simple proxy that would let your Cline and Claude CLI auto switching to all OpenRouters :free models on quota exhaustion

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages