Claude Code

更新时间:
复制 MD 格式

Claude Code is a command-line AI coding assistant developed by Anthropic. Connect it to Alibaba Cloud Model Studio using Pay-as-you-go, Coding Plan, Token Plan Personal Edition, or Token Plan Team Edition.

Install Claude Code

Install

macOS

  1. Install or update Node.js (v18.0 or later).

  2. Run the following command to install Claude Code.

    npm install -g @anthropic-ai/claude-code
  3. Verify the installation. A version number in the output confirms success.

    claude --version

Windows

To use Claude Code on Windows, install WSL or Git for Windows, then run the following command in WSL or Git Bash.

npm install -g @anthropic-ai/claude-code
For more details, see the Windows setup guide in the official Claude Code documentation.

Skip login verification

Edit or create ~/.claude.json (Windows path: C:\Users\<username>\.claude.json), and set hasCompletedOnboarding to true to skip the official Anthropic login verification.

{
  "hasCompletedOnboarding": true
}

Configure access credentials

Create ~/.claude/settings.json (Windows path: C:\Users\<username>\.claude\settings.json) and add the configuration for your billing plan.

Token Plan Personal Edition

Replace YOUR_API_KEY with the Token Plan Personal Edition dedicated API Key. For available models, see supported models for Token Plan Personal Edition.

{
    "env": {
        "ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY",
        "ANTHROPIC_BASE_URL": "https://token-plan.cn-beijing.maas.aliyuncs.com/apps/anthropic",
        "ANTHROPIC_MODEL": "qwen3.8-max",
        "ANTHROPIC_DEFAULT_HAIKU_MODEL": "qwen3.6-flash",
        "ANTHROPIC_DEFAULT_SONNET_MODEL": "qwen3.8-max",
        "ANTHROPIC_DEFAULT_OPUS_MODEL": "qwen3.8-max",
        "CLAUDE_CODE_SUBAGENT_MODEL": "qwen3.7-max",
        "CLAUDE_CODE_MAX_CONTEXT_TOKENS": "983616"
    }
}

Token Plan Team Edition

Replace YOUR_API_KEY with the Token Plan Team Edition dedicated API Key. For available models, see supported models for Token Plan Team Edition.

{
    "env": {
        "ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY",
        "ANTHROPIC_BASE_URL": "https://token-plan.cn-beijing.maas.aliyuncs.com/apps/anthropic",
        "ANTHROPIC_MODEL": "qwen3.8-max",
        "ANTHROPIC_DEFAULT_HAIKU_MODEL": "qwen3.6-flash",
        "ANTHROPIC_DEFAULT_SONNET_MODEL": "qwen3.8-max",
        "ANTHROPIC_DEFAULT_OPUS_MODEL": "qwen3.8-max",
        "CLAUDE_CODE_SUBAGENT_MODEL": "qwen3.7-max",
        "CLAUDE_CODE_MAX_CONTEXT_TOKENS": "983616"
    }
}

Coding Plan

Replace YOUR_API_KEY with the Coding Plan dedicated API Key. For available models, see supported models for Coding Plan.

{
    "env": {
        "ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY",
        "ANTHROPIC_BASE_URL": "https://coding.dashscope.aliyuncs.com/apps/anthropic",
        "ANTHROPIC_MODEL": "qwen3.7-plus",
        "ANTHROPIC_DEFAULT_HAIKU_MODEL": "qwen3.7-plus",
        "ANTHROPIC_DEFAULT_SONNET_MODEL": "qwen3.7-plus",
        "ANTHROPIC_DEFAULT_OPUS_MODEL": "qwen3.7-plus",
        "CLAUDE_CODE_SUBAGENT_MODEL": "qwen3.7-plus"
    }
}

Pay-as-you-go

Replace YOUR_API_KEY with the Alibaba Cloud Model Studio API Key. For available models, see Anthropic-compatible API.

Set ANTHROPIC_BASE_URL based on the region. The API key must match the selected region:

  • China North 2 (Beijing): https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/apps/anthropic

  • Singapore: https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic. Replace WorkspaceId with your actual Get the Workspace ID.

{
    "env": {
        "ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY",
        "ANTHROPIC_BASE_URL": "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/apps/anthropic",
        "ANTHROPIC_MODEL": "qwen3.7-max",
        "ANTHROPIC_DEFAULT_HAIKU_MODEL": "qwen3.6-flash",
        "ANTHROPIC_DEFAULT_SONNET_MODEL": "qwen3.7-max",
        "ANTHROPIC_DEFAULT_OPUS_MODEL": "qwen3.7-max",
        "CLAUDE_CODE_SUBAGENT_MODEL": "qwen3.7-max"
    }
}

