Claude Code is a programming agent product from Anthropic. Its interface, configuration options, and supported capabilities may change across versions. This guide describes a general integration approach: forwarding Claude Code model requests to the Kimi API through environment variables.
Install Claude Code
Skip this step if Claude Code is already installed. Run:No Node.js yet? Expand for installation and initialization
No Node.js yet? Expand for installation and initialization
macOS and Linux:Windows (PowerShell):After installing Node.js, run the initialization once:
Not a fresh install? Clean up legacy configuration and environment variables
Not a fresh install? Clean up legacy configuration and environment variables
If you previously modified This script only removes endpoint, credential, and model-related variables from
~/.claude/settings.json through third-party tools or by hand, stale entries in its env field override environment variables exported in your terminal, which can silently prevent the new configuration from taking effect or rewrite model requests. Run the following script to clean them up first:env; other settings (such as permissions and theme) are left untouched.Also check shell configuration files such as ~/.zshrc and ~/.bashrc for stale ANTHROPIC_* exports (on Windows, check your user environment variables) and remove any you find — they interfere with the new configuration just as much.Get a Kimi API Key
Visit Kimi Open Platform to create an API key (choose the default project), and use it in place ofYOUR_MOONSHOT_API_KEY below.
Configure Environment Variables
Choose one of the two methods below and do not mix them: Method 1 takes effect immediately but only lasts for the current terminal session; Method 2 writes to a configuration file and persists.Method 1: Terminal Environment Variables (Current Session Only)
macOS and Linux:Method 2: Write To settings.json (Persistent)
Write the same variables into theenv field of ~/.claude/settings.json:
env values in settings.json override variables exported in your terminal; this file contains your API key in plaintext — do not commit it to a git repository; restart Claude Code after saving.
Configuration Reference
Claude Code uses different model tiers for different scenarios (main conversation, background summarization, sub-agents, and so on). Configuring only some of the variables makes the corresponding scenarios fail silently:Models And Thinking Behavior
How the three models actually behave in Claude Code (verified against the Anthropic-compatible endpoint):
When switching models, replace the value of every model variable in the configuration with the new model name.
Confirm That The Configuration Took Effect
In Claude Code, enter/status to confirm the configuration:
- Base URL should show
https://api.moonshot.ai/anthropic - Model should show
kimi-k3[1m]
/model menu is a built-in list of fixed aliases — it does not show Kimi models, and you do not need to switch anything there. Whether the configuration took effect is determined by what /status shows.

hi). Receiving a normal reply confirms the end-to-end setup works.
Turn On Thinking
kimi-k3 thinks by default and works out of the box. If you switch to kimi-k2.7-code, it requires requests to explicitly enable thinking: press Tab in Claude Code to turn Thinking on and start working once you see the “Thinking on” indicator — otherwise the model rejects requests (400 invalid thinking), and features such as WebSearch do not work.

Switch To The High-Speed Model
Kimi K2.7 Code offers a high-speed variant,kimi-k2.7-code-highspeed, with an output speed about 5-6x that of the regular version. If you prioritize output speed, change the value of every model variable in the configuration to kimi-k2.7-code-highspeed (note that it requires explicitly enabled thinking — see Models And Thinking Behavior). See K2.7 Code pricing for details.
Third-Party Tool: cc-switch
Community tools such as cc-switch can switch between multiple provider configurations. These tools are not maintained by Kimi, and their presets may differ from the values recommended on this page. After using them, verify each variable against the Configuration Reference above, and use/status to confirm the Base URL and model actually in effect.
FAQ
401 authentication errors
401 authentication errors
Check that
ANTHROPIC_AUTH_TOKEN is a valid Kimi API key. If you previously configured ANTHROPIC_API_KEY, remove it to avoid conflicts with ANTHROPIC_AUTH_TOKEN when both are present.Model not found
Model not found
Check the spelling of every model variable (
kimi-k3[1m]), and make sure there are no extra spaces or quotes.Background tasks or sub-agents fail
Background tasks or sub-agents fail
This usually means
ANTHROPIC_DEFAULT_HAIKU_MODEL, ANTHROPIC_DEFAULT_FABLE_MODEL, or CLAUDE_CODE_SUBAGENT_MODEL is not set, so those scenarios requested a model name the Kimi endpoint cannot recognize. Fill in the missing variables per the Configuration Reference above.Configuration changes do not take effect
Configuration changes do not take effect
- Check for stale entries in the
envfield of~/.claude/settings.json(they override terminal environment variables); you can run the cleanup script in the collapsed section above; - Variables exported in a terminal only apply to the current session and must be set again in a new window. If you appended them to
~/.zshrcor used the settings.json method, make sure you restarted Claude Code after the change.
API key and endpoint mismatch
API key and endpoint mismatch
Make sure
ANTHROPIC_BASE_URL matches the platform where you created the API key — create the key on the platform linked in “Get a Kimi API Key” above and use the endpoint shown on this page.Previously logged in with /login
Previously logged in with /login
Once set,
ANTHROPIC_AUTH_TOKEN takes precedence over a saved claude.ai login, so no action is usually needed. Run /status in a session to confirm which credential source is active; to remove the saved login, run /logout.