Command-line toolsAnthropic-compatible

How to use Claude Code with a custom Anthropic API endpoint

Point Claude Code at a third-party Anthropic-compatible API with ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN — shell, settings.json and VS Code examples plus fixes.

Last updated:Claude Code Official site

Copy-paste configuration

These are the three values the tool needs. Create the API key on the API Keys page of your CCSub dashboard.

ANTHROPIC_BASE_URL
https://www.ccsub.net(no /v1, no trailing slash)
ANTHROPIC_AUTH_TOKEN
sk-your-ccsub-key
Model (optional)
claude-sonnet-5(switch any time with /model)
macOS / Linux — append to ~/.zshrc (or ~/.bashrc)
echo 'export ANTHROPIC_BASE_URL="https://www.ccsub.net"' >> ~/.zshrc
echo 'export ANTHROPIC_AUTH_TOKEN="sk-your-key"' >> ~/.zshrc
source ~/.zshrc
claude

For model, use an ID such as claude-sonnet-5 — the full list of model IDs is on the models page. No key yet? Create an account first.

Steps at a glance

  1. 1

    Install Claude Code

    Install Node.js 18 or newer, then run npm install -g @anthropic-ai/claude-code@latest (prefix with sudo on macOS/Linux if npm needs it). Check it with claude --version.

  2. 2

    Create a CCSub API key

    Sign up for CCSub, open the API Keys page in the dashboard, create a key and copy the sk- value.

  3. 3

    Set two environment variables

    Set ANTHROPIC_BASE_URL to https://www.ccsub.net and ANTHROPIC_AUTH_TOKEN to your key, in your shell profile, as Windows user variables, or in the env block of ~/.claude/settings.json.

  4. 4

    Open a new terminal and run claude

    Close every terminal window, open a new one in your project folder and run claude. Accept the defaults on first launch.

  5. 5

    Confirm the route

    Run /status inside Claude Code and check that Anthropic base URL shows https://www.ccsub.net, then send a message and find it on the Usage page of the CCSub dashboard.

Claude Code is Anthropic's agentic coding tool. You run it as the Claude Code CLI in a terminal or through its VS Code and JetBrains extensions, and it only speaks the Anthropic Messages API. That keeps the setup short: no Claude account login and no code changes. You tell Claude Code where to send requests (ANTHROPIC_BASE_URL) and which credential to send (ANTHROPIC_AUTH_TOKEN). Anthropic documents this as connecting Claude Code to an "LLM gateway", and CCSub works the same way.

The two variables

What Claude Code needs
ANTHROPIC_BASE_URL
https://www.ccsub.netEndpoint root. No /v1, no trailing slash.
ANTHROPIC_AUTH_TOKEN
sk-your-ccsub-keyCreated on the API Keys page; sent as Authorization: Bearer.
ANTHROPIC_MODEL (optional)
claude-sonnet-5Pins a default model. You can also switch with /model.

The mistake we see most often is a /v1 suffix. Claude Code builds the request path itself, so https://www.ccsub.net becomes https://www.ccsub.net/v1/messages. If you enter https://www.ccsub.net/v1, the request goes to /v1/v1/messages and fails.

macOS and Linux

Check your shell with echo $SHELL. If it ends in zsh, edit ~/.zshrc; if it ends in bash, edit ~/.bashrc:

echo 'export ANTHROPIC_BASE_URL="https://www.ccsub.net"' >> ~/.zshrc
echo 'export ANTHROPIC_AUTH_TOKEN="sk-your-key"' >> ~/.zshrc
source ~/.zshrc

Run echo $ANTHROPIC_BASE_URL afterwards. If it prints the URL, the current window has picked it up.

Windows (PowerShell)

Store the values as user environment variables so every new terminal sees them:

[System.Environment]::SetEnvironmentVariable('ANTHROPIC_BASE_URL', 'https://www.ccsub.net', 'User')
[System.Environment]::SetEnvironmentVariable('ANTHROPIC_AUTH_TOKEN', 'sk-your-key', 'User')

