Skip to main content
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:
macOS and Linux:
Windows (PowerShell):
After installing Node.js, run the initialization once:
If you previously modified ~/.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:
This script only removes endpoint, credential, and model-related variables from 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 of YOUR_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:
Windows (PowerShell):

Method 2: Write To settings.json (Persistent)

Write the same variables into the env field of ~/.claude/settings.json:
Note: 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]
Claude Code’s /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. status Finally, send any message (for example 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. thinking-on You can now use Claude Code for development normally.

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

  • WebSearch fails with 400 invalid thinking: only type=enabled is allowed for this model: kimi-k2.7-code requires thinking, and WebSearch requests without it are rejected by the platform. Press Tab to turn Thinking on first, then retry; if it still fails, switch to kimi-k2.6 (thinking optional, not subject to this restriction). kimi-k3 is not affected. This is unrelated to your local configuration or cc-switch.
  • WebFetch reports temporarily unavailable or returns no fetched content: the endpoint does not support WebFetch for now — unrelated to your configuration; it will work once the platform adds support. As a workaround, paste the web page content into the chat, or use an MCP scraping tool instead.
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.
Check the spelling of every model variable (kimi-k3[1m]), and make sure there are no extra spaces or quotes.
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.
  • Check for stale entries in the env field 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 ~/.zshrc or used the settings.json method, make sure you restarted Claude Code after the change.
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.
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.