Spaces:
Running
Running
Add README.md for build
Browse files12345678910---title: Claude Code Proxyemoji: π¨colorFrom: greencolorTo: greensdk: dockerpinned: false---Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500<div align="center"># π€ Free Claude CodeUse Claude Code CLI, VS Code, JetBrains ACP, or chat bots through your own Anthropic-compatible proxy.[](https://opensource.org/licenses/MIT)[](https://www.python.org/downloads/)[](https://github.com/astral-sh/uv)[](https://github.com/Alishahryar1/free-claude-code/actions/workflows/tests.yml)[](https://pypi.org/project/ty/)[](https://github.com/astral-sh/ruff)[](https://github.com/Delgan/loguru)Free Claude Code routes Anthropic Messages API traffic from Claude Code to NVIDIA NIM. It keeps Claude Code's client-side protocol stable while letting you use NVIDIA's free models.[Quick Start](#quick-start) Β· [Providers](#choose-a-provider) Β· [Clients](#connect-claude-code) Β· [Troubleshooting](#troubleshooting) Β· [Development](#development)</div><div align="center"><img src="pic.png" alt="Free Claude Code in action" width="700"></div>## What You Get- Drop-in proxy for Claude Code's Anthropic API calls.- NVIDIA NIM provider backend with free models.- Per-model routing: send Opus, Sonnet, Haiku, and fallback traffic to different NVIDIA NIM models.- Native Claude Code `/model` picker support through the proxy's `/v1/models` endpoint.- Streaming, tool use, reasoning/thinking block handling, and local request optimizations.- Optional Discord or Telegram bot wrapper for remote coding sessions.- Optional voice-note transcription through local Whisper or NVIDIA NIM.## Quick Start### 1. Install RequirementsInstall [Claude Code](https://github.com/anthropics/claude-code), then install `uv` and Python 3.14.macOS/Linux:```bashcurl -LsSf https://astral.sh/uv/install.sh | shuv self updateuv python install 3.14```Windows PowerShell:```powershellpowershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"uv self updateuv python install 3.14```### 2. Clone And Configure```bashgit clone https://github.com/Alishahryar1/free-claude-code.gitcd free-claude-codecp .env.example .env```PowerShell uses:```powershellCopy-Item .env.example .env```Edit `.env` and choose one provider. For the default NVIDIA NIM path:```dotenvNVIDIA_NIM_API_KEY="nvapi-your-key"MODEL="nvidia_nim/z-ai/glm4.7"ANTHROPIC_AUTH_TOKEN="freecc"```Use any local secret for `ANTHROPIC_AUTH_TOKEN`; Claude Code will send the same value back to this proxy. Leave it empty only for local/private testing.### 3. Start The Proxy```bashuv run uvicorn server:app --host 0.0.0.0 --port 8082```Package install alternative:```bashuv tool install git+https://github.com/Alishahryar1/free-claude-code.gitfcc-initfree-claude-code````fcc-init` creates `~/.config/free-claude-code/.env` from the bundled template.### 4. Run Claude CodePoint `ANTHROPIC_BASE_URL` at the proxy root. Do not append `/v1`.PowerShell:```powershell$env:ANTHROPIC_AUTH_TOKEN="freecc"; $env:ANTHROPIC_BASE_URL="http://localhost:8082"; claude```Bash:```bashANTHROPIC_AUTH_TOKEN="freecc" ANTHROPIC_BASE_URL="http://localhost:8082" claude```## Choose A ProviderModel values use this format:```textprovider_id/model/name````MODEL` is the fallback. `MODEL_OPUS`, `MODEL_SONNET`, and `MODEL_HAIKU` override routing for requests that Claude Code sends for those tiers.| Provider | Prefix | Transport | Key | Default base URL || --- | --- | --- | --- | --- || <img src="https://cdn.simpleicons.org/nvidia/76B900" alt="" width="18" height="18"> NVIDIA NIM | `nvidia_nim/...` | OpenAI chat translation | `NVIDIA_NIM_API_KEY` | `https://integrate.api.nvidia.com/v1` || <img src="https://cdn.simpleicons.org/groq/F55036" alt="" width="18" height="18"> Groq | `groq/...` | OpenAI chat translation | `GROQ_API_KEY` | `https://api.groq.com/openai/v1` || <img src="https://cdn.simpleicons.org/cerebras/313131" alt="" width="18" height="18"> Cerebras | `cerebras/...` | OpenAI chat translation | `CEREBRAS_API_KEY` | `https://api.cerebras.ai/v1` |<details><summary><img src="https://cdn.simpleicons.org/nvidia/76B900" alt="" width="18" height="18"> <b>NVIDIA NIM</b></summary>Get a key at [build.nvidia.com/settings/api-keys](https://build.nvidia.com/settings/api-keys).```dotenvNVIDIA_NIM_API_KEY="nvapi-your-key"MODEL="nvidia_nim/z-ai/glm4.7"```Popular examples:- `nvidia_nim/qwen/qwen3-coder-480b-a35b-instruct`- `nvidia_nim/mistralai/mistral-large-3-675b-instruct-2512`- `nvidia_nim/z-ai/glm4.7`</details><details><summary><img src="https://cdn.simpleicons.org/groq/F55036" alt="" width="18" height="18"> <b>Groq</b></summary>Get a key at [console.groq.com/keys](https://console.groq.com/keys).```dotenvGROQ_API_KEY="gsk_..."MODEL="groq/openai/gpt-oss-120b"```Popular examples:- `groq/openai/gpt-oss-120b` (Best overall for Claude Code)- `groq/openai/gpt-oss-20b` (Ultra-low latency)- `groq/llama-3.3-70b-versatile`</details><details><summary><img src="https://cdn.simpleicons.org/cerebras/313131" alt="" width="18" height="18"> <b>Cerebras</b></summary>Get a key at [cloud.cerebras.ai](https://cloud.cerebras.ai/).```dotenvCEREBRAS_API_KEY="csk_..."MODEL="cerebras/gpt-oss-120b"```Popular examples:- `cerebras/gpt-oss-120b` (~3000 tok/s - Fastest reasoning)- `cerebras/qwen-3-235b`- `cerebras/llama3.1-8b`</details>## Connect Claude Code### Claude Code CLI```bashANTHROPIC_AUTH_TOKEN="freecc" ANTHROPIC_BASE_URL="http://localhost:8082" claude```### VS Code ExtensionOpen Settings, search for `claude-code.environmentVariables`, choose **Edit in settings.json**, and add:```json"claudeCode.environmentVariables": [{ "name": "ANTHROPIC_BASE_URL", "value": "http://localhost:8082" },{ "name": "ANTHROPIC_AUTH_TOKEN", "value": "freecc" }]```Reload the extension. If the extension shows a login screen, choose the Anthropic Console path once; the local proxy still handles model traffic after the environment variables are active.### JetBrains ACPEdit the installed Claude ACP config:- Windows: `C:\Users\%USERNAME%\AppData\Roaming\JetBrains\acp-agents\installed.json`- Linux/macOS: `~/.jetbrains/acp.json`Set the environment for `acp.registry.claude-acp`:```json"env": {"ANTHROPIC_BASE_URL": "http://localhost:8082","ANTHROPIC_AUTH_TOKEN": "freecc"}```Restart the IDE after changing the file.### Model PickerClaude Code 2.1.126 or later reads this proxy's `/v1/models` endpoint when `ANTHROPIC_BASE_URL` points at the proxy. Start Claude Code normally, run `/model`, and choose any discovered provider model.<div align="center"><img src="cc-model-picker.png" alt="Claude Code model picker showing gateway models" width="700"></div>The proxy lists models for configured provider keys and referenced local providers. Picker-safe IDs are routed back to the real provider/model automatically, so no `.env` edit or separate launcher script is needed after startup.Each provider model also has a `(no thinking)` picker variant. Use it when a model does not support Claude Code thinking or fails with adaptive-thinking requests. It routes to the same upstream model while asking Claude Code to send a non-thinking request.## Optional Integrations### Discord And Telegram BotsThe bot wrapper runs Claude Code sessions remotely, streams progress, supports reply-based conversation branches, and can stop or clear tasks.Discord minimum config:```dotenvMESSAGING_PLATFORM="discord"DISCORD_BOT_TOKEN="your-discord-bot-token"ALLOWED_DISCORD_CHANNELS="123456789"CLAUDE_WORKSPACE="./agent_workspace"ALLOWED_DIR="C:/Users/yourname/projects"```Create the bot in the [Discord Developer Portal](https://discord.com/developers/applications), enable Message Content Intent, and invite it with read/send/history permissions.Telegram minimum config:```dotenvMESSAGING_PLATFORM="telegram"TELEGRAM_BOT_TOKEN="123456789:ABC..."ALLOWED_TELEGRAM_USER_ID="your-user-id"CLAUDE_WORKSPACE="./agent_workspace"ALLOWED_DIR="C:/Users/yourname/projects"```Get a token from [@BotFather](https://t.me/BotFather) and your user ID from [@userinfobot](https://t.me/userinfobot).Useful commands:- `/stop` cancels a task; reply to a task message to stop only that branch.- `/clear` resets sessions; reply to clear one branch.- `/stats` shows session state.### Voice NotesVoice notes work on Discord and Telegram. Choose one backend:```bashuv sync --extra voice_localuv sync --extra voiceuv sync --extra voice --extra voice_local``````dotenvVOICE_NOTE_ENABLED=trueWHISPER_DEVICE="cpu" # cpu | cuda | nvidia_nimWHISPER_MODEL="base"HF_TOKEN=""```Use `WHISPER_DEVICE="nvidia_nim"` with the `voice` extra and `NVIDIA_NIM_API_KEY` for NVIDIA-hosted transcription.## Configuration Reference[`.env.example`](.env.example) is the canonical list of variables. The sections below are the ones most users change.### Model Routing```dotenvMODEL="nvidia_nim/z-ai/glm4.7"MODEL_OPUS=MODEL_SONNET=MODEL_HAIKU=ENABLE_MODEL_THINKING=trueENABLE_OPUS_THINKING=ENABLE_SONNET_THINKING=ENABLE_HAIKU_THINKING=```Blank per-tier values inherit the fallback. Blank thinking overrides inherit `ENABLE_MODEL_THINKING`.### Provider Keys And URLs```dotenvNVIDIA_NIM_API_KEY=""```Proxy settings are per provider:```dotenvNVIDIA_NIM_PROXY=""```### Rate Limits And Timeouts```dotenvPROVIDER_RATE_LIMIT=1PROVIDER_RATE_WINDOW=3PROVIDER_MAX_CONCURRENCY=5HTTP_READ_TIMEOUT=120HTTP_WRITE_TIMEOUT=10HTTP_CONNECT_TIMEOUT=10```Use lower limits for free hosted providers; local providers can usually tolerate higher concurrency if the machine can handle it.### Security And Diagnostics```dotenvANTHROPIC_AUTH_TOKEN=LOG_RAW_API_PAYLOADS=falseLOG_RAW_SSE_EVENTS=falseLOG_API_ERROR_TRACEBACKS=falseLOG_RAW_MESSAGING_CONTENT=falseLOG_RAW_CLI_DIAGNOSTICS=falseLOG_MESSAGING_ERROR_DETAILS=false```Raw logging flags can expose prompts, tool arguments, paths, and model output. Keep them off unless you are debugging locally.### Local Web Tools```dotenvENABLE_WEB_SERVER_TOOLS=trueWEB_FETCH_ALLOWED_SCHEMES=http,httpsWEB_FETCH_ALLOW_PRIVATE_NETWORKS=false```These tools perform outbound HTTP from the proxy. Keep private-network access disabled unless you are in a controlled lab environment.## Troubleshooting### **Major Fixes (May 2026)**#### **1. Model Visibility & Caching Issues**The Claude CLI often caches model lists, causing local proxy models to disappear.- **Fix:** We implemented a "Multi-Model Advertisement" feature. The `MODEL` environment variable now supports a comma-separated list.- **Action:** Set `MODEL="model1,model2,model3"` in your `.env`. The proxy will force the CLI to display all of them by registering them as primary models.#### **2. The "Amnesia/Thinking" Loop**When using `auto` mode, the proxy would sometimes switch models in the middle of a "Thinking" block if it took too long, causing the CLI to repeat the same thought endlessly.- **Fix:** Implemented "Sticky Sessions" in `api/services.py`. Once a model yields its first event (including thinking blocks), the proxy commits to that model for the duration of the turn. Fallbacks only occur if the model fails to start entirely.#### **3. NVIDIA NIM Fallback Sync**Ensured that the `AUTO_MODEL_PRIORITY` and `NVIDIA_NIM_FALLBACK_MODELS` are synchronized to provide maximum coverage.### Claude Code says `undefined ... input_tokens`, `$.speed`, or malformed responseUpdate to the latest commit first. Older versions could emit invalid usage metadata in streaming responses. Then check:- `ANTHROPIC_BASE_URL` is `http://localhost:8082`, not `http://localhost:8082/v1`.- The proxy is returning Server-Sent Events for `/v1/messages`.- `server.log` contains no upstream 400/500 response before the malformed-response error.### Provider disconnects during streamingErrors like `incomplete chunked read`, `server disconnected`, or a peer closing the body usually come from the upstream provider or gateway. Reduce concurrency, raise timeouts, or retry later.### Tool calls work on one model but not anotherTool support is model and provider dependent. Some OpenAI-compatible models emit malformed tool-call deltas, omit tool names, or return tool calls as plain text. Try another model or provider before assuming the proxy is broken.### The VS Code extension still shows a login screenConfirm the extension environment variables are set, then reload the extension or restart VS Code. The browser login flow may still appear once; the local proxy is used when `ANTHROPIC_BASE_URL` is active in the extension process.## How It Works```textClaude Code CLI / IDE|| Anthropic Messages APIvFree Claude Code proxy (:8082)|| provider-specific request/stream adaptervNVIDIA NIM```Important pieces:- FastAPI exposes Anthropic-compatible routes such as `/v1/messages`, `/v1/messages/count_tokens`, and `/v1/models`.- Model routing resolves the Claude model name to `MODEL_OPUS`, `MODEL_SONNET`, `MODEL_HAIKU`, or `MODEL`.- NVIDIA NIM uses OpenAI chat streaming translated into Anthropic SSE.- The proxy normalizes thinking blocks, tool calls, token usage metadata, and provider errors into the shape Claude Code expects.- Request optimizations answer trivial Claude Code probes locally to save latency and quota.## Development### Project Structure```textfree-claude-code/βββ server.py # ASGI entry pointβββ api/ # FastAPI routes, service layer, routing, optimizationsβββ core/ # Shared Anthropic protocol helpers and SSE utilitiesβββ providers/ # Provider transports, registry, rate limitingβββ messaging/ # Discord/Telegram adapters, sessions, voiceβββ cli/ # Package entry points and Claude process managementβββ config/ # Settings, provider catalog, loggingβοΏ½οΏ½β tests/ # Unit and contract tests```### Commands```bashuv run ruff formatuv run ruff checkuv run ty checkuv run pytest```Run them in that order before pushing. CI enforces the same checks.### Package Scripts`pyproject.toml` installs:- `free-claude-code`: starts the proxy with configured host and port.- `fcc-init`: creates the user config template at `~/.config/free-claude-code/.env`.### Extending- Add messaging platforms by implementing the `MessagingPlatform` interface in `messaging/`.- Extend NVIDIA NIM provider functionality by modifying `providers/nvidia_nim/`.## Contributing- Report bugs and feature requests in [Issues](https://github.com/Alishahryar1/free-claude-code/issues).- Keep changes small and covered by focused tests.- Do not open Docker integration PRs.- Do not open README change PRs just open an issue for it.- Run the full check sequence before opening a pull request.- The syntax Except X, Y is brought back in python 3.14 final version (not in 3.14 alpha). Keep in mind before opening PRs.## NVIDIA Qwen integrationYou can run a simple NVIDIA Qwen streaming example using the OpenAI-compatible client shipped below.- Install the dependency:```bashpip install -r requirements.txt```- Set your NVIDIA API key (do NOT commit keys). Example (PowerShell temporary):```powershell$env:NV_API_KEY = "nvapi-<YOUR_KEY>"python nvidia_integration.py "Write a short Python script that prints Hello"```Persisted (Windows):```powershellsetx NV_API_KEY "nvapi-<YOUR_KEY>"# open a new shell to use the persisted variable```Linux/macOS:```bashexport NV_API_KEY="nvapi-<YOUR_KEY>"python nvidia_integration.py "Write a short Python script that prints Hello"```The example `nvidia_integration.py` streams completions from `https://integrate.api.nvidia.com/v1` using the `qwen/qwen3-coder-480b-a35b-instruct` model. Replace `<YOUR_KEY>` with your actual NVIDIA API key. Never share or commit your API keys.## LicenseMIT License. See [LICENSE](LICENSE) for details.
README.md+500-10