Goal: Keep the
claude(Claude Code CLI) workflow (scan repo, edit files, run commands), but point the backend to Moonshot’s Anthropic Messages API–compatible endpoint so you can use Kimi K2.5.
The idea in 10 seconds
Claude Code speaks Anthropic’s Messages API. It can be configured (env vars or ~/.claude/settings.json) to use a custom Anthropic-compatible endpoint.
Moonshot (Kimi) exposes an endpoint that’s identical to Anthropic’s Messages API at:
https://api.moonshot.cn/anthropic/v1/messages(China)- (Same pattern for global:
https://api.moonshot.ai/anthropic/v1/messages)
That’s why Claude Code can drive Kimi models without code changes.
What you need
- Claude Code CLI installed (you can run
claude). - A Moonshot / Kimi API key (from Moonshot Open Platform).
- Pick your base domain:
- Global:
https://api.moonshot.ai - China:
https://api.moonshot.cn
- Global:
Claude Code will use the Anthropic-compatible route under /anthropic.
Option A: configure with environment variables
Paste this in your shell (macOS / Linux) before launching claude:
# 1) Claude Code → Moonshot Anthropic-compatible base
# Moonshot Messages API compatible route is /anthropic/v1/messages
export ANTHROPIC_BASE_URL="https://api.moonshot.ai/anthropic"
# 2) Auth
export ANTHROPIC_AUTH_TOKEN="YOUR_MOONSHOT_API_KEY"
# 3) Model
export ANTHROPIC_MODEL="kimi-k2.5"
export ANTHROPIC_SMALL_FAST_MODEL="kimi-k2.5"
# 4) Optional: fewer non-essential requests + friendlier long runs
export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
export API_TIMEOUT_MS=600000
# Launch Claude Code
claudeIf you’re using the China domain, change the base URL to:
export ANTHROPIC_BASE_URL="https://api.moonshot.cn/anthropic"Option B: persist in ~/.claude/settings.json
Claude Code supports a user-level config file at ~/.claude/settings.json with an env object. Use this if you don’t want to export variables every time.
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.moonshot.ai/anthropic",
"ANTHROPIC_AUTH_TOKEN": "YOUR_MOONSHOT_API_KEY",
"ANTHROPIC_MODEL": "kimi-k2.5",
"ANTHROPIC_SMALL_FAST_MODEL": "kimi-k2.5",
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
"API_TIMEOUT_MS": "600000"
}
}Restart your terminal and run:
claudeQuick sanity check
Inside Claude Code, ask:
- “What model id are you running?”
- “Which base URL are you connected to (moonshot.ai or moonshot.cn)?”
If it answers and keeps working across edits/commands, your routing is correct.
Troubleshooting
1) Claude Code still prompts you to log in to Anthropic
Most likely Claude Code didn’t pick up your env vars.
- Test with Option A first (export in the current shell).
- Then persist via
~/.claude/settings.json. - Restart the terminal.
2) 401 / token invalid
- Make sure the key is a Moonshot Open Platform API key.
- Use
ANTHROPIC_AUTH_TOKEN. - The base URL should end with
/anthropic(not/v1, and not any CLI-only URL).
3) Timeouts / long tool runs fail mid-way
- Increase
API_TIMEOUT_MS(e.g., 600000 → 900000). - Keep
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1. - Avoid giant directories (like
node_modules/or build outputs). Use Claude Code deny/permission rules to prevent scanning unnecessary paths.
Why the Anthropic-compatible route matters
Moonshot exposes both:
.../v1/chat/completions(OpenAI-compatible).../anthropic/v1/messages(Anthropic-compatible, matches Claude Code)
Since Claude Code natively speaks the Messages API, the /anthropic/v1/messages route is the cleanest integration.