# How to Move Claude Code to ChatGPT Subscription Models: Proxy Setup and CLI Replacement

> AI Release · @ai_releaseorg · https://ai-release.org/guides/kak-perevesti-claude-code-na-modeli-chatgpt-po-podpiske_en.html

## TL;DR
- **Time to complete:** 30 minutes
- **Difficulty:** Intermediate
- **You'll need:** Claude Code CLI (`claude --version`), Node.js runtime for the CLI, Python 3 + pip (only if your translator proxy is a Python package), `curl`, a free TCP port (examples below use `8080`), and an OpenAI credential — an API key, or whatever credential your plan's documentation says to use.

Subscription note: a ChatGPT consumer plan does not automatically give you an API key. Check your account page and the proxy documentation for which credential type is supported before you start. Everything below assumes you have a working credential string; where a value depends on your setup it is written as `<placeholder>`.

## What you'll get
- A local translator proxy listening on `http://127.0.0.1:8080` that accepts Anthropic-format requests (`/v1/messages`) and forwards them to an OpenAI model.
- Claude Code rewired to that proxy through `ANTHROPIC_BASE_URL` and `ANTHROPIC_AUTH_TOKEN`, persisted in `~/.claude/settings.json`.
- A one-command smoke test that proves the full path Claude Code → proxy → model works, plus a one-line rollback.

## Quick start
```bash
export OPENAI_API_KEY="<openai-credential>"
pip install "litellm[proxy]"
litellm --model <openai-model-name> --port 8080
```
```bash
export ANTHROPIC_BASE_URL="http://127.0.0.1:8080"
export ANTHROPIC_AUTH_TOKEN="<proxy-token>"
claude -p "Reply with the single word OK"
```
Details and verification — in the steps below.

