Run Claude Code on Kimi or Qwen: Full Guide to Using Domestic LLMs
Claude Code only understands Anthropic‑format endpoints, but by adjusting three environment variables you can route it to domestic models such as Kimi K3 or Alibaba Qwen, with detailed step‑by‑step instructions for direct env‑var changes, settings‑file configuration, and GUI or CLI tools, plus known limitations.
Core environment variables
ANTHROPIC_BASE_URL– Model service address; replace with the vendor’s Anthropic‑compatible gateway. ANTHROPIC_AUTH_TOKEN – Your API key for the chosen provider. ANTHROPIC_MODEL – Target model identifier (e.g., kimi-k3 or qwen3-coder-plus).
Three persistence levels are supported:
Temporary: prefix a command with KEY=value (affects only that invocation).
Current session: export the variables in the shell; they disappear when the terminal closes.
Permanent: write the variables into ~/.claude/settings.json under an env section.
Solution A – Kimi K3 (simplest single‑model integration)
Moonshot provides a native Anthropic gateway. The flagship Kimi K3 model is available via API with model ID kimi-k3.
# Switch URL, Key, Model
export ANTHROPIC_BASE_URL=https://api.moonshot.cn/anthropic
export ANTHROPIC_AUTH_TOKEN=YOUR_KIMI_API_KEY
export ANTHROPIC_MODEL=kimi-k3
source ~/.zshrc # or restart the shell
claude # launch Claude CodeVerify with the /status command: the Base URL should show the Moonshot domain and the Model should display kimi-k3. The built‑in /model menu never lists Kimi models, so it cannot be used for verification.
Solution B – Qwen (Alibaba DashScope)
Alibaba DashScope also offers a Claude Code‑specific proxy endpoint.
export ANTHROPIC_BASE_URL=https://dashscope.aliyuncs.com/api/v2/apps/claude-code-proxy
export ANTHROPIC_AUTH_TOKEN=YOUR_DASHSCOPE_KEY
export ANTHROPIC_MODEL=qwen3-coder-plusThe stable programming model is qwen3-coder-plus. Alibaba previewed the 2.4 TB Qwen3.8‑Max on July 20 and plans to open‑source its weights; once its compatible endpoint is released, only the ANTHROPIC_MODEL value needs to be changed.
Solution C – Persistent settings.json
To avoid re‑exporting variables in each terminal, write the three variables into ~/.claude/settings.json under an env section. Example:
{
"$schema": "https://json.schemastore.org/claude-code-settings.json",
"env": {
"ANTHROPIC_BASE_URL": "https://api.moonshot.cn/anthropic",
"ANTHROPIC_AUTH_TOKEN": "YOUR_API_Key",
"ANTHROPIC_MODEL": "kimi-k3[1m]",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "kimi-k3[1m]",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "kimi-k3[1m]",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "kimi-k3[1m]",
"CLAUDE_CODE_SUBAGENT_MODEL": "kimi-k3[1m]"
}
}Claude Code selects different model tiers (Opus, Sonnet, Haiku, etc.) for background tasks. If only ANTHROPIC_MODEL is set, background tasks will request a non‑existent Haiku model ID and fail. Therefore all tier‑specific variables must point to the same model ID, as shown above.
The file stores the API key in plain text; it must never be committed to a Git repository.
Advanced: Multi‑model free switching
5.1 cc‑switch – GUI one‑click switch
cc‑switch is a cross‑platform desktop app (Tauri + Rust) with over 110 k ★ on GitHub. It ships with 50+ provider presets (DeepSeek, Kimi, GLM, SiliconFlow, Bedrock, …). Users can hot‑switch providers without restarting Claude Code, and it also supports automatic failover and local proxies.
5.2 kimicc – single‑command tool
# Run Claude Code with Kimi
npx kimicc
# Switch to Qwen
npx kimicc --qwen
# Specify any model ID
npx kimicc --model=kimi-k3The kimicc inject command writes the Anthropic variables into ~/.claude/settings.json, making the configuration permanent.
5.3 Claude Code Router (CCR) – protocol conversion
CCR runs a local service (default http://localhost:3456) that translates OpenAI‑compatible or vendor‑specific APIs into the Anthropic format required by Claude Code. In the web UI, fill each provider’s Base URL and API Key; for OpenAI‑style models set the endpoint to /chat/completions and choose the openai transformer.
Known limitations and pitfalls
Remote Control is disabled when ANTHROPIC_BASE_URL is custom.
WebFetch is unavailable on the Kimi endpoint (WebSearch still works).
Prompt caching may not work on third‑party gateways, reducing cost benefits for high‑frequency context reads.
K3 incurs high inference‑token cost even for simple queries; factor this into budgeting.
No official technical support from Anthropic for non‑Claude back‑ends.
401 errors usually stem from a conflict between ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN; keep only AUTH_TOKEN and clear old variables from shell profiles.
Setting only ANTHROPIC_MODEL is insufficient because background tasks still request a Haiku model ID; all tier‑specific model variables must be aligned.
404 errors can arise from double‑appending /v1/messages to the Base URL; when using CCR keep the Base URL ending with /v1/messages.
On first launch Claude Code may default to “No” for custom APIs; manually confirm “Yes” to enable the gateway.
Model IDs differ between Anthropic and OpenAI formats; use the IDs shown in this guide.
Never hard‑code API keys in source code, screenshots, or commit them to public repositories.
Relevant links
Claude Code environment variables: https://code.claude.com/docs/en/env-vars Claude Code LLM gateway documentation: https://code.claude.com/docs/en/llm-gateway cc‑switch (provider‑switch GUI): https://github.com/farion1231/cc-switch kimicc (one‑click integration): https://github.com/kaichen/kimicc Kimi official Claude Code guide: https://platform.kimi.ai/docs/guide/claude-code-kimi Kimi open platform: https://platform.moonshot.cn/ Alibaba Cloud Bailei (DashScope):
https://bailian.console.aliyun.com/Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Tech Ocean
Focused on AI programming, sharing ready-to-use development efficiency solutions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