Then close all PowerShell and terminal windows. Windows does not push new variables into windows that are already open, and the same goes for the integrated terminal inside VS Code or Cursor: quit the editor and start it again.

Using settings.json instead

If you would rather not touch system variables, put the values in Claude Code's own settings file, ~/.claude/settings.json (%USERPROFILE%\.claude\settings.json on Windows). It applies to every project, including background sessions:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://www.ccsub.net",
    "ANTHROPIC_AUTH_TOKEN": "sk-your-key"
  }
}

If the file already has other settings, merge the env block in and watch your commas. When the same variable is set both in your shell and in settings.json, the settings file wins — check it first if a shell change seems to do nothing.

For a single project, use .claude/settings.local.json. Do not put the key in a project's .claude/settings.json: that file is normally committed, so the key would travel with the repository. Project-level files also only apply after you accept the folder trust prompt.

The Claude Code extension for VS Code (and JetBrains)

The Claude Code extension for VS Code checks credentials before it launches, and that check does not read ~/.claude/settings.json. Anthropic's docs recommend VS Code's own user settings instead. Run Preferences: Open User Settings (JSON) and add:

{
  "claudeCode.environmentVariables": [
    { "name": "ANTHROPIC_BASE_URL", "value": "https://www.ccsub.net" },
    { "name": "ANTHROPIC_AUTH_TOKEN", "value": "sk-your-key" }
  ]
}

The JetBrains plugin runs the Claude Code CLI in the IDE's built-in terminal, so it reads the same shell variables and ~/.claude/settings.json as above. Restart the IDE after changing them so the terminal picks them up.

Start a session and confirm the route

cd ~/your-project
claude

Accept the defaults on first launch. Type /model to choose a model; the model field takes IDs such as claude-sonnet-5, and every available ID is listed on the models page.

Two ways to confirm traffic really goes through CCSub:

  1. Run /status. The Status tab should show an Anthropic base URL line with https://www.ccsub.net and an Auth token line naming ANTHROPIC_AUTH_TOKEN. If the base URL line is missing, the variable did not reach the session.
  2. Check the bill: send one message, then open Usage in the CCSub dashboard. If the request and its token counts show up, you are done.