## Requirements and setup
![Illustration: Requirements and setup](https://ai-release.org/guides/img/kak-perevesti-claude-code-na-modeli-chatgpt-po-podpiske-en-1.jpg?v=1796114874)

- **OS:** macOS, Linux, or Windows (PowerShell; WSL2 also works and matches the bash commands below).
- **Claude Code CLI installed and logged in once** — run `claude --version`; it must print a version string, not `command not found`.
- **A translator proxy.** Claude Code speaks the Anthropic Messages API; OpenAI models speak the Chat Completions API. A proxy — a small local service that rewrites one request format into the other — is what bridges them. **Example:** the LiteLLM proxy is a widely used option that serves an Anthropic-compatible `/v1/messages` endpoint. Confirm the exact install and flag names in its current documentation, because flags change between releases.
- **A free port:** check with `lsof -i :8080` (macOS/Linux) or `netstat -ano | findstr :8080` (Windows). Empty output = free.
- **A credential** for the OpenAI side, exported as `OPENAI_API_KEY`.
- **A proxy token** you invent yourself (any random string); it stops other local processes from using your proxy. Generate one: `openssl rand -hex 16`.

## Step 1. Inventory the CLI's configuration surfaces

**What to do:** Find out which Anthropic environment variables are already set in your shell, and where Claude Code stores persistent settings.

```bash
claude --version
env | grep -i anthropic
ls -la ~/.claude
```

**Why:** Claude Code picks its endpoint from environment variables, and the persistent copy usually lives in `~/.claude/settings.json` (per-project settings live in `.claude/settings.json` inside the repo). If an old `ANTHROPIC_BASE_URL` is already exported, your new value will be silently ignored — the shell wins over the file in most setups. Confirm the exact file locations for your build in the official Claude Code documentation, since paths differ between CLI and desktop builds (see [Claude Code Desktop: setup, limits and how it differs from the CLI](https://ai-release.org/guides/claude-code-desktop-ustanovka.html?utm_source=tg&utm_medium=channel&utm_campaign=guide_inline&utm_content=guide_to_guide)).

The variables that matter:

| Variable | Role |
|---|---|
| `ANTHROPIC_BASE_URL` | Which host Claude Code sends requests to |
| `ANTHROPIC_AUTH_TOKEN` | Bearer token sent in the `Authorization` header |
| `ANTHROPIC_API_KEY` | Key sent in the `x-api-key` header |

**How to check:** `env | grep -i anthropic` should print nothing (or only variables you recognise). If it prints an `ANTHROPIC_BASE_URL`, note its value — that is your old endpoint, and you will restore it to roll back.

## Step 2. Start the proxy and repoint Claude Code
![Illustration: Step 2. Start the proxy and repoint Claude Code](https://ai-release.org/guides/img/kak-perevesti-claude-code-na-modeli-chatgpt-po-podpiske-en-2.jpg?v=1796114883)


**What to do:** Launch the translator on `127.0.0.1:8080`, then tell Claude Code to use it.

```bash
export OPENAI_API_KEY="<openai-credential>"
litellm --model <openai-model-name> --port 8080
```

Then, in a **second terminal**, verify the proxy answers in Anthropic format before touching Claude Code:

```bash
curl -s http://127.0.0.1:8080/v1/messages \
  -H "content-type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -H "x-api-key: <proxy-token>" \
  -d '{"model":"<claude-model-alias>","max_tokens":64,"messages":[{"role":"user","content":"ping"}]}'
```

**Why:** Testing with `curl` isolates the proxy from the CLI. If the proxy is broken, you see it here instead of guessing inside Claude Code. The `/v1/messages` path and `anthropic-version: 2023-06-01` header are what Claude Code itself sends — using them proves compatibility.

**Model mapping is the part that usually fails.** Claude Code sends Claude model names; your proxy must map those names onto your OpenAI model. Get the real string from the proxy's own log rather than guessing: start the proxy with verbose logging, send the `curl` above with any model name, and read the `model` field it reports. Then add a mapping entry in the proxy config:

```yaml
model_list:
  - model_name: <claude-model-alias>
    litellm_params:
      model: openai/<openai-model-name>
      api_key: os.environ/OPENAI_API_KEY
```

Now persist the client side in `~/.claude/settings.json`:

```json
{
  "env": {
    "ANTHROPIC_BASE_URL": "http://127.0.0.1:8080",
    "ANTHROPIC_AUTH_TOKEN": "<proxy-token>"
  }
}
```

**How to check:** After saving the file, start a new shell (the settings file is read at launch) and run `claude -p "Reply with the single word OK"`. The proxy terminal must show one incoming request and an HTTP `200`; the CLI must print `OK`.

## Step 3. Verify end-to-end and lock the result
![Illustration: Step 3. Verify end-to-end and lock the result](https://ai-release.org/guides/img/kak-perevesti-claude-code-na-modeli-chatgpt-po-podpiske-en-3.jpg?v=1796114890)


**What to do:** Run the same smoke test three ways and confirm the proxy log shows a mapped model each time.

```bash
claude -p "Reply with the single word OK"
claude -p "List three file extensions you can read" 
curl -s http://127.0.0.1:8080/v1/messages -H "content-type: application/json" \
  -H "anthropic-version: 2023-06-01" -H "x-api-key: <proxy-token>" \
  -d '{"model":"<claude-model-alias>","max_tokens":32,"messages":[{"role":"user","content":"ping"}]}'
```

**Why:** The first command proves the CLI-to-proxy hop; the second proves a real task (not just a canned reply) survives translation; the third proves the proxy still works independently, so a later failure can be localised to Claude Code rather than to the backend.

**How to check:** Final checklist — all four items must be true.

- [ ] `claude -p "Reply with the single word OK"` prints `OK`
- [ ] Proxy log shows `200` and your `<openai-model-name>`, not the Claude alias
- [ ] `~/.claude/settings.json` parses as JSON (`python3 -m json.tool ~/.claude/settings.json`)
- [ ] Proxy is bound to `127.0.0.1`, not `0.0.0.0` — verify with `lsof -i :8080`

Rollback, if you need the original endpoint back: delete the `env` block from `~/.claude/settings.json` (or `unset ANTHROPIC_BASE_URL ANTHROPIC_AUTH_TOKEN`) and open a new shell.

## Troubleshooting

**Problem. Claude Code exits immediately, the proxy log stays empty.**
- Error: `Error: connect ECONNREFUSED 127.0.0.1:8080`
- Cause: nothing is listening on that port — the proxy crashed at start, is bound to a different port, or was started in a terminal you closed.
- Solution: confirm the listener, then restart the proxy in the foreground so you can read its startup log: `lsof -i :8080` (expect one line for your proxy process). If the output is empty, the proxy is gone — reread its startup output for a missing `OPENAI_API_KEY`.

**Problem. The proxy answers `curl` but Claude Code reports an auth failure.**
- Error: `401 {"type":"error","error":{"type":"authentication_error","message":"invalid x-api-key"}}`
- Cause: Claude Code sent `ANTHROPIC_API_KEY` (header `x-api-key`) while the proxy expects a bearer token — or the token value in `settings.json` does not match the one you gave the proxy.
- Solution: keep exactly one credential variable. Run `unset ANTHROPIC_API_KEY` and re-run with only `ANTHROPIC_AUTH_TOKEN` set: `env | grep -i anthropic` should list just the base URL and the auth token. Then repeat `claude -p "Reply with the single word OK"`.

**Problem. The request reaches the proxy and fails on the model name.**
- Error: `404 {"type":"error","error":{"type":"not_found_error","message":"model: <claude-model-alias>"}}`
- Cause: no mapping entry for the model string Claude Code sends — the value in the error message is the exact alias you must map.
- Solution: copy that string into `model_list[].model_name` in the proxy config, restart the proxy, and re-run the `curl` test with the same alias. If the CLI still sends a different alias, pin it explicitly with `ANTHROPIC_MODEL` in the same `env` block.

## Summary and next steps
You now have a local proxy on `127.0.0.1:8080` translating Anthropic-format calls to an OpenAI model, with Claude Code configured through `~/.claude/settings.json` and a repeatable smoke test. If you want to drive the same setup from a phone or compare it against other agents, see [How to Remotely Control Claude Code and Codex from Your Phone](https://ai-release.org/guides/kak-udalenno-upravlyat-claude-code-i-codex-s-telefona-n.html?utm_source=tg&utm_medium=channel&utm_campaign=guide_inline&utm_content=guide_to_guide) and [1loop vs Claude Code](https://ai-release.org/guides/1loop-ili-claude-code-chto-vybrat-dlya-koding-agenta-na.html?utm_source=tg&utm_medium=channel&utm_campaign=guide_inline&utm_content=guide_to_guide).

## FAQ

**Does a ChatGPT Plus or Pro subscription work as an API key?**
Not automatically — consumer plans and API credentials are separate products. Check your account page and your proxy's documentation for the supported credential type; if the plan exposes no key, use an API key instead.

**Will every Claude Code feature work through the proxy?**
No guarantee. Tool-calling, long-context handling and streaming depend on what your proxy and backend model support; verify each behaviour with a real task rather than assuming parity. Check the proxy documentation for the current support matrix.

**How do I switch back to Anthropic's endpoint?**
Remove the `env` block from `~/.claude/settings.json`, or run `unset ANTHROPIC_BASE_URL ANTHROPIC_AUTH_TOKEN`, then open a new shell and run `claude -p "ping"`.

**Where do I get the model name to put in the mapping?**
From the proxy's own request log: send one `curl` to `/v1/messages`, read the `model` field the CLI or curl sent, and map that exact string. Do not invent a name — an unmapped alias returns the `not_found_error` shown above.
