# Claude Code ANTHROPIC_BASE_URL: Environment Variable Setup

Follow the 14 steps below to install Terminal, Git, and Node.js on Windows 11 or macOS, lift PowerShell's red-text script restriction, save QCode's endpoint URL and API key as permanent environment variables and Claude Code settings, and verify end-to-end connectivity with `curl.exe` in one shot.


**Short answer**: In Terminal on Windows 11 or macOS (Windows PowerShell on Windows), verify Git and Node.js LTS and run `Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser`, add `ANTHROPIC_BASE_URL` and `ANTHROPIC_AUTH_TOKEN` in **Edit environment variables for your account** (and if you also use Claude Code, add them to the `env` block in `%USERPROFILE%\.claude\settings.json`), then open a fresh terminal and verify with `curl.exe`.

| Item | Fill in |
|---|---|
| Anthropic endpoint (`ANTHROPIC_BASE_URL`) | `https://api.qcode.cc/api` |
| OpenAI-compatible endpoint (`OPENAI_BASE_URL`) | `https://api.qcode.cc/openai/v1` |
| Auth credential (`ANTHROPIC_AUTH_TOKEN`) | `cr_xxxxxxxx` |
| PowerShell execution policy command | `Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser` |
| Claude Code config file | `%USERPROFILE%\.claude\settings.json` |

Checked on 2026-11-22 · Windows Terminal 1.25.3131.0 / Git 2.56.1 / Node.js v26.13.1 · Windows 11


Almost every AI coding tool (such as Claude Code, the Anthropic SDK, Codex CLI, and OpenAI-compatible clients) relies on environment variables to decide which service to call and which key to send. If you only want automatic setup for Claude Code, you can also use the [one-click setup script](/docs/getting-started/one-click-install); if you want a solid Windows 11 command-line foundation from scratch or prefer to manage environment variables manually, follow the steps below (avoid mixing manual edits with the one-click script so they do not overwrite each other).


- **Applies to**: Windows 10 / 11 (64-bit) and macOS; the screenshots were taken on Windows 11
- **Software version**: Windows Terminal 1.25.3131.0 / Git 2.56.1 / Node.js v26.13.1 LTS (npm 11.20.0) / Windows PowerShell 5.1
- **Screenshots updated**: 2026-11
- **Time needed**: 15 minutes
- **You will need**: a QCode API key starting with `cr_`