Before opening Claude Code at all, you can test the URL and key with curl. A JSON body starting with {"id":"msg_ means everything works; a 401 means the key is wrong:

curl -sS -X POST "$ANTHROPIC_BASE_URL/v1/messages" \
  -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model":"claude-sonnet-5","max_tokens":16,"messages":[{"role":"user","content":"hi"}]}'

Multiple credentials fight each other. If you previously signed in with a claude.ai account and then set ANTHROPIC_AUTH_TOKEN, Claude Code shows a startup warning ending in auth may not work as expected (older versions say Auth conflict: Both a token ... and an API key ... are set). Requests use the token, but the stale login can cause odd auth behaviour. Run /logout inside Claude Code to clear it.

Claude Code skills: where they go, how to install them, what to check

A skill is a folder with a SKILL.md file that holds instructions for the AI. Type /my-skill to run it directly, or let the AI load it on its own when it's relevant.

"Plugin" below means a Claude Code plugin installed with /plugin, not the VS Code extension or JetBrains plugin covered above. It bundles skills, slash commands, subagents, hooks, MCP servers and other components into one install. Skills also work without a plugin.

Where skills live

  • Personal: ~/.claude/skills/my-skill/SKILL.md, available in every project on your machine. On Windows that's %USERPROFILE%\.claude\skills\my-skill\SKILL.md.
  • Project: .claude/skills/my-skill/SKILL.md, used only in that repository. Commit it and your team gets it too.
  • Plugin: once the plugin is enabled, its skills appear as /plugin-name:skill-name.

SKILL.md starts with frontmatter, and the opening --- has to be on the first line:

---
name: my-skill
description: What it does and when to use it
---

Step-by-step instructions go here.

The official docs only recommend description, and name defaults to the folder name. Tools such as npx skills require both fields, so write both and keep name the same as the folder. Lead description with the key use case, since the skill listing cuts it off at 1,536 characters.

Three ways to install

1. Copy the folder. Put the whole skill folder in one of the locations above. You don't need to restart Claude Code:

mkdir -p ~/.claude/skills
cp -r ./my-skill ~/.claude/skills/

2. Install a plugin from a marketplace with /plugin. Anthropic's official marketplace, claude-plugins-official, is added the first time you start an interactive terminal session, so you can install from it straight away:

/plugin install skill-creator@claude-plugins-official

If Claude Code says that marketplace isn't found, add it with /plugin marketplace add anthropics/claude-plugins-official and retry. Other marketplaces have to be added first. The install ID is <plugin>@<marketplace>; for example, the anthropics/skills repository registers as anthropic-agent-skills:

/plugin marketplace add anthropics/skills
/plugin install document-skills@anthropic-agent-skills

In a session, /plugin install opens the plugin's details first so you can review it and choose a scope. From your shell, claude plugin install <plugin>@<marketplace> installs to user scope by default. A plugin can run code with your user privileges, so only install ones you trust.

3. The third-party npx skills tool. npx skills comes from Vercel Labs and needs Node.js 22.20 or later. -a claude-code targets Claude Code. By default it installs into the current project's .claude/skills/; -g installs into ~/.claude/skills/ instead, and -y skips the confirmation prompts:

npx skills add vercel-labs/agent-skills --skill web-design-guidelines -g -a claude-code -y

When a skill doesn't load

  1. Check the layout. A skill must be a folder with SKILL.md inside and --- on line one. A single my-skill.md file won't show up in /skills.
  2. Check the list. Run /skills and look for it. If you created the skills folder mid-session, run /reload-skills. A plugin installed from your shell loads after /reload-plugins or in a new session.
  3. The AI doesn't use it on its own. Put the words you actually use into description, or start your message with /my-skill to run it directly.
  4. Look for errors. If the YAML doesn't parse, the skill still loads but with no fields set, so the AI can't match its description. Run claude --debug to see the parse error. On v2.1.233 or later you can also run claude plugin validate ~/.claude/skills.

Do you need to change anything for CCSub?

No. Skills are files Claude Code reads from your own disk, and requests still go to the ANTHROPIC_BASE_URL you set on this page. Three things to know:

  • Cost. For each skill the AI can invoke on its own, the name and description are in context on every turn and go out with each request. Once a skill is invoked, its SKILL.md content stays in the conversation. Those tokens are billed like the rest of the conversation. Delete skills you don't use, or highlight one in /skills, press Space until it's off and press Esc to save, which applies to this project only (plugin skills are managed in /plugin). For a skill you only run by hand, add disable-model-invocation: true and its description stays out of context.
  • claude.ai skills don't sync. With ANTHROPIC_AUTH_TOKEN, the skills enabled on your claude.ai account, including Anthropic's built-in pdf and xlsx, are not synced. If you need them, install skills locally as shown above.
  • Plugins that call a model themselves. claude-mem makes its own model calls to take notes and doesn't read Claude Code's ANTHROPIC_BASE_URL, so its own config needs the CCSub URL and key again, plus a model ID. See the claude-mem guide.

Skill and plugin guides on this site

Switching between providers

If you move between CCSub and other API providers, editing variables every time gets old. CC Switch is a desktop app that swaps Claude Code providers with one click, and CCSub is already in its preset list. For OpenAI's terminal agent, see the Codex CLI guide.

Who it's for

  • Developers who live in the terminal and want the AI to edit files and run commands directly.
  • People who rely on Claude Code's built-in features: subagents, MCP, hooks and slash commands.
  • Not comfortable with the command line? Use the Claude Code extension in VS Code (see above), or a GUI tool such as Cursor or Cline.

How billing works

Every turn in Claude Code resends the conversation so far, so input tokens grow over a long session. On CCSub, cache reads and writes for regular accounts are billed at the input price, which means /clear when you change topics and /compact for long threads are the simplest ways to keep usage down.

  • Pay-as-you-go: ¥1 buys $1 of credit that never expires. Each request is charged by its input and output tokens at the model's rate (see the models page).
  • Monthly plans: the day's quota is used first (it resets at 00:00 Beijing time), then your balance.
  • Not charged: requests that fail authentication (401) or hit an upstream 503 / 504.
  • Check it: every request's tokens and charge are listed on the Usage page in the dashboard.

Common errors and fixes

401 authentication_error: Missing or invalid API key

Cause:ANTHROPIC_AUTH_TOKEN is not set in this shell, the key was pasted with extra whitespace, or the key is disabled.

Fix:Run echo $ANTHROPIC_AUTH_TOKEN to check the value, make sure the key is enabled in the dashboard, then open a fresh terminal.

Stuck on “Connecting…”, Connection refused, or timeouts

Cause:The base URL has a /v1 suffix or a trailing slash, or a local proxy/VPN is intercepting terminal traffic.

Fix:Set ANTHROPIC_BASE_URL back to exactly https://www.ccsub.net and retry with the proxy client turned off.

API returned an empty or malformed response (HTTP 200)

Cause:The request path is wrong, so the server answers with a web page instead of an API response — usually an extra /v1 or /api in the base URL.

Fix:Use the bare https://www.ccsub.net with no path.

Claude Code still asks me to log in

Cause:The token is only in a project's .claude/settings.json or settings.local.json, which applies after the folder trust prompt, or the VS Code extension cannot see ~/.claude/settings.json.

Fix:Set the token in your shell or ~/.claude/settings.json; for the extension use claudeCode.environmentVariables.

402 insufficient_balance

Cause:Your balance does not cover the estimated cost of the request, or a monthly plan's daily quota is used up.

Fix:Top up your balance. Monthly plan quotas reset at 00:00 Beijing time (UTC+8); once the day's quota is spent, requests draw from your balance.

404 Unknown model

Cause:The model field contains a display name or a typo instead of a model ID.

Fix:Use the hyphenated ID, e.g. claude-sonnet-5, exactly as listed on the models page.

For more error messages and what they mean, see the error troubleshooting index. Installation and network issues are covered in the troubleshooting docs (Chinese).

FAQ

Should ANTHROPIC_BASE_URL end with /v1?

No. Claude Code appends /v1/messages itself, so use https://www.ccsub.net. Adding /v1 produces /v1/v1/messages and the request fails.

ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY?

Use ANTHROPIC_AUTH_TOKEN, as in the CCSub docs. It is sent as an Authorization: Bearer header and takes effect immediately without a login screen. ANTHROPIC_API_KEY needs a one-time approval in interactive mode, and a key you once declined is silently ignored. CCSub accepts either header.

I set the variables but Claude Code still talks to Anthropic. Why?

Terminals only read environment variables when they start, so open a new one. Inside Claude Code, run /status: if there is no Anthropic base URL line, the variable never reached the session.

How do I configure the Claude Code VS Code extension?

Anthropic's docs recommend VS Code's own user settings: run Preferences: Open User Settings (JSON) and add claudeCode.environmentVariables with ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN. Values in ~/.claude/settings.json reach the spawned process but not the extension's own login check.

What do I put as the model?

Pick one with /model inside a session, or pin a default by adding ANTHROPIC_MODEL (for example claude-sonnet-5) to the env block. The full list of model IDs is on the CCSub models page.

Further reading

Need a CCSub API key?

Sign up, create a key in the dashboard, and paste the values above into your tool. Pay-as-you-go balance does not expire — you only pay for the tokens you use.