Claude Code is a command-line AI programming assistant that helps you write code, debug issues, and refactor projects. Install it in DSW and connect to a model through the PAI-Token Service to get started.
Quick start
Step 1: Install Claude Code
Open the DSW Terminal and run the following command:
curl -fsSL https://pai-dsw-ai-machine.oss-cn-beijing.aliyuncs.com/agent/claude/setup-cc-dsw.sh -o setup-cc-dsw.sh && bash setup-cc-dsw.sh
The script guides you through the installation and configuration process:
-
Installs Node.js and Claude Code.
-
Prompts you to select a model service and configure the connection. We recommend the PAI-Token Service. For details, see Step 2.
-
Persists the configuration to
/mnt/workspaceor another mount path that you specify, so you do not need to reinstall after the instance restarts.
Step 2: Configure the model service
Claude Code requires a connection to a large model to function. The PAI-Token Service is recommended for the following benefits:
-
Zero deployment: Ready to use upon activation. No need to deploy a vLLM service.
-
Rich model selection: Access popular models including Qwen, DeepSeek, and GLM, and switch between them with a single click.
-
Optimized networking: Stable, low-latency calls from within the DSW private network.
-
Unified billing: Costs are consolidated with your other PAI resources on a single bill, simplifying accounting for enterprise customers.
To use model services from Model Studio or EAS, see Appendix: Use other model services.
Enable the PAI-Token Service
-
Go to the PAI-Token Service console.
-
If the service is not enabled, click Enable with One Click.
-
Return to the installation script and select PAI-Token Service from the menu. The script automatically retrieves the token and completes the configuration.
The PAI-Token Service is billed based on token usage. For details, see PAI-Token Service billing details.
If your DSW instance already has the default PAI role configured (the ALIBABA_CLOUD_CREDENTIALS_URI environment variable is set), the script automatically retrieves the token. You do not need to copy and paste it manually.
Select a model
The script automatically fetches a list of available models for you to choose from:
|
Scenario |
Recommended model |
Description |
|
General programming / Refactoring |
|
Flagship large model with the strongest overall capabilities (recommended by default). |
|
Code-specific tasks |
|
Optimized for code generation, with strong long-context performance. |
|
Complex reasoning / Large-scale refactoring |
|
Excels at reasoning and planning, ideal for architecture-level tasks. |
|
Previous-generation flagship |
|
The stable and reliable flagship model of the Qwen3 series. |
|
Multimodal analysis |
|
Supports image understanding (screenshots, charts, and UI design mockups). |
|
Maximum response speed |
|
Lightweight and fast, suitable for simple Q&A, renaming, or comment generation. |
|
Cost-effective for daily use |
|
Sufficient for daily conversations and minor modifications. |
|
GLM series |
|
Zhipu GLM series models. Choose based on your preference. |
This list is updated regularly; the script always shows the most current options.
To change the model, edit the ANTHROPIC_MODEL field in ~/.claude/settings.json, or rerun bash setup-cc-dsw.sh --reconfigure.
Step 3: Start using Claude Code
Navigate to your project directory, run claude to start the tool, and then describe what you want to do in natural language.
Example: Refactor a notebook into a training script
cd /mnt/workspace/my-project
claude
After starting the tool, enter a description of your task. For example:
I have a notebook at notebooks/train_lora.ipynb that I need to refactor into src/train.py. The new script must support the --config parameter, multi-GPU training (compatible with DLC torchrun), and periodically save a checkpoint. First, read the notebook to understand the existing logic, and then begin refactoring.
Claude Code reads the notebook, understands its logic, and generates the script. You can verify the result directly in the terminal.
More use cases
-
GPU debugging: Paste the CUDA OOM error into Claude Code, and it will provide tuning suggestions for parameters such as
batch_sizeandgradient_accumulation_steps. -
Data processing: Describe the input format, output format, and filtering rules. Claude Code generates and tests a script for you.
-
DLC distributed training: Once your code runs on a single GPU, ask Claude Code to generate the DLC task configuration and submission script.
-
EAS inference service: Develop and debug an EAS inference service in DSW without repeatedly deploying it online.
Provide project context with CLAUDE.md
While Claude Code can read your code, it cannot infer specifics such as GPU models, data directories, or training commands. Provide this context in a CLAUDE.md file, which Claude Code reads automatically on startup.
The setup-cc-dsw.sh script generates both a global and a project-level CLAUDE.md file for you. You can also use the /init command within Claude Code to add details about your project structure.
Where to place CLAUDE.md
|
Path |
Scope |
Content |
|
|
Global |
General DSW rules, such as path conventions, prohibitions against writing to the system disk, and requirements for confirming sensitive operations. |
|
|
Project |
Project structure, GPU/Python versions, training/inference commands, and dependency versions. |
|
|
Local |
Rules that apply only to this submodule. |
What to include
Include only information that Claude Code cannot infer from your code:
-
Execution environment: GPU model and number, Python/CUDA versions, and the conda environment name.
-
Key paths: The absolute paths to your code, data, and model output.
-
Common commands: Commands for single-GPU debugging, multi-GPU training, and starting inference.
-
Restrictions: Actions to avoid, such as "Do not write to /home" or "Do not commit directly to the main branch."
If Claude Code repeatedly makes the same mistake, you can add a rule by typing a line starting with # in the chat. Claude Code will automatically add it to the CLAUDE.md file.
Tips
-
Start in the project directory: Claude Code treats the directory where it is launched as the project root. To ensure it correctly recognizes your project files, start it from a directory like
/mnt/workspace/your-project. -
Use
/compactto free up context: Claude Code may slow down during long conversations. When you switch to a new task, enter/compactto clear the conversation history and free up context space. -
Run
git initfirst: We recommend initializing a Git repository before using Claude Code so you can easily revert changes at any time.
Data persistence
The default working directory for a DSW instance is /mnt/workspace. Whether data is retained after the instance is stopped depends on the storage configuration:
-
Cloud disk: For a public resource group, data is cleared if the instance is stopped for more than 15 days. For a dedicated resource group, data is cleared when the instance is deleted.
-
NAS / CPFS mount (recommended): Data persists independently of the instance lifecycle and is retained even after the instance is deleted.
We recommend mounting NAS or CPFS to /mnt/workspace when creating an instance. This makes the working directory persistent by default and allows multiple instances to share code and data.
The installation script creates a symbolic link for the Claude Code configuration files in /mnt/workspace/.claude-persist/ and redirects temporary files to /mnt/workspace/.claude-tmp, preventing temporary files from filling up the /tmp directory on the system disk.
FAQ
Q: Network timeout during installation
A: Ensure that a public NAT gateway is enabled for your VPC. The script automatically retries the installation by switching to a different npm mirror. If it still fails, check the outbound traffic allowlist for your instance.
Q: 401 or 403 error with the claude command
A: The token is invalid or does not match the Base URL. Rerun bash setup-cc-dsw.sh --reconfigure. You can also verify the token by using curl:
curl -H "Authorization: Bearer YOUR_TOKEN" https://aiservice.cn-beijing.aliyuncs.com/anthropic
Q: claude command not found after restart
A: If you created the DSW instance in a dedicated resource group without a mounted NAS or CPFS, the system disk is cleared when the instance is stopped. Therefore, you must reinstall Claude Code after restarting the instance.
Q: PAI-Token Service Base URL in the cn-beijing region
A: The Anthropic-compatible endpoint for the PAI-Token Service is deployed centrally in the cn-beijing region, regardless of where your DSW instance is located. DSW instances in other regions call the service over the public internet, which may result in slightly higher latency but does not affect usability.
Appendix: Use other model services
In addition to the PAI-Token Service, you can connect to Model Studio or a self-deployed model on EAS. To make changes, edit ~/.claude/settings.json or rerun bash setup-cc-dsw.sh --reconfigure.
Model Studio pay-as-you-go
{
"env": {
"ANTHROPIC_AUTH_TOKEN": "sk-YOUR_KEY",
"ANTHROPIC_BASE_URL": "https://dashscope.aliyuncs.com/apps/anthropic",
"ANTHROPIC_MODEL": "qwen3-coder-plus",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "qwen3-coder-plus",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "qwen3-coder-plus",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "qwen3-coder-plus"
}
}
Model Studio supports endpoints in multiple regions:
|
Region |
Base URL |
|
China (Beijing) |
|
|
Asia Pacific SE 1 (Singapore) |
|
|
US East 1 (Virginia) |
|
The API key must match the region. Cross-region usage is not supported.
Model Studio Coding Plan
{
"env": {
"ANTHROPIC_AUTH_TOKEN": "sk-YOUR_CODING_PLAN_KEY",
"ANTHROPIC_BASE_URL": "https://coding.dashscope.aliyuncs.com/apps/anthropic",
"ANTHROPIC_MODEL": "qwen3.6-plus",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "qwen3.6-plus",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "qwen3.6-plus",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "qwen3.6-plus"
}
}
Model Studio Token Plan Team Edition
{
"env": {
"ANTHROPIC_AUTH_TOKEN": "sk-YOUR_TOKEN_PLAN_KEY",
"ANTHROPIC_BASE_URL": "https://token-plan.cn-beijing.maas.aliyuncs.com/apps/anthropic",
"ANTHROPIC_MODEL": "qwen3.6-plus",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "qwen3.6-plus",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "qwen3.6-plus",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "qwen3.6-plus"
}
}
EAS self-deployed model
{
"env": {
"ANTHROPIC_AUTH_TOKEN": "YOUR_EAS_TOKEN",
"ANTHROPIC_BASE_URL": "https://YOUR_ENDPOINT.pai-eas.aliyuncs.com",
"ANTHROPIC_MODEL": "qwen3-coder",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "qwen3-coder",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "qwen3-coder",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "qwen3-coder"
}
}
The EAS service must be started with the Anthropic-compatible endpoint: python3 -m vllm.entrypoints.anthropic.api_server --enable-auto-tool-choice --tool-call-parser hermes. For details, see Use PAI models in Claude Code.