> **On a Mac?** Run the same steps in Terminal. The screenshots show Windows PowerShell; on macOS, set a variable with `export NAME="value"` instead of `$env:NAME = "value"`, and read `%USERPROFILE%\` as `~/` in file paths. The **macOS / Linux / WSL and other ways to set them** section of this page has the commands that differ.


- Your PC runs Windows 10 / 11 (64-bit) or macOS, and you have permission to install software locally (installing Git and Node.js may trigger a User Account Control prompt)
- You have already signed up on QCode.cc and copied your `cr_` API key from the [Dashboard](https://qcode.cc/en/dashboard). No account yet? [Sign up for QCode](https://qcode.cc/en/auth/sign-up?utm_source=docs.qcode.cc&utm_medium=tut_before&utm_campaign=knowledge_base&src=docs-getting-started-environment-before) first, choose a plan on the [pricing page](https://qcode.cc/en/pricing?utm_source=docs.qcode.cc&utm_medium=tut_before&utm_campaign=knowledge_base&src=docs-getting-started-environment-before), and then create a key in the [Dashboard](https://qcode.cc/en/dashboard).
- Your PC can reach `git-scm.com`, `nodejs.org` (or a regional mirror), and `api.qcode.cc`
- Set aside about 15 uninterrupted minutes to install the tools in order and reopen Terminal to verify
- If you are on macOS, Linux, or WSL, jump straight to **macOS / Linux / WSL and other ways to set them** below


## Download and install

Before starting, here are the official download entry points and Windows build choices for the three core tools (Windows 11 already includes Terminal out of the box):

- **Windows Terminal**: Pre-installed on Windows 11; on Windows 10 (2004 and later), install from Microsoft Store (auto-updates), download the `.msixbundle` from [GitHub Releases](https://github.com/microsoft/terminal), or run `winget install Microsoft.WindowsTerminal`.
- **Git for Windows**: Visit the [git-scm.com Windows download page](https://git-scm.com/downloads/win) (which redirects to `https://git-scm.com/install/windows`), or download from [GitHub Releases](https://github.com/git-for-windows/git/releases). Pick `64-bit.exe` on 64-bit PCs (currently `Git-2.56.1-64-bit.exe`) or `arm64.exe` on ARM64 PCs; to install from the command line, run `winget install --id Git.Git -e --source winget` (a User Account Control prompt will appear).
- **Node.js LTS**: Visit the [Node.js download page](https://nodejs.org/en/download) (the Chinese page shown in the screenshot is [nodejs.org/zh-cn/download](https://nodejs.org/zh-cn/download)), select the **LTS** release (currently `v26.13.1 LTS`, bundled with npm `11.20.0`), and choose the `.msi` installer for beginners (pick x64 or ARM64); to install from the command line, run `winget install OpenJS.NodeJS.LTS`.

Network conditions vary slightly by region — pick your region first:

**Germany / Japan**

- Windows Terminal, Git for Windows, and Node.js have no regional restrictions — install directly via the official links above, Microsoft Store, or `winget`.
- To install both tools from the command line, run `winget install --id Git.Git -e --source winget` and `winget install OpenJS.NodeJS.LTS`, then close and reopen Terminal.


**Mainland China**

- **Node.js**: If direct access to `nodejs.org` is slow or drops, download the same LTS `.msi` installer from a domestic mirror such as `https://nodejs.cn/download` or `https://npmmirror.com/mirrors/node/`; after installation, you can also switch the npm registry to `https://registry.npmmirror.com` for faster package installs.
- **Git for Windows**: If GitHub Releases is unstable, download the 64-bit installer (`64-bit.exe`) from the Tsinghua mirror at `https://mirrors.tuna.tsinghua.edu.cn/github-release/git-for-windows/git/LatestRelease/`.
- **Windows security prompts**: If running `.exe` or `.msi` triggers "Windows protected your PC", click **More info** → **Run anyway**; when User Account Control pops up, click **Yes**.
- **QCode endpoint**: The steps below use the global endpoint `https://api.qcode.cc/api` by default. If it is unstable, users in Asia can switch to the Asia node `https://asia.qcode.cc/api` with the exact same key.


**Arab countries**

- Use the same channels as **Germany / Japan**: official installers, Microsoft Store, or `winget`.
- After installing Git and the Node.js `.msi`, make sure to close the old window and reopen Terminal so the updated `PATH` takes effect.


**Russia / Iran**

- Prefer the official download pages or `winget` for Git for Windows and Node.js LTS.
- If an installer download times out, check that your network connection is stable and retry; after installation, verify both tools in a freshly opened Terminal with `git --version` and `node --version`.


## Follow the screenshots: Windows 11, one step at a time

Each of the 14 steps below does one thing. The orange numbered markers on the screenshots match the circled numbers in the text one to one.



### Open Windows Terminal

Press the `Win` key at the bottom left of your keyboard to open the Start menu and type `Terminal` (in the Chinese Windows 11 screenshot, `终端`). Under Best match, find **Terminal** (`终端（应用）`) (①), then click **Open** (`打开`) on the right (②) or press Enter to launch it. Note that in Chinese Windows 11 Start Search, this app is named `终端` rather than `Windows 终端`.

![Press Win to search for Terminal in the Start menu, find the Terminal app under Best match, and click Open on the right](https://docs.qcode.cc/static/images/tut/environment/202611/zh/01-start-menu-terminal.webp)


Done right you will see: a dark-background Terminal window opens with a tab bar along the top.


**Stuck? Searching for Terminal does not find the app**

Windows 10 or stripped-down Windows builds may not include Windows Terminal pre-installed. Install it from Microsoft Store or GitHub as shown in **Download and install** above, or search for `Windows PowerShell` in the Start menu and open that directly for now.




### Confirm the tab is PowerShell, not CMD

Once Terminal opens, check two details: the top tab reads `Windows PowerShell` (①), and the command prompt on the far left starts with `PS` (②, such as `PS C:\Users\<your name>>`). If the tab says Command Prompt (`命令提示符`) and there is no `PS` prefix, you are in legacy CMD — click the downward arrow next to the tab bar and open a new **Windows PowerShell** tab.

![Windows Terminal window on first launch showing the Windows PowerShell tab at the top and a prompt starting with PS](https://docs.qcode.cc/static/images/tut/environment/202611/zh/02-terminal-powershell.webp)


Done right you will see: the top tab says `Windows PowerShell`, and the prompt before the cursor starts with `PS`.




### Download and install Git for Windows

Open the [official Git for Windows download page](https://git-scm.com/downloads/win) in your browser (it redirects automatically to `/install/windows`). Click the blue link at the top to download the latest 64-bit installer (①, currently `2.56.1`), double-click the `.exe` file, and click **Next** all the way through with the default options; or copy the command under **Using winget tool** (②) and run it in Terminal for a one-line install:

```powershell
winget install --id Git.Git -e --source winget
```

![Official Git for Windows download page with the latest 64-bit installer link at the top and the winget install command below](https://docs.qcode.cc/static/images/tut/environment/202611/zh/03-git-download-page.webp)


Done right you will see: the setup wizard reaches the Finish screen (or `winget` reports the installation completed) without exiting on an error.


**Stuck? A User Account Control prompt appears, or the official download is slow**

Click **Yes** when User Account Control pops up during Git installation; if you see "Windows protected your PC", click **More info** → **Run anyway**. Users in Mainland China experiencing slow downloads from the official site can use the Tsinghua mirror listed under **Mainland China** in **Download and install** above to download the 64-bit installer.




### Download and install Node.js LTS

Open the [official Node.js download page](https://nodejs.org/en/download) (the screenshot shows the Chinese version at `nodejs.org/zh-cn/download`). First confirm that the version selector at the top is set to an LTS release (①, currently `v26.13.1 LTS`), then click the green **Windows Installer (.msi)** (`Windows 安装程序(.msi)`) button at the bottom left (②). Double-click the `.msi` and finish with the default options (the installer adds Node.js to `PATH` by default). Once finished, close your open Terminal window completely and open a fresh one.

![Official Node.js download page with the LTS release selected at the top and the green Windows Installer (.msi) button at the bottom left](https://docs.qcode.cc/static/images/tut/environment/202611/zh/04-nodejs-download-page.webp)


Done right you will see: the `.msi` installer reports completion and closes, and you have opened a brand-new `Windows PowerShell` window.


**Stuck? The page shows a block of fnm commands by default — do I need to copy them?**

No. The upper section of the Node.js download page defaults to recommending `fnm` for version management, but for beginners the green **Windows Installer (.msi)** button at the bottom left is much simpler. If you prefer command-line installation, you can also run `winget install OpenJS.NodeJS.LTS`.




### Verify Git and Node.js versions and recognize the PowerShell red-text error

In the freshly opened `Windows PowerShell` window, run these three commands one by one:

```powershell
git --version
node --version
npm --version
```

Check the output: `git --version` prints `git version 2.56.1.windows.1` (①) and `node --version` prints `v26.13.1` (②), confirming both are installed and on `PATH`. On a fresh Windows 11 machine, `npm --version` usually produces a block of red text (③) stating that `npm.ps1` cannot be loaded because running scripts is disabled on this system (shown in Chinese in the screenshot as `无法加载文件 …npm.ps1，因为在此系统上禁止运行脚本`). Because `npm` runs through a `.ps1` script, Windows' default execution policy blocks it (Claude Code will hit the exact same error later). Nothing went wrong with your installation — the next two steps fix it immediately.

![Running git --version, node --version, and npm --version in Terminal: the first two print versions while npm triggers a red PowerShell script execution error](https://docs.qcode.cc/static/images/tut/environment/202611/zh/05-verify-git-node-npm-error.webp)


Done right you will see: both `git` and `node` print version numbers. If `npm --version` already prints a version (such as `11.20.0`) with no red text, your execution policy is already relaxed and you can skip the next two steps.


**Stuck? It says git or node is not recognized**

An already-open Terminal window does not automatically reload updated environment variables after installing new software. Close every open Terminal window completely, then launch Terminal again from the Start menu and rerun the commands above.




### Check the current PowerShell execution policy

In the same Terminal window, enter the command below and press Enter (①) to inspect the execution policy across all scopes:

```powershell
Get-ExecutionPolicy -List
```

Look at the `CurrentUser` row in the table (②). On a fresh Windows 11 system, all five scopes (`MachinePolicy`, `UserPolicy`, `Process`, `CurrentUser`, `LocalMachine`) default to `Undefined`, which resolves to the strictest policy, `Restricted` (blocking all local `.ps1` scripts).

![Running Get-ExecutionPolicy -List to inspect all five execution policy scopes, with CurrentUser defaulting to Undefined](https://docs.qcode.cc/static/images/tut/environment/202611/zh/06-exec-policy-list.webp)


Done right you will see: a two-column, five-row table where the `CurrentUser` row displays the current policy (by default `Undefined`).




### Allow local scripts for CurrentUser and verify npm

Run these three commands in order (**no administrator privileges required**):

```powershell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Get-ExecutionPolicy -Scope CurrentUser
npm --version
```

The first command (①) sets the policy for your user account to `RemoteSigned`. In Windows 11's built-in Windows PowerShell 5.1, this command **takes effect silently with no `[Y]/[N]` confirmation prompt** — it returns straight to the prompt, so do not type an extra `Y`. Next, run the second command to confirm it prints `RemoteSigned` (②); then run `npm --version` and it will print `11.20.0` cleanly (③) with no red text.

![Running Set-ExecutionPolicy RemoteSigned for CurrentUser, verifying it prints RemoteSigned, and running npm --version cleanly to print 11.20.0](https://docs.qcode.cc/static/images/tut/environment/202611/zh/07-exec-policy-fix.webp)


Done right you will see: `Get-ExecutionPolicy -Scope CurrentUser` prints `RemoteSigned`, and `npm --version` outputs the version number with no red error text.


**Stuck? Typing an extra Y threw red text, or a company PC says the policy is overridden**

If you typed `Y` and pressed Enter out of habit after the first command, PowerShell will report that `'Y'` is not recognized as a cmdlet. That does not affect the policy change that already succeeded — just run `Get-ExecutionPolicy -Scope CurrentUser` to confirm. On a corporate PC where Group Policy locks `MachinePolicy` or `UserPolicy`, contact IT, or run `Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process` to allow scripts temporarily in the current window only.




### Open the Windows Environment Variables dialog

Next, save QCode's endpoint URL and key as **permanent user-level environment variables** so every future terminal, IDE, and SDK picks them up automatically. Press `Win`, search for **Edit environment variables for your account** (in Chinese Windows 11, `编辑帐户的环境变量`), and open it — or press `Win+R`, enter `rundll32 sysdm.cpl,EditEnvironmentVariables`, and press Enter. This dialog **does not require administrator privileges**.

In the **Environment Variables** (`环境变量`) dialog, the upper half is the **User variables** (`用户变量`) section for your account (①). Click **New...** (`新建(N)...`) directly below that section (②) to add the first variable.

![Environment Variables dialog showing the User variables section in the upper half and the New... button directly beneath it](https://docs.qcode.cc/static/images/tut/environment/202611/zh/08-env-dialog-overview.webp)


Done right you will see: the **Environment Variables** window opens and the **New...** button under **User variables** is clickable (the System variables buttons in the lower half being grayed out is normal).




### Add the user variable ANTHROPIC_BASE_URL

In the **New User Variable** (`新建用户变量`) popup, fill in:

- **Variable name** (`变量名(N):`) (①): `ANTHROPIC_BASE_URL`
- **Variable value** (`变量值(V):`) (②): `https://api.qcode.cc/api` (switch to `https://asia.qcode.cc/api` if it is unstable)

Double-check that the URL ends at `/api` with **no trailing slash**, then click **OK** (`确定`) (③).

![New User Variable dialog with Variable name set to ANTHROPIC_BASE_URL, Variable value set to https://api.qcode.cc/api, and the OK button](https://docs.qcode.cc/static/images/tut/environment/202611/zh/09-env-dialog-new-var.webp)


Done right you will see: the **New User Variable** popup closes and a new `ANTHROPIC_BASE_URL` row appears in the User variables list.




### Add the user variable ANTHROPIC_AUTH_TOKEN and save

Click **New...** (`新建(N)...`) under **User variables** again and add the second variable the same way:

- **Variable name** (`变量名(N):`): `ANTHROPIC_AUTH_TOKEN`
- **Variable value** (`变量值(V):`): paste your QCode API key (starting with `cr_`, such as `cr_xxxxxxxx`)

Click **OK** to return to the main dialog, verify that both `ANTHROPIC_AUTH_TOKEN` (masked in the screenshot) and `ANTHROPIC_BASE_URL` appear alphabetically at the top of the list (①), and confirm there is no leftover `ANTHROPIC_API_KEY`. Finally, be sure to click **OK** (`确定`) at the bottom of the dialog (②) so Windows actually saves your changes.

![User variables list showing both ANTHROPIC_AUTH_TOKEN (masked) and ANTHROPIC_BASE_URL at the top, with the OK button at the bottom of the dialog](https://docs.qcode.cc/static/images/tut/environment/202611/zh/10-env-dialog-added.webp)


Done right you will see: both variables appear at the top of the **User variables** list, and the dialog closes cleanly after you click **OK** at the bottom.


**Need an API key?**

If you do not have a QCode account yet, [Sign up for QCode](https://qcode.cc/en/auth/sign-up?utm_source=docs.qcode.cc&utm_medium=tut_key_step&utm_campaign=knowledge_base&src=docs-getting-started-environment-key) first. If you prefer to pay by actual usage, buy a [Pay-as-you-go Pack](https://qcode.cc/en/pay-as-you-go?utm_source=docs.qcode.cc&utm_medium=tut_key_step&utm_campaign=knowledge_base&src=docs-getting-started-environment-key) first, then create a key in the [Dashboard](https://qcode.cc/en/dashboard) and paste the entire string starting with `cr_` into the **Variable value** field. You can pay by credit/debit card (Visa / Mastercard), Apple Pay / Google Pay, or cryptocurrency — see [Payment methods](/docs/reference/payment-methods).




### Open the Claude Code config directory .claude

If you plan to use Claude Code next, you can also write the settings into `.claude\settings.json` inside your user folder. Press `Win+R`, type `%USERPROFILE%\.claude`, and press Enter (if Windows says the path cannot be found, create a new folder named `.claude` under `C:\Users\<your name>` first).

In File Explorer, confirm the address bar shows `C:\Users\<your name>\.claude` (①). Folders starting with `.` are visible by default on Windows, so you do not need to enable **Hidden items** under **View**. Next, create or locate `settings.json` inside that folder (②).

![File Explorer open to the .claude folder under the user profile directory, showing the path in the address bar and settings.json in the file list](https://docs.qcode.cc/static/images/tut/environment/202611/zh/11-explorer-claude-dir.webp)


Done right you will see: File Explorer is inside the `.claude` folder and contains a file named `settings.json` (confirm the extension is `.json`, not `.json.txt`).


**Stuck? The new file became settings.json.txt**

In File Explorer's top toolbar, click **View** → **Show** → check **File name extensions**, then remove the trailing `.txt`. You can also run these two lines in PowerShell to create both the folder and an empty file automatically:

```powershell
New-Item -ItemType Directory -Path "$env:USERPROFILE\.claude" -Force
New-Item -ItemType File -Path "$env:USERPROFILE\.claude\settings.json" -Force
```




### Check the env block in settings.json with Notepad

Right-click `settings.json`, open it with **Notepad** (`记事本`), paste the standard JSON below (replacing `cr_xxxxxxxx` with your own key), and press `Ctrl+S` to save:

```json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.qcode.cc/api",
    "ANTHROPIC_AUTH_TOKEN": "cr_xxxxxxxx"
  }
}
```

Verify both fields inside `"env"`: `ANTHROPIC_BASE_URL` ends at `/api` with no trailing slash (①), and `ANTHROPIC_AUTH_TOKEN` contains your full `cr_` key (②, masked in the screenshot). Also make sure `ANTHROPIC_API_KEY` is **not** in this file — keep `ANTHROPIC_AUTH_TOKEN` as the only credential.

![settings.json open in Notepad showing ANTHROPIC_BASE_URL and masked ANTHROPIC_AUTH_TOKEN inside the env block, with no ANTHROPIC_API_KEY](https://docs.qcode.cc/static/images/tut/environment/202611/zh/12-notepad-settings-json.webp)


Done right you will see: the JSON uses straight double quotes, matching braces, and no trailing commas or comments, and the unsaved indicator in the title bar disappears after saving.


**Stuck? The file already has other settings in it**

If `settings.json` already contains other keys, do not overwrite the whole file — simply add the `"env": { ... }` block alongside the existing top-level keys inside `{ ... }`, separated by commas. Remember `settings.json` is strict JSON and does not allow `//` comments.




### Open a new Terminal window to verify user environment variables

Already-open Terminal windows on Windows do not automatically pick up newly saved variables. Close the old window, open a fresh **Terminal** from the Start menu, and run these three commands:

```powershell
echo $env:ANTHROPIC_BASE_URL
$env:ANTHROPIC_AUTH_TOKEN.Length
[string]::IsNullOrEmpty($env:ANTHROPIC_API_KEY)
```

Check all three lines of output: `ANTHROPIC_BASE_URL` echoes `https://api.qcode.cc/api` verbatim (①); `$env:ANTHROPIC_AUTH_TOKEN.Length` prints the character length of your key (for example `67`, confirming it is non-empty without printing the secret in plain text, ②); and the last command returns `True` (③), confirming no conflicting `ANTHROPIC_API_KEY` is left in your environment.

![Checking environment variables in a new Windows Terminal window: ANTHROPIC_BASE_URL prints https://api.qcode.cc/api, ANTHROPIC_AUTH_TOKEN has non-zero length, and ANTHROPIC_API_KEY check returns True](https://docs.qcode.cc/static/images/tut/environment/202611/zh/13-verify-env-vars.webp)


Done right you will see: Terminal outputs `https://api.qcode.cc/api`, a number greater than 0, and `True`, in that order.


**Stuck? The first line is blank, or the third line returns False**

A blank first line usually means you forgot to close and reopen Terminal, or forgot to click **OK** at the bottom of the **Environment Variables** dialog earlier. If the third line returns `False`, you have an old `ANTHROPIC_API_KEY` set — go back to the **Environment Variables** dialog, delete it, and reopen Terminal to re-check.




### Verify network, path, and end-to-end reply with curl.exe

Finally, run a connectivity and end-to-end reply test using Windows' built-in `curl.exe`. In the same `Windows PowerShell` window, run these two commands in order (in PowerShell 5.1, you must use `curl.exe` and `-o NUL` rather than `curl` and `/dev/null`):

```powershell
curl.exe -s -o NUL -w "%{http_code}\n" -H "Authorization: Bearer $env:ANTHROPIC_AUTH_TOKEN" https://api.qcode.cc/v1/models
```

```powershell
$body = '{"model":"claude-opus-5-5","max_tokens":32,"messages":[{"role":"user","content":"Reply with exactly: OK"}]}'
$body | curl.exe -s -X POST "$env:ANTHROPIC_BASE_URL/v1/messages" -H "x-api-key: $env:ANTHROPIC_AUTH_TOKEN" -H "anthropic-version: 2023-06-01" -H "content-type: application/json" --data-binary "@-"
```

Check both outputs: the first request hits `/v1/models` with your Bearer token and prints status code `200` (①); the second pipes the JSON body to `$env:ANTHROPIC_BASE_URL/v1/messages` and returns a JSON response containing `"text":"OK"` (②). Seeing both confirms your network, endpoint path, and key are all working.

![Verifying QCode connectivity with curl.exe in PowerShell: /v1/models returns HTTP 200 and the end-to-end /v1/messages request returns a JSON response containing text OK](https://docs.qcode.cc/static/images/tut/environment/202611/zh/14-verify-curl.webp)


Done right you will see: the first command prints only `200`, and the second returns full JSON containing `"text":"OK"`, with no `401`, `404`, or path error.


**Stuck? It returned 401, 404, or a wall of HTML**

`401` means the key is invalid or missing characters — double-check the `cr_` prefix and trim any leading/trailing spaces. `404` usually means an extra trailing `/` on `ANTHROPIC_BASE_URL` or a typo in the path. A wall of webpage HTML means no key was attached (`$env:ANTHROPIC_AUTH_TOKEN` is empty) — go back one step and make sure the variables are loaded.




## Verify it works

When all five checks below match, your Windows 11 development environment and QCode connection are ready:

- `git --version`, `node --version`, and `npm --version` all print version numbers with no red errors;
- `Get-ExecutionPolicy -Scope CurrentUser` outputs `RemoteSigned`;
- In a freshly opened Terminal, `echo $env:ANTHROPIC_BASE_URL` prints `https://api.qcode.cc/api` (or `https://asia.qcode.cc/api`), `$env:ANTHROPIC_AUTH_TOKEN.Length` is greater than 0, and `[string]::IsNullOrEmpty($env:ANTHROPIC_API_KEY)` returns `True`;
- `curl.exe` against `/v1/models` returns `200`, and the end-to-end request to `$env:ANTHROPIC_BASE_URL/v1/messages` returns JSON containing `"text":"OK"`;
- Opening [probe.qcode.cc](https://probe.qcode.cc) and entering the same `cr_` key shows the test request you just sent.


### All done

Your Windows 11 command-line environment, environment variables, and QCode connectivity are set up and verified. Next you can:

- [Install Claude Code (Installation Guide)](/docs/getting-started/installation)
- [One-Click Setup Script](/docs/getting-started/one-click-install)
- [Endpoints and API Formats](/docs/getting-started/endpoints-and-api-paths)
- [Chinese Models Setup](/docs/usage/cn-models)
- Next: compare plans on the [pricing page](https://qcode.cc/en/pricing?utm_source=docs.qcode.cc&utm_medium=tut_done&utm_campaign=knowledge_base&src=docs-getting-started-environment-done)
- Return to the [Dashboard](https://qcode.cc/en/dashboard) to check usage and balance


## Common errors

| Error message | Why | What to do |
|---|---|---|
| `npm : File C:\Program Files\nodejs\npm.ps1 cannot be loaded because running scripts is disabled on this system.` | Windows 11 defaults PowerShell's execution policy to `Undefined` (effectively `Restricted`), blocking local scripts such as `npm.ps1` and `claude.ps1` (shown in Chinese Windows as `无法加载文件 … 禁止运行脚本`) | Run `Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser` in PowerShell (no admin rights needed), then verify `Get-ExecutionPolicy -Scope CurrentUser` returns `RemoteSigned` |
| `Y : The term 'Y' is not recognized as the name of a cmdlet, function, script file, or operable program.` | Changing execution policy with `-Scope CurrentUser` in Windows PowerShell 5.1 succeeds silently with no confirmation prompt, so typing an extra `Y` runs it as a command | The policy is already active — ignore this red error and verify with `Get-ExecutionPolicy -Scope CurrentUser` and `npm --version` |
| `Warning: Failed to open the file /dev/null: The system cannot find the path specified` | Copying a Linux/macOS `curl -o /dev/null` command directly into Windows PowerShell fails because Windows has no `/dev/null` (and `curl` is an alias for `Invoke-WebRequest`) | Use `curl.exe` and replace `-o /dev/null` with `-o NUL`; when testing QCode, pipe the JSON via `--data-binary "@-"` as shown above |
| `{"error":{"message":"Invalid or missing API key","type":"invalid_request_error","code":"invalid_api_key"}}` | Calling `https://api.qcode.cc/v1/models` without a key (or with an empty `$env:ANTHROPIC_AUTH_TOKEN`), or with an invalid key, returns HTTP 401 with this JSON error | Confirm `$env:ANTHROPIC_AUTH_TOKEN.Length` is greater than 0 in a new Terminal, pass `-H "Authorization: Bearer $env:ANTHROPIC_AUTH_TOKEN"` to `curl.exe`, and run the `/v1/messages` end-to-end check; if the message says the key is disabled or has expired, switch to the currently active API key in your console |

## FAQ

### What happens when my key expires?

Two cases:

- A **personal plan** key cannot be renewed when it expires — you must start a new plan and switch to a new key;
- A **pay-as-you-go pack** key automatically resumes working when you buy another pack after it expires.

After switching to a new key, return to the **Environment Variables** dialog to update `ANTHROPIC_AUTH_TOKEN` (and if you also configured `%USERPROFILE%\.claude\settings.json`, update that too and reopen Terminal).

### Do I need to set both user environment variables and `settings.json`? Which takes precedence?

- **Windows user environment variables** apply globally to all CLI tools, IDEs, and SDKs (Claude Code, Anthropic SDK, Python/Node scripts, etc.);
- **The `env` block in `%USERPROFILE%\.claude\settings.json`** applies only to Claude Code.

If both define the same variable, the environment variable inherited by the process at startup takes precedence over the config file. Keep both in sync — or maintain only the one you actually use — so you do not update a key in one place while an older key stays in the other and causes 401 errors.

### Why didn't my environment variable changes take effect?

Already-open Terminal, VS Code, or editor windows on Windows do not reload newly saved user variables automatically. Make sure you clicked **OK** at the bottom of the **Environment Variables** dialog, then **close your terminal or editor completely and reopen it** (do not just minimize it). If edits to `settings.json` do not apply, check for missing commas, curly quotes, or comments.

### Why can't I paste Linux `curl` commands directly into PowerShell?

Windows PowerShell 5.1 differs in three ways: first, `curl` is an alias for `Invoke-WebRequest`, so you must explicitly invoke `curl.exe`; second, Windows has no `/dev/null`, so write `-o NUL`; third, passing `-d '{"model":...}'` directly strips double quotes and breaks JSON parsing — assigning the payload to `$body` and piping it into `--data-binary "@-"` works reliably.

### What if the terminal says `'$env:ANTHROPIC_BASE_URL' is not recognized as an internal or external command`?

You are in legacy Command Prompt (CMD) instead of PowerShell. Check the tab title and prompt prefix to make sure it starts with `PS`, then switch to a `Windows PowerShell` tab and run the command again.

### I already ran the one-click setup script — do I still need to do this manually?

No need to redo it. The one-click setup script has already written the required configuration for Claude Code; if you manually edit user variables or `settings.json` later, whichever value you saved last takes effect. For quick automated setup, see [One-Click Setup Script](/docs/getting-started/one-click-install).

## The two core variables and per-tool reference

Connecting to Claude-family models (Claude Code and the official Anthropic Python / TypeScript SDKs) requires only two core environment variables:

- **`ANTHROPIC_BASE_URL`**: The endpoint URL ending at `/api` (`https://api.qcode.cc/api`). The SDK appends `/v1/messages` automatically. **Do not include a trailing slash** — `https://api.qcode.cc/api/` turns into `//v1/messages` and returns `404`.
- **`ANTHROPIC_AUTH_TOKEN`**: Your QCode.cc key, starting with `cr_`, created in the [QCode.cc Dashboard](https://qcode.cc/en/dashboard).

> **About `ANTHROPIC_AUTH_TOKEN`**: By QCode convention, the relay key goes into `ANTHROPIC_AUTH_TOKEN` (rather than `ANTHROPIC_API_KEY`, which the official Anthropic API uses), and Claude Code sends it via `Authorization: Bearer`. When configuring Claude Code, remove `ANTHROPIC_API_KEY` and keep only `ANTHROPIC_AUTH_TOKEN`. If a third-party tool only recognizes `ANTHROPIC_API_KEY`, entering the same `cr_` key there works too.

Different tools read different variable names and URL prefixes — match yours below:

| Tool | Environment variables | Value |
|---|---|---|
| Claude Code | `ANTHROPIC_BASE_URL`<br>`ANTHROPIC_AUTH_TOKEN` | `https://api.qcode.cc/api`<br>`cr_xxxxxxxx` |
| Anthropic SDK (Python / JS) | `ANTHROPIC_BASE_URL`<br>`ANTHROPIC_AUTH_TOKEN` | `https://api.qcode.cc/api`<br>`cr_xxxxxxxx` |
| Codex CLI | `base_url` in `~/.codex` config | `https://api.qcode.cc/openai` |
| OpenAI-compatible tools | `OPENAI_BASE_URL`<br>`OPENAI_API_KEY` | `https://api.qcode.cc/openai/v1`<br>`cr_xxxxxxxx` |
| Gemini / Antigravity (currently unavailable) | base URL | `https://api.qcode.cc/gemini` |

A few notes:

- **Codex CLI** does not read `OPENAI_BASE_URL`; it reads `base_url` from `~/.codex`. Because it uses the OpenAI Responses protocol and appends paths itself, end the URL at `/openai` with **no `/v1`**. See [Endpoints and API Formats](/docs/getting-started/endpoints-and-api-paths) for details.
- **OpenAI-compatible tools** (official OpenAI SDK, LangChain, generic clients) read `OPENAI_BASE_URL` and `OPENAI_API_KEY`, ending at `/openai/v1`.
- **Gemini / Antigravity** (QCode does not offer Gemini for now; protocol reference only): ends at `/gemini`, and the SDK appends `/v1beta/`.
- **One key across protocols**: Your `cr_` key is protocol-agnostic — `/api` speaks Anthropic, `/openai/v1` speaks OpenAI. Switching tools only means changing the URL, never the key.

### Available models

Once your endpoint is set, choose a model ID matching your tool's protocol (see [Endpoints and API Formats](/docs/getting-started/endpoints-and-api-paths) for details, and [qcode.cc/models](https://qcode.cc/en/models) for the live model list):

- **Claude family** (5-series daily default): `claude-opus-5-5` (1M, recommended flagship), `claude-sonnet-5-5` (1M, balanced), `claude-fable-5-2` / `claude-fable-5-1` / `claude-fable-5` (1M, top tier), `claude-sonnet-4-6` / `claude-opus-4-8` / `claude-opus-4-7` (previous generation, still available), `claude-haiku-5-5` (1M, fastest)
- **GPT family**: `gpt-6.2-sol` (recommended), `gpt-6.2-astra`, and `gpt-6-sol`
- **Gemini family**: Not currently offered by QCode — use Claude, GPT, or Chinese models
- **Chinese models** (GLM / Kimi / DeepSeek / Qwen): `qwen3.8-max`, `deepseek-v4.1-flash`, `deepseek-v4-pro`, `kimi-k3.1-pro`, `kimi-k3`, `glm-5.3`, and more — see [Chinese Models Setup](/docs/usage/cn-models)
- **Images**: `gpt-image-2` (endpoint `https://api.qcode.cc/qcode-img/v1`)

> **Claude Code context length**: Claude Code gives Claude 5.5 models and Fable 5.2 a **1M** window by default; to pin a **200K** window, set `CLAUDE_CODE_DISABLE_1M_CONTEXT=1`.

## macOS / Linux / WSL and other ways to set them

If you use macOS, Linux, or Windows WSL — or want to isolate keys per project — pick the configuration scope that fits your workflow:

1. **Shell rc file (persistent, global)**: Add to `~/.zshrc` (macOS / zsh) or `~/.bashrc` (Linux / WSL / bash) so every new terminal loads them automatically:

```bash
echo 'export ANTHROPIC_BASE_URL="https://api.qcode.cc/api"' >> ~/.zshrc
echo 'export ANTHROPIC_AUTH_TOKEN="cr_xxxxxxxx"' >> ~/.zshrc
source ~/.zshrc
```

For bash, replace `~/.zshrc` with `~/.bashrc`.

2. **Project `.env` file (persistent, per project)**: Place a `.env` file in the project root so it only affects that project — handy when different projects use different keys:

```bash
ANTHROPIC_BASE_URL=https://api.qcode.cc/api
ANTHROPIC_AUTH_TOKEN=cr_xxxxxxxx
```

> `.env` contains your key — always add it to `.gitignore` and never commit it to a repository.

3. **Tool-specific config files (per tool)**: Such as Claude Code's `~/.claude/settings.json` (`%USERPROFILE%\.claude\settings.json` on Windows), Codex CLI's `~/.codex`, or an editor plugin's settings panel. These apply only to that tool.

**Persistent vs. temporary**: All three options above are persistent. If you only want to test in the **current terminal session** (cleared as soon as you close the window), run:

```bash
# Temporary setup on macOS / Linux / WSL
export ANTHROPIC_BASE_URL="https://api.qcode.cc/api"
export ANTHROPIC_AUTH_TOKEN="cr_xxxxxxxx"
```

```powershell
# Temporary setup in Windows PowerShell
$env:ANTHROPIC_BASE_URL = "https://api.qcode.cc/api"
$env:ANTHROPIC_AUTH_TOKEN = "cr_xxxxxxxx"
```

> **Precedence note**: System / shell environment variables inherited at process startup take precedence over config files. Remember to run `source` or open a new terminal after editing shell rc files; when the same variable is set in multiple places, whichever value the process actually inherits wins.

On macOS / Linux / WSL, verify with bash `curl` (confirm `$ANTHROPIC_AUTH_TOKEN` is non-empty, then check the status code and end-to-end reply):

```bash
echo "$ANTHROPIC_BASE_URL"
curl -s -o /dev/null -w '%{http_code}\n' \
  -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
  https://api.qcode.cc/v1/models
```

```bash
curl -X POST "$ANTHROPIC_BASE_URL/v1/messages" \
  -H "x-api-key: $ANTHROPIC_AUTH_TOKEN" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model":"claude-opus-5-5","max_tokens":64,"messages":[{"role":"user","content":"ping"}]}'
```

**Reading the status codes**: A `200` with a valid key plus a normal JSON reply from the second command means your network, endpoint, and key are all ready. `401` means the key is invalid or not passed properly (check the full `cr_` prefix). `404` usually means a wrong path prefix or an extra trailing `/`.

## Other endpoints and regional nodes

QCode offers three ingress domains with identical capabilities; your single `cr_` key works across all of them:

| Node | Anthropic-compatible (Claude Code / SDK) | OpenAI-compatible | Codex CLI |
|---|---|---|---|
| Global (default) | `https://api.qcode.cc/api` | `https://api.qcode.cc/openai/v1` | `https://api.qcode.cc/openai` |
| Asia | `https://asia.qcode.cc/api` | `https://asia.qcode.cc/openai/v1` | `https://asia.qcode.cc/openai` |
| North America / Europe | `https://us.qcode.cc/api` | `https://us.qcode.cc/openai/v1` | `https://us.qcode.cc/openai` |

By default, use `https://api.qcode.cc`; if it is unstable, switch to `https://asia.qcode.cc` (Asia) or `https://us.qcode.cc` (North America / Europe). See [Endpoints and API Formats](/docs/getting-started/endpoints-and-api-paths) for details.

> Want to inspect the status and latency of every request? Requests across all ingress domains report to [probe.qcode.cc](https://probe.qcode.cc) — enter your `cr_` key to view them.

## Useful variables when connecting to a gateway

When Claude Code connects through a third-party gateway (including QCode), the official environment variables below are helpful for default model selection and troubleshooting. Definitions follow the [official environment variables reference](https://code.claude.com/docs/en/env-vars) and the [LLM gateway connection guide](https://code.claude.com/docs/en/llm-gateway-connect):

| Variable | When to use it |
|---|---|
| `ANTHROPIC_DEFAULT_MODEL` | Sets the **default model for new sessions** (since 2.1.236). Unlike `ANTHROPIC_MODEL`, an in-session `/model` choice overrides it and persists across restarts, whereas `ANTHROPIC_MODEL` is forced on every launch |
| `CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1` | Lets the `/model` picker query the gateway's model list (off by default so shared-key gateways do not expose models you lack access to). Against QCode, only **Claude-family IDs** appear; **Chinese models will not appear**, so keep using `ANTHROPIC_MODEL` or `ANTHROPIC_DEFAULT_MODEL` for them |
| `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` | Strips the `anthropic-beta` header and beta tool fields. Enable this if the gateway returns a 400 error like `Unexpected value(s) … anthropic-beta` |
| `CLAUDE_CODE_AUTO_MODE_SERVER=0` | Stops auto mode from requesting server-side review and runs Claude Code's local classifier requests directly (QCode does not return server-side review results). Once set, the incompatibility notice disappears and the first action requiring review is no longer paused. If QCode's one-click setup script already added it, you do not need to add it manually. Officially marked temporary and may be removed in a future release — see [Feature Availability](/docs/reference/feature-availability) |
| `CLAUDE_CODE_DISABLE_ARTIFACT=1` | Disables the Artifact tool (once set, it cannot be re-enabled in the settings UI). If you are stuck on Claude Code 2.1.265–2.1.267, hit gateway 400 rejections on tool schemas, and cannot upgrade to ≥2.1.268 yet, use this as a temporary workaround |
| `CLAUDE_CODE_ATTRIBUTION_HEADER=0` | Removes the attribution block (client version and prompt fingerprint) from the top of the system prompt. Read the official documentation before deciding whether to disable it |

## Related docs

- [Installation Guide](/docs/getting-started/installation) — Install and launch Claude Code
- [One-Click Setup Script](/docs/getting-started/one-click-install) — Configure Claude Code with a single command
- [Endpoints and API Formats](/docs/getting-started/endpoints-and-api-paths) — Protocol URLs and ingress domains
- [How to Choose a Plan](/docs/getting-started/choose-a-plan) — Pick the right QCode plan and get a `cr_` key
- [Chinese Models Setup](/docs/usage/cn-models) — Chinese model IDs available on the OpenAI-compatible endpoint
- [Feature Availability](/docs/reference/feature-availability) — Claude Code feature support and gateway variable reference