If you're using Claude Code and want something faster, cheaper, and open source, plug in Kimi K2 by Moonshot AI. It performs on par with Claude 4 (sometimes better), costs up to 90% less, and is open source. The swap is simple — just two environment variables.
Here’s the direct integration method.
Claude Code uses two environment variables to define the model provider. You’ll point it to Moonshot’s Kimi K2 endpoint:
export ANTHROPIC_BASE_URL="<https://api.moonshot.ai/v1>" export ANTHROPIC_AUTH_TOKEN="your_kimi_api_key_here"
Replace your_kimi_api_key_here
with the key you got from Step 1.
Once set, any Claude Code command will route through Kimi K2 instead of Anthropic.
With the env vars set, run Claude Code like you always do. You’ll see a message about the API base being overridden — that’s your confirmation it’s working.
Example command:
/init
This scans your codebase and generates a CLAUDE.md
file at the root. It still looks like Claude is doing the work, but behind the scenes, it’s Kimi K2 answering.
To make this even faster, drop this into your .zshrc
file (Mac):
kimi() { ANTHROPIC_AUTH_TOKEN="your_kimi_api_key_here" ANTHROPIC_BASE_URL="<https://api.moonshot.ai/anthropic/>" claude "$@" }
Then reload your shell:
source ~/.zshrc
Now you can run Claude Code with Kimi K2 by simply typing:
kimi /init
or any other Claude command.
Moonshot’s API can get congested. During peak times, expect slower responses — around 60 to 75 seconds for full generations. It's the tradeoff for a cheaper, open-source alternative.
That’s all it takes: one API key, two environment variables (or one CLI function), and you’re running Claude Code powered by Kimi K2.
No extra installs. No breaking changes. Just faster, cheaper output with full Claude Code compatibility.
Ready to make your online presence shine? I'd love to chat about your project and how we can bring your ideas to life.
Free Consultation 💬