Claude Code
Configure and use AGTCloud in Claude Code.
Claude Code is a terminal programming tool launched by Anthropic. By configuring the API address, API Key, and model ID, Claude Code can use AGTCloud's Anthropic Messages compatible entry point.
This guide covers the Claude Code CLI. Support for tool calls, extended thinking, and experimental features varies by model, so choose a model that is available to the current API Key and supports Anthropic Messages.
Preparation
Before you start, please confirm that you have:
- Prepare your terminal environment and Git;
- Register and log in to AGTCloud;
- Create a token on the API Keys page;
- Find a model ID that is available to the current token and supports the Anthropic protocol in the Model Marketplace.
Install Claude Code
Choose the installation method that matches your operating system. The native installation script will update automatically; Homebrew and WinGet installation require manual updates through their respective package managers.
curl -fsSL https://claude.ai/install.sh | bashAfter installation, reopen the terminal and check the version:
claude --version
claude doctorclaude doctor checks the installation and configuration. If the terminal cannot find claude, reopen it and confirm that the installation directory is in PATH.
Configure AGTCloud
Claude Code sends requests to ANTHROPIC_BASE_URL. Enter only the AGTCloud API Origin; do not append /v1, because Claude Code automatically requests /v1/messages.
Temporary configuration
The following configuration applies only to the current terminal session. Replace your-api-key and MODEL_ID with your API Key and model ID.
unset ANTHROPIC_AUTH_TOKEN
export ANTHROPIC_BASE_URL="https://api.agtcloud.cn"
export ANTHROPIC_API_KEY="your-api-key"
export ANTHROPIC_MODEL="MODEL_ID"| Environmental variables | Function |
|---|---|
ANTHROPIC_BASE_URL | Point the Claude Code request to the AGTCloud API address shown on this page |
ANTHROPIC_API_KEY | Sends the AGTCloud API Key in the x-api-key header |
ANTHROPIC_MODEL | Specify the model ID to be used by default for this session |
Clearing conflicting authentication variables
If ANTHROPIC_AUTH_TOKEN is set, Claude Code may use it as a Bearer token instead of ANTHROPIC_API_KEY. Clear the conflicting variable before applying this guide.
Durable configuration
If you want the settings to load automatically whenever you open a terminal, add the same values to your shell configuration file or Windows user environment variables. The API Key will be stored locally as plaintext, so use this method only on a trusted personal device.
Edit ~/.zshrc and add:
export ANTHROPIC_BASE_URL="https://api.agtcloud.cn"
export ANTHROPIC_API_KEY="your-api-key"
export ANTHROPIC_MODEL="MODEL_ID"Load configuration after saving:
source ~/.zshrcChoose a model
MODEL_ID is a placeholder, not a real model name. From the Model Marketplace, copy the full ID of a model that is available to the current API Key and supports Anthropic Messages.
In Claude Code, run /model to view and switch the session model. Whether the selector lists every AGTCloud model depends on the Claude Code version and current API Key. If the target model is absent, set its full ID with ANTHROPIC_MODEL.
Start and verify the connection
Enter the project directory
cd /path/to/your/projectLaunch Claude Code
claudeIf the first startup prompts whether to use the API Key from the environment variable, please confirm as prompted in the terminal.
Check the current configuration
Executing in Claude Code:
/statusConfirm that the authentication source is an API Key and check whether the Base URL is the AGTCloud API address shown on this page. The Base URL should not contain duplicate /v1.
Initiate read-only tests
In a test project containing README.md, enter:
Please read the README.md and summarize the purpose of this project in three points. Do not modify any files.If the content returns normally and the corresponding call record appears in the AGTCloud console, it means the basic connection has been established.
After completing the configuration check, you can send a simple question to confirm that the model responds correctly.
Frequently Asked Questions
| Issue | What to check | Resolution |
|---|---|---|
The claude command is not found | Installation and PATH | Reopen the terminal and run claude doctor; rerun the official installer if necessary |
| Login is still required after startup | Whether the API Key is active in the same terminal where Claude Code is launched | Check the ANTHROPIC_API_KEY, reopen the terminal, and restart it |
| The API Key is not active | Whether ANTHROPIC_AUTH_TOKEN is also set | Clear conflicting variables and use /status to verify the authentication source |
Returns 401 | API Key, environment variables, and token status | Copy a valid API Key again and use /status to confirm the authentication source |
Returns 403 | Token permissions, model permissions, and account status | Check the token status and the models available to the account in the console |
Returns 404 | Base URL and model ID | Use https://api.agtcloud.cn as the Base URL without appending /v1, then copy the model ID again |
| Models cannot be found or unusable | models available to the current API Key and protocol support | Select a model that supports Anthropic Messages and specify the full ID via the ANTHROPIC_MODEL |
| Some tools or advanced features are unavailable | Model capabilities and gateway compatibility | Start with a basic conversation. Advanced capabilities depend on the selected model and the current integration support |
If you cannot identify an issue, record the request time, model ID, HTTP status, and redacted error message, then review Errors and troubleshooting. Never submit the full API Key.
Safety advice
- Create a separate API Key for Claude Code to facilitate permission management and disable credentials.
- Do not write real keys into code, repositories, screenshots, logs, or shared scripts.
- In shared devices or team environments, prioritize operating system credential management or organize a unified key distribution scheme.
- If an API Key is suspected of leaking, it should be immediately disabled or removed in the console and a new Key created.
Next, you can continue reading API Key, Base URL & Authentication and Anthropic Messages.