Skip to main content

Claude Code

Use Alibaba Cloud Model Studio models in Claude Code.

Quick Start

Choose your client and complete the configuration.
  • CLI
  • CC Switch
  • IDE plugin
  • Desktop
  1. 1

    Configure the model

    • Token Plan
    • Pay-as-you-go
    • Coding Plan
    Replace YOUR_API_KEY with your Token Plan API Key:
    export ANTHROPIC_AUTH_TOKEN="YOUR_API_KEY"
    export ANTHROPIC_BASE_URL="https://token-plan.ap-southeast-1.maas.aliyuncs.com/apps/anthropic"
    export ANTHROPIC_MODEL="auto"
    export ANTHROPIC_DEFAULT_HAIKU_MODEL="qwen3.6-flash"
    export ANTHROPIC_DEFAULT_SONNET_MODEL="qwen3.8-flash"
    export ANTHROPIC_DEFAULT_OPUS_MODEL="qwen3.8-max"
    export CLAUDE_CODE_SUBAGENT_MODEL="auto"
    export CLAUDE_CODE_MAX_CONTEXT_TOKENS="983616"
    
    These environment variables apply only to the current terminal. For persistent configuration, use Configure with a configuration file.
  2. 2

    Verify

    Run the following command to verify:
    claude -p "Hello"
    

Configure with a Configuration File

In addition to the options above, you can also connect using a configuration file.
  1. 1

    Open or create the configuration file

    • macOS / Linux: ~/.claude/settings.json
    • Windows: C:\Users\<username>\.claude\settings.json
  2. 2

    Add the configuration

    • Token Plan
    • Pay-as-you-go
    • Coding Plan
    Replace YOUR_API_KEY with your Token Plan API Key:
    {
        "env": {
            "ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY",
            "ANTHROPIC_BASE_URL": "https://token-plan.ap-southeast-1.maas.aliyuncs.com/apps/anthropic",
            "ANTHROPIC_MODEL": "auto",
            "ANTHROPIC_DEFAULT_HAIKU_MODEL": "qwen3.6-flash",
            "ANTHROPIC_DEFAULT_SONNET_MODEL": "qwen3.8-flash",
            "ANTHROPIC_DEFAULT_OPUS_MODEL": "qwen3.8-max",
            "CLAUDE_CODE_SUBAGENT_MODEL": "auto",
            "CLAUDE_CODE_MAX_CONTEXT_TOKENS": "983616"
        }
    }
    
  3. 3

    Verify

    After saving, run the following command to verify:
    claude -p "Hello"
    

Configure Context Window Size

Claude Code defaults to a 200K context window. If the model supports 1M, extend it to 1M (1,000,000 tokens). 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}.ap-southeast-1.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}.ap-southeast-1.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.

Permission modes

Claude Code provides six permission modes:
  • default: Prompts for confirmation before every operation.
  • acceptEdits: Approves file edits automatically. Other operations still prompt for confirmation.
  • plan: Read-only planning mode. No changes are executed.
  • dontAsk: Does not prompt. An operation that would require a prompt is rejected directly.
  • bypassPermissions: Bypasses all permission checks.
  • delegate: Delegated mode.
Method 1: Command-line flag Use --permission-mode to set the default permission mode for a session:
claude --permission-mode plan
claude --permission-mode acceptEdits
Method 2: Interactive command Enter /permissions in a session to manage pre-approve and pre-deny rules for the bash, edit, and MCP tools. Method 3: settings.json configuration Configure the permissions field in ~/.claude/settings.json:
{
    "permissions": {
        "allow": ["Bash(git:*)", "Read", "Edit"],
        "deny": ["Bash(rm:*)"],
        "defaultMode": "default"
    }
}

Integrate Bailian CLI

  1. 1

    Install Bailian CLI

    Please install the Alibaba Cloud Bailian CLI globally: npm install -g bailian-cli
    
  2. 2

    Configure the API Key

    Go to the Bailian console to get an API Key, then tell Claude Code:
    My API Key is: sk-xxxxxxxxxxxxx
    
  3. 3

    Get started

    Describe your task 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.
    

Error Codes

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

FAQ

The pay-as-you-go setup remains the same: use your general Model Studio API key and Base URL. After you purchase a savings plan, it takes effect automatically and eligible usage is deducted automatically. See Savings plans.

How do I skip the official Anthropic 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
}
The API key type does not match ANTHROPIC_BASE_URL. Model Studio provides three access methods, and each access method uses a different base URL and a dedicated API key.

Access method

Base URL

API key

Token Plan

https://token-plan.ap-southeast-1.maas.aliyuncs.com/apps/anthropic

Token Plan API key

Pay-as-you-go

https://dashscope-intl.aliyuncs.com/apps/anthropic

Model Studio API key (starts with sk-)

Coding Plan

https://coding-intl.dashscope.aliyuncs.com/apps/anthropic

Coding Plan dedicated API key

Troubleshooting steps:
  1. Check the request URL. Check ANTHROPIC_BASE_URL in ~/.claude/settings.json.
  2. Confirm the API key type. Using the table above, confirm that your API key type matches the base URL.
  3. Correct the configuration. When you use a Model Studio Pay-as-you-go API key, set ANTHROPIC_BASE_URL to https://dashscope-intl.aliyuncs.com/apps/anthropic.
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.
The legacy compatible interface https://dashscope-intl.aliyuncs.com/api/v2/apps/claude-code-proxy only supports deprecated models. Specifying other models has no effect. To use available models, migrate to the new interface by following the configuration in this document.
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.
If model calls fail in Claude Code with an AccessDenied error (HTTP 403, code: access_denied) after you configure the model mapping, check whether the model is marked as Upcoming deprecation in Model Studio console > Model Gallery. Models marked for upcoming deprecation still appear in the list, but API calls return 403 AccessDenied. Follow these steps:
  1. Check whether the model is marked for deprecation. In Model Studio console > Model Gallery, search for the model you are using and check its status label.
  2. Switch to the latest available model. Replace the legacy model (such as qwen-coder-turbo-0919) in the model mapping with the latest available model (such as qwen3.8-max).
  3. Reconfigure the model mapping and test. Update the model mapping under Advanced options in CC Switch, click Enable, and start a new Claude Code session to verify.
Pay attention to the model lifecycle. Models marked for upcoming deprecation in Model Studio console > Model Gallery may become unavailable at any time. You can check a model's availability status there.