Kimi publishes an official Claude Code integration guide, and it is the cleanest current route for using Kimi K3 in a terminal coding agent.
The integration works because Kimi provides an Anthropic-compatible endpoint for Claude Code, while Kimi K3 itself is the model used behind that endpoint. The guide below follows Kimi's documented values and adds a few checks that make setup problems easier to spot.
Install Claude Code
Install Claude Code with npm:
npm install -g @anthropic-ai/claude-codeThen create a Kimi API key in the Kimi Open Platform console.
Configure the current shell
For a one-session setup, export the environment variables before launching Claude Code:
export ANTHROPIC_BASE_URL="https://api.moonshot.ai/anthropic"
export ANTHROPIC_AUTH_TOKEN="YOUR_MOONSHOT_API_KEY"
export ANTHROPIC_MODEL="kimi-k3[1m]"
export ANTHROPIC_DEFAULT_OPUS_MODEL="kimi-k3[1m]"
export ANTHROPIC_DEFAULT_SONNET_MODEL="kimi-k3[1m]"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="kimi-k3[1m]"
export ANTHROPIC_DEFAULT_FABLE_MODEL="kimi-k3[1m]"
export CLAUDE_CODE_SUBAGENT_MODEL="kimi-k3[1m]"
export ENABLE_TOOL_SEARCH="false"
export CLAUDE_CODE_AUTO_COMPACT_WINDOW="1048576"
export CLAUDE_CODE_EFFORT_LEVEL="max"
claudeReplace YOUR_MOONSHOT_API_KEY with your real Kimi API key.
Two values are easy to miss:
ENABLE_TOOL_SEARCH="false"is set because Kimi's Claude Code guide marks tool search as unsupported for this route.CLAUDE_CODE_AUTO_COMPACT_WINDOW="1048576"matches Kimi K3's one-million-token context window.
Make it persistent
If you do not want to export variables every time, add them to Claude Code's settings file:
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.moonshot.ai/anthropic",
"ANTHROPIC_AUTH_TOKEN": "YOUR_MOONSHOT_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]",
"ANTHROPIC_DEFAULT_FABLE_MODEL": "kimi-k3[1m]",
"CLAUDE_CODE_SUBAGENT_MODEL": "kimi-k3[1m]",
"ENABLE_TOOL_SEARCH": "false",
"CLAUDE_CODE_AUTO_COMPACT_WINDOW": "1048576",
"CLAUDE_CODE_EFFORT_LEVEL": "max"
}
}The file path is:
~/.claude/settings.jsonKimi's guide notes that values in this settings file override variables exported in the terminal. It also stores the API key as plain text, so keep the file private and avoid checking it into a repository.
After editing the file, restart Claude Code.
Verify the model
Inside Claude Code, run:
/statusConfirm that the base URL points to:
https://api.moonshot.ai/anthropicand that the model is:
kimi-k3[1m]Kimi's guide also notes that /model may not list Kimi models even when the integration is working, so use /status as the more reliable check.
Troubleshooting
If Claude Code still uses a different provider, check ~/.claude/settings.json first, because it can override shell exports.
If authentication fails, create a fresh Kimi API key and paste it again without quotes or extra spaces.
If the session compacts too early, confirm that CLAUDE_CODE_AUTO_COMPACT_WINDOW is set to 1048576.
If tool search errors appear, confirm that ENABLE_TOOL_SEARCH is set to false.
