Set Up Claude Code with AGI Plan: Env Vars, settings.json, Rollback
Connecting Claude Code to AGI Plan doesn't require a reinstall or a Claude account. You point Claude Code's base URL at AGI Plan and swap in an API key created in AGI Plan. You can try it with temporary environment variables, then make it permanent in settings.json. This guide follows the order "try it temporarily, make it permanent, keep a way back," and lists where to look for common errors.
First, the relationship: AGI Plan is a commercial partner of cdnping. The AGI Plan site states clearly that it is not an officially authorized channel. Is AGI Plan an official Claude channel? covers this plainly, and it's worth a read before you connect.
What is AGI Plan, and who is it for?
AGI Plan is a multi-provider LLM aggregation gateway. It's billed as a monthly subscription, settled in RMB, and needs no foreign credit card. It is compatible with both the OpenAI and Anthropic API formats, so tools like Claude Code, Codex, and OpenCode only need one base URL change to draw on the same quota across several capability groups. Some models are labeled "overseas only"; check the AGI Plan models page for specifics.
If you haven't signed up yet, start with Getting started with AGI Plan: sign up, create a key, change one setting, or follow the prompts at agiplan.dev/startup. For how the plan's quota unit (CU) converts to your own usage, see What is a CU in AGI Plan.
What do you need before connecting?
- Claude Code installed, with
clauderunnable from the command line. - An AGI Plan account (email verification-code sign-up) and an API key created in the console.
- The base URL AGI Plan provides for Claude Code. This article doesn't hard-code it; use the AGI Plan step-by-step Claude Code tutorial and the console as the source of truth. Below,
<AGIPLAN_BASE_URL>and<YOUR_KEY>are placeholders.
Step 1: Try it with environment variables
The advantage of a temporary setup is that it disappears when you close the terminal and changes no files. macOS / Linux:
export ANTHROPIC_BASE_URL="<AGIPLAN_BASE_URL>"
export ANTHROPIC_AUTH_TOKEN="<YOUR_KEY>"
claude
Windows PowerShell:
$env:ANTHROPIC_BASE_URL = "<AGIPLAN_BASE_URL>"
$env:ANTHROPIC_AUTH_TOKEN = "<YOUR_KEY>"
claude
ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN are environment variables officially supported by Claude Code. Some gateways want the key in ANTHROPIC_API_KEY instead; the two send different request headers, so follow the AGI Plan tutorial on which to use. Don't set both, or you're likely to get an auth conflict warning. See Claude Code auth conflict and 401 errors for how to handle it.
Step 2: Make it permanent in settings.json
Once the temporary setup works, make it permanent. Claude Code's settings.json supports an env field, and the variables in it are injected on every launch. The user-level file is usually at ~/.claude/settings.json; the project-level one is at .claude/settings.json in the project directory:
{
"env": {
"ANTHROPIC_BASE_URL": "<AGIPLAN_BASE_URL>",
"ANTHROPIC_AUTH_TOKEN": "<YOUR_KEY>"
}
}
A few things to watch:
- Don't put the key in a project-level file that gets committed to Git. If it has to live in the project, use
.claude/settings.local.json, which isn't checked in, or just use the user-level file. - When several levels are configured, there's a precedence order. See Claude Code settings.json levels, precedence, and env config for which level overrides which.
- If your shell has already exported variables with the same names,
unsetthem or close the terminal first. Otherwise you may think config A is active when config B is the one in effect.
How do you verify requests really go through AGI Plan?
Check in this order; each step has a clear pass condition:
| Check | How | Expected |
|---|---|---|
| Variable is set | echo $ANTHROPIC_BASE_URL (in PowerShell, $env:ANTHROPIC_BASE_URL) | Prints the address you entered |
| It starts | Run claude and send "hello" | Normal reply, no auth error |
| Model selection | Use /model inside Claude Code to view or switch | Lists the available options; see How to switch models in Claude Code |
| Quota is being charged | Check usage in the AGI Plan console | Usage changes after you send a request |
The last check is the most direct: if console usage goes up, your requests are going through AGI Plan. If Claude Code works but the console doesn't move, you're most likely still using your original login or a config from somewhere else.
How do you roll back to your previous setup?
Do two things before connecting and rollback is simple:
- Back up:
cp ~/.claude/settings.json ~/.claude/settings.json.bak. - Note which fields were already in
env.
To roll back, delete the ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN lines from env (or restore the backup), run unset ANTHROPIC_BASE_URL ANTHROPIC_AUTH_TOKEN in the current terminal, and restart claude. If you were using a subscription login before, just log in again. For the difference between the two login methods, see Claude Code: API key login vs. subscription login.
Common errors
The table below gives directions for troubleshooting; the exact error text depends on what Claude Code and AGI Plan actually print.
| Symptom | Common cause | Check first |
|---|---|---|
| 401 / authentication failed | Key copied incompletely, extra space or newline, wrong variable name | Re-copy the key; confirm you're using the variable the AGI Plan tutorial specifies |
| auth conflict warning | AUTH_TOKEN and API_KEY both set, or coexisting with a subscription login | Keep only one; log out first if needed |
| 404 / path not found | Base URL has an extra or missing path segment | Paste the address from the tutorial exactly as given |
| 429 | Possibly rate limiting or exhausted quota; the response message decides | Check console usage and plan quota |
| Model unavailable | The chosen model is labeled "overseas only" or isn't in your capability group | See the AGI Plan models page and How to read service regions and "overseas only" labels |
| Timeouts, very slow | Network path from your machine to the gateway, or upstream fluctuation | See the status page and latency article below |
How do you tell whether it's local, the gateway, or upstream?
Rule out local configuration first, then look at service status. cdnping's AGI Plan API status page mirrors the availability data AGI Plan publishes, and Is Claude Code down? combines the official status page, API probes, and user reports so you can tell whether the problem is widespread. For why latency to AI APIs from mainland China looks the way it does, see How to read AI API latency in China.
Next steps
- Sign up and create a key, following agiplan.dev/startup.
- Get it working with environment variables first, then write settings.json.
- To find out whether Claude Code and Codex can share quota, read Can Claude Code and Codex share one quota?
If your use case has enterprise compliance requirements, or you need a direct connection to Anthropic, evaluate official channels instead of looking at only this one option.