After saving the configuration, open a new terminal and run claude "hello". A response from the model confirms the setup is working. To verify further, run /status in Claude Code and check that ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN point to the Model Studio address.

Configure Context Window Size

Claude Code uses a 200K context window by default. To handle large codebases or long conversations, you can expand the context window to 1M (1,000,000 tokens), provided the model supports that context length. Two configuration methods are available:

Method 1: Set via environment variable

Add CLAUDE_CODE_MAX_CONTEXT_TOKENS to the env field in ~/.claude/settings.json:

{
    "env": {
        "ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY",
        "ANTHROPIC_BASE_URL": "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/apps/anthropic",
        "ANTHROPIC_MODEL": "qwen3.7-plus",
        "CLAUDE_CODE_MAX_CONTEXT_TOKENS": "1000000"
    }
}

Method 2: Use a model name suffix

Append [1m] to the model name. This works with Model Studio models that support a 1M context window:

{
    "env": {
        "ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY",
        "ANTHROPIC_BASE_URL": "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/apps/anthropic",
        "ANTHROPIC_MODEL": "qwen3.7-plus[1m]",
        "ANTHROPIC_DEFAULT_SONNET_MODEL": "qwen3.7-plus[1m]",
        "ANTHROPIC_DEFAULT_OPUS_MODEL": "qwen3.7-plus[1m]",
        "CLAUDE_CODE_SUBAGENT_MODEL": "qwen3.7-plus[1m]"
    }
}

After modifying the configuration, open a new terminal window to restart Claude Code for the changes to take effect. For more environment variable details, see the Claude Code official environment variables documentation.

Use CC Switch

CC Switch is a community open-source desktop GUI for managing multiple API keys or billing plans. Switch between providers with one click, without editing settings.json manually.

Install CC Switch

  • macOS: brew tap farion1231/ccswitch && brew install --cask cc-switch, or download the .dmg from Releases.

  • Windows: download the .msi installer or portable .zip from Releases.

  • Linux: on Arch, run paru -S cc-switch-bin; on other distributions, download .deb / .rpm / .AppImage from Releases.

Add a provider

  1. In the CC Switch main interface, select Claude Code in the top icon bar (the orange star icon), then click + in the upper-right corner to open Add New Provider. Fill in the fields based on the table below, then click Add.

    Billing plan

    Configuration

    Token Plan Personal Edition

    Provider name: Bailian-Token Plan Personal Edition

    API Key: get from console

    Endpoint: https://token-plan.cn-beijing.maas.aliyuncs.com/apps/anthropic

    Token Plan Team Edition

    Provider name: Bailian-Token Plan Team Edition

    API Key: get from console

    Endpoint: https://token-plan.cn-beijing.maas.aliyuncs.com/apps/anthropic

    Coding Plan

    Provider name: Bailian-Coding Plan

    API Key: get from console

    Endpoint: https://coding.dashscope.aliyuncs.com/apps/anthropic

    Pay-as-you-go

    Provider name: Bailian-Pay-as-you-go

    API Key: Model Studio API Key

    Endpoint: https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/apps/anthropic

  2. Expand Advanced Options to configure model mapping. Set the main model and the Haiku, Sonnet, and Opus default models to supported models for your plan. Example mapping:

    • Main model: qwen3.7-max (not supported by Coding Plan)

    • Haiku default model: qwen3.6-flash (not supported by Coding Plan)

    • Sonnet default model: qwen3.7-max (not supported by Coding Plan)

    • Opus default model: qwen3.7-max (not supported by Coding Plan)

  3. Return to the main interface, click Enable next to the provider, then start a new Claude Code session for the configuration to take effect.

Connect Claude Code Desktop

Claude Code Desktop (Claude Desktop) and the Claude Code CLI are two separate entry points, shown in CC Switch as the Claude Code and Claude Desktop panels respectively. The desktop app reaches Model Studio through the CC Switch local gateway: CC Switch automatically writes both the gateway address and the auth token into the desktop configuration, so you do not enter your Model Studio API Key in the desktop app. The Model Studio API Key is entered only in the CC Switch provider configuration and is injected automatically when the local router forwards the request.

Important

