# Route Claude Code through a local LiteLLM proxy

> Point Claude Code at LiteLLM with ANTHROPIC_BASE_URL, pin a patched release, and keep the proxy private.

Source: https://fullbytedeveloper.com/blog/litellm-claude-code-local-proxy
Published here: 2026-11-21

Point Claude Code at a local LiteLLM proxy with `ANTHROPIC_BASE_URL` set to the proxy root and a credential var the gateway expects [2] [5]. Define Anthropic models in `config.yaml`, start `litellm --config`, and unset a conflicting shell `ANTHROPIC_API_KEY` when a virtual key should win [2]. Pin a current patched PyPI or Docker release before you expose the proxy to anything beyond localhost [7] [8] [9] [11].

Related field note: [LiteLLM compromised release response](/blog/litellm-compromised-release-response). This page is the routing setup, not a private multi-account failover recipe.

## Pin a current patched litellm first

As of 2026-11-20, PyPI reported `litellm` version `1.110.2` [11]. Run that line or newer after you re-check PyPI and the advisory list on install day.

Two separate security stories matter for this post:

1. **CISA KEV CVE-2026-40217** (GHSA-wxxx-gvqv-xp7p): unprotected alternate channel / sandbox escape via custom-code guardrail testing. GitHub advisory lists a first patched version at `1.83.10` (description also mentions `1.83.11` / RestrictedPython). CISA added the CVE to the Known Exploited Vulnerabilities Catalog on 2026-11-18 [8] [9]. Upgrade to `1.83.10` or later at minimum; prefer current stable.
2. **GHSA-3cv6-jpf6-8222** (CVE-2026-84377): authenticated SSRF and provider-credential exfiltration via unvalidated request-body routing parameters, with patched lines starting at examples such as `1.88.6` / `1.96.2` and later backports listed in the advisory [7].

March 2026 PyPI supply-chain compromise of `1.82.7` / `1.82.8` is a third story already covered on the field note and LiteLLM's own security blog [10] [12] [13]. Those builds were removed from PyPI; still pin and verify.

**Warning:** keep a local proxy off the public internet when you can. Admin credentials on a reachable proxy raise the blast radius of every authenticated bug class above.

## Write a minimal config.yaml

LiteLLM documents top-level sections `model_list`, `router_settings`, `litellm_settings`, `general_settings`, and optional `environment_variables` [1]. Shape from the Claude Code client docs [2]:

```yaml title="config.yaml"
model_list:
  - model_name: claude-sonnet-5
    litellm_params:
      model: anthropic/claude-sonnet-5
      api_key: os.environ/ANTHROPIC_API_KEY
general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY
```

`model_name` is what the client asks for. `litellm_params.model` is what LiteLLM sends to `completion()`. Secrets of the form `os.environ/NAME` read that environment variable [1].

## Start the proxy

```bash
export ANTHROPIC_API_KEY="YOUR_PROVIDER_KEY"
export LITELLM_MASTER_KEY="YOUR_LOCAL_MASTER_KEY"
litellm --config /path/to/config.yaml
```

Docs examples commonly listen on port 4000 [2]. You should see the proxy process start. Follow the official docs and verify the listen address on your own machine.

## Point Claude Code at the proxy

Anthropic and LiteLLM agree on the gateway pattern [2] [4] [5]:

```bash
export ANTHROPIC_BASE_URL="http://localhost:4000"
export ANTHROPIC_AUTH_TOKEN="$LITELLM_MASTER_KEY"
export ANTHROPIC_MODEL="claude-sonnet-5"
unset ANTHROPIC_API_KEY
claude
```

Claude Code appends `/v1/messages` to the base URL [2] [5]. Use `ANTHROPIC_AUTH_TOKEN` for Bearer auth or `ANTHROPIC_API_KEY` for x-api-key, matching what your gateway expects [5]. If both are set, LiteLLM docs say to unset the shell `ANTHROPIC_API_KEY` so a virtual key in `ANTHROPIC_AUTH_TOKEN` wins [2].

You should confirm the Anthropic base URL line via Claude Code `/status` per Anthropic's gateway docs [5]. Optional: `CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1` so `/model` can load gateway entries from `GET /v1/models` [2] [4]. As of Claude Code v2.1.196, Remote Control is disabled when `ANTHROPIC_BASE_URL` is not `api.anthropic.com` [4].

## Use documented deployment failover only

Public load-balancing docs: multiple `model_list` rows can share one `model_name`; `litellm_params.order` sets priority; `router_settings` can set retries and fallbacks [3]. That is reliability for owned keys and deployments, not a measured recipe to rotate personal Claude.ai seats. Save any "beats rate limits" claim for a Part 2 with your own numbers.

Corporate `HTTPS_PROXY` / `HTTP_PROXY` / `NO_PROXY` remain a different layer from `ANTHROPIC_BASE_URL` [6].

You now have a local gateway shape, Claude Code env wiring, and a patch habit tied to GHSA-3cv6-jpf6-8222 plus CISA KEV CVE-2026-40217.

Send this to the friend who wants Claude Code to go through their own LiteLLM proxy.

Image: Three boxes: Claude Code with ANTHROPIC_BASE_URL localhost:4000, LiteLLM proxy with config.yaml and /v1/messages, then providers via model_list. Security habit strip cites patched litellm and advisories. No people.
https://fullbytedeveloper.com/media/litellm-claude-code-local-proxy/agent-proxy-providers.webp
Claude Code talks to a local LiteLLM proxy, then providers. Pin a current patched release.

## Sources

1. [LiteLLM: Proxy config.yaml, accessed 2026-11-20](https://docs.litellm.ai/docs/proxy/configs)
2. [LiteLLM: Claude Code client setup, accessed 2026-11-20](https://docs.litellm.ai/docs/proxy/client_setup/claude_code)
3. [LiteLLM: Load balancing, accessed 2026-11-20](https://docs.litellm.ai/docs/proxy/load_balancing)
4. [Anthropic: Claude Code environment variables, accessed 2026-11-20](https://code.claude.com/docs/en/env-vars)
5. [Anthropic: LLM gateway connect, accessed 2026-11-20](https://code.claude.com/docs/en/llm-gateway-connect)
6. [Anthropic: Network configuration, accessed 2026-11-20](https://code.claude.com/docs/en/network-config)
7. [GHSA-3cv6-jpf6-8222: authenticated SSRF / credential exfiltration, accessed 2026-11-20](https://github.com/advisories/GHSA-3cv6-jpf6-8222)
8. [GHSA-wxxx-gvqv-xp7p / CVE-2026-40217: custom-code guardrail sandbox escape, accessed 2026-11-20](https://github.com/advisories/GHSA-wxxx-gvqv-xp7p)
9. [CISA Known Exploited Vulnerabilities Catalog (CVE-2026-40217 entry), accessed 2026-11-20](https://www.cisa.gov/known-exploited-vulnerabilities-catalog)
10. [LiteLLM: Security Update March 2026 (PyPI 1.82.7/1.82.8), accessed 2026-11-20](https://docs.litellm.ai/blog/security-update-march-2026)
11. [PyPI JSON for litellm, accessed 2026-11-20](https://pypi.org/pypi/litellm/json)
12. [Simon Willison: Malicious litellm_init.pth note, related reading](https://simonwillison.net/2026/Mar/24/malicious-litellm/)
13. [Full Byte Developer: LiteLLM compromised release response](https://fullbytedeveloper.com/blog/litellm-compromised-release-response)