Do not manually enter your Model Studio API Key in the desktop app's third-party inference configuration. The token the desktop app uses to authenticate to the CC Switch local gateway (address http://127.0.0.1:15721/claude-desktop) is generated and written automatically by CC Switch; entering the Model Studio API Key here fails authentication because the token does not match. Writing the desktop third-party configuration is currently supported only on macOS and Windows.

  1. Install Claude Code Desktop from the Claude download page.

  2. In CC Switch, switch to the Claude Desktop panel from the app switcher on the left. If the entry is not shown, go to Settings > General and make sure Claude Desktop is not hidden under app visibility.

  3. Add the Model Studio provider: if you have already configured a Model Studio provider in the Claude Code panel, click Import existing providers from Claude Code to reuse it; otherwise click + in the upper-right to add one. Because Model Studio model IDs (such as qwen3.7-max) are not the three role IDs that Claude Desktop recognizes (claude-sonnet-* / claude-opus-* / claude-haiku-*), turn on Needs model mapping and map the Sonnet, Opus, and Haiku roles to the actual Model Studio models to request (for example, Sonnet > qwen3.7-max).

  4. Enable local routing: go to Settings > Routing > Local Routing and turn on Show Routing Toggle on Main Page; return to the Claude Desktop panel and turn on the Claude Desktop local routing switch. The default listen address is 127.0.0.1:15721.

  5. Click Enable on the provider card. CC Switch automatically writes the third-party inference configuration into Claude Code Desktop.

  6. Keep CC Switch running, then fully quit and restart Claude Code Desktop for the changes to take effect. Select the configured model from the model menu to start using it.

Claude Code IDE plugins

After completing the CLI configuration above, install the Claude Code plugin in your IDE. The plugin reuses the configuration in settings.json directly.

VS Code

  1. Search for Claude Code for VS Code in the extension marketplace and install it.

  2. Restart VS Code and click the icon in the upper-right corner to open Claude Code.

  3. Type / in the dialog box, select General config, and set the model in Selected Model.

JetBrains

  1. Search for Claude Code in the extension marketplace and install it.

  2. Restart the IDE and click the icon in the upper-right corner to start using it.

Use case: Integrate Bailian CLI

Bailian CLI registers a Skill at ~/.claude/skills/bailian-cli/ during installation, allowing Claude Code to invoke Bailian capabilities through conversation. For the full capability list, see the Bailian CLI console. Prerequisite: Node.js 18+.

  1. Tell Claude Code to install Bailian CLI:

    Please install the Alibaba Cloud Bailian CLI globally: npm install -g bailian-cli
  2. Go to the Bailian console to get your API Key, then tell Claude Code to configure it:

    My API Key is: sk-xxxxxxxxxxxxx
  3. Describe what you need in natural language, for example:

    Generate 6 Amazon e-commerce hero images for a white wireless Bluetooth headset.
    Generate a 30-second product demo video for a white wireless Bluetooth headset.

FAQ

Error codes

If you encounter errors during configuration, refer to the FAQ documentation for your billing plan:

After starting Claude Code, the interface displays "Unable to connect to Anthropic services. Failed to connect to api.anthropic.com: ERR_BAD_REQUEST"

Claude Code is connecting to the official Anthropic service instead of Alibaba Cloud Model Studio. This usually means the environment variables are missing or have not taken effect. Follow these steps:

  1. Check the configuration. Run the /status command after starting Claude Code. Verify that ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN point to the Model Studio address. If the output is empty or shows a non-Model Studio address, check the settings.json configuration.

  2. Verify hasCompletedOnboarding. Confirm that hasCompletedOnboarding is set to true in ~/.claude.json. Without this, Claude Code attempts to connect to the official Anthropic service for login verification on startup.

  3. Open a new terminal. After editing the configuration file, open a new terminal window and run claude for the changes to take effect.

  4. Update Claude Code. If the issue persists after all the steps above, the Claude Code version may be outdated. Run npm install -g @anthropic-ai/claude-code@latest to update to the latest version, then try again.

Model switching does not take effect when using the legacy interface

The legacy compatible interface https://dashscope.aliyuncs.com/api/v2/apps/claude-code-proxy only supports the qwen3-coder-plus model. Specifying other models has no effect. To use other models, migrate to the new interface by following the configuration in this document.

CC Switch reports "No available model list endpoint found. Check the Base URL or confirm that the provider has opened the port" when adding a provider

This message comes from the connectivity check CC Switch runs when saving a provider: it probes a model list endpoint (such as /v1/models) against the configured request URL. Model Studio's Anthropic-compatible endpoint (ending in /apps/anthropic) only provides the messages endpoint /v1/messages and does not provide a model list endpoint, so the probe returns 404 and CC Switch reports "No available model list endpoint found".

This message does not affect normal use of Claude Code and can be ignored. Claude Code sends conversations through /v1/messages, and the models it uses are specified directly by the model mapping in CC Switch's Advanced options, without relying on auto-discovery from a model list endpoint. When the request URL and API Key are configured correctly, simply click Enable and start a new Claude Code session to chat normally.

If you still cannot chat, verify that the request URL ends in /apps/anthropic without an extra /v1, and that you have filled in the models supported by your plan in the model mapping under Advanced options.