深夜提醒

现在是深夜,建议您注意休息,不要熬夜哦~

🏮 🏮 🏮

新年快乐

祝君万事如意心想事成!

share-image
中
ESC

Configuring Kimi Code in Claude Code: A Complete Usage Guide

English 阅读中文版

Configuring Kimi Code in Claude Code: A Complete Usage Guide

As AI coding assistants diversify, developers want to switch flexibly among different tools. This article details how to configure Kimi Code in Claude Code, so you can enjoy the capabilities of two excellent AI coding assistants at once.
Configuring Kimi Code in Claude Code: A Complete Usage Guide

1. Overview of Claude Code’s Configuration System

Claude Code is configured through a settings.json file and supports the following core features:

  • Custom environment variables: Set API keys, proxies, etc.
  • Hooks: Execute commands when specific events fire
  • MCP servers: Integrate third-party services and tools
  • Permission control: Fine-grained control over tool execution permissions

Config File Locations

# Global config (recommended)
~/.claude/settings.json

# Project-level config
<project-root>/.claude/settings.json

Basic Config Structure

{
"env": {
"ANTHROPIC_API_KEY": "your-api-key"
},
"hooks": {
"PreToolUse": [],
"PostToolUse": []
},
"mcpServers": {},
"permissions": {
"allow": [],
"deny": []
}
}

2. Introduction to Kimi Code

Kimi Code is an AI coding assistant launched by Moonshot AI, with the following features:

  • Long-context support: Supports ultra-long text understanding and code analysis
  • Chinese optimization: Optimized for Chinese developer scenarios
  • Code completion: Intelligent code completion and generation
  • Multi-language support: Supports mainstream languages such as Python, JavaScript, Go, and Rust

3. Prerequisites: Installing Claude Code

If you haven’t installed Claude Code yet, you can refer to the Kimi Code official docs - Third-Party Agent Integration Guide to install it.

Installing Node.js (macOS / Linux)

Using fnm to install Node.js is recommended:

# Install fnm
curl -fsSL https://fnm.vercel.app/install | bash

# Open a new terminal to make fnm take effect
fnm install 24.3.0
fnm default 24.3.0
fnm use 24.3.0

Installing Claude Code

npm install -g @anthropic-ai/claude-code --registry=https://registry.npmmirror.com

Initializing the Config

Skip the first-launch onboarding flow and generate the config file directly:

node --eval "
const fs = require('fs');
const path = require('path');
const os = require('os');
const homeDir = os.homedir();
const filePath = path.join(homeDir, '.claude.json');
if (fs.existsSync(filePath)) {
const content = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
fs.writeFileSync(filePath, JSON.stringify({ ...content, hasCompletedOnboarding: true }, null, 2), 'utf-8');
} else {
fs.writeFileSync(filePath, JSON.stringify({ hasCompletedOnboarding: true }, null, 2), 'utf-8');
}"

Once the installation is done, continue with the Kimi Code configuration steps below.

4. Detailed Configuration Steps

Step 1: Get a Kimi API Key

First, you need to get an API Key on the Kimi open platform:

  1. Visit the Kimi open platform
  2. Register/log in to your account
  3. Go to “API Key Management”
  4. Create a new API Key
  5. Copy and save it safely

Step 2: Configure Environment Variables

Edit Claude Code’s settings.json and add the Kimi-related environment variables:

{
"env": {
"ANTHROPIC_API_KEY": "your-anthropic-api-key",
"KIMI_API_KEY": "your-kimi-api-key",
"KIMI_BASE_URL": "https://api.moonshot.cn/v1"
}
}

Step 3: Configure the Kimi Code MCP Server

Add the Kimi Code MCP server config to settings.json:

{
"mcpServers": {
"kimi-code": {
"command": "npx",
"args": ["-y", "@kimi/code-mcp@latest"],
"env": {
"KIMI_API_KEY": "${KIMI_API_KEY}",
"KIMI_BASE_URL": "${KIMI_BASE_URL}"
}
}
}
}

Or, if you connect via stdio:

{
"mcpServers": {
"kimi-code": {
"type": "stdio",
"command": "kimi-code-mcp",
"args": [],
"env": {
"KIMI_API_KEY": "${KIMI_API_KEY}",
"KIMI_BASE_URL": "${KIMI_BASE_URL}"
}
}
}
}

Step 4: Configure SSE Mode (Optional)

If you want to connect to Kimi Code via HTTP SSE:

{
"mcpServers": {
"kimi-code": {
"type": "sse",
"url": "http://localhost:3000/sse",
"env": {
"KIMI_API_KEY": "${KIMI_API_KEY}"
}
}
}
}

Step 5: Complete Config Example

Here’s a complete settings.json config example:

{
"env": {
"ANTHROPIC_API_KEY": "sk-ant-api03-xxxxxxxx",
"KIMI_API_KEY": "sk-xxxxxxxx",
"KIMI_BASE_URL": "https://api.moonshot.cn/v1"
},
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"pattern": "rm|del|remove",
"command": "echo '⚠️ Warning: executing a delete operation, please confirm' && read -n 1"
}
],
"PostToolUse": []
},
"mcpServers": {
"kimi-code": {
"command": "npx",
"args": ["-y", "@kimi/code-mcp@latest"],
"env": {
"KIMI_API_KEY": "${KIMI_API_KEY}",
"KIMI_BASE_URL": "${KIMI_BASE_URL}"
}
},
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/home/user/projects"]
}
},
"permissions": {
"allow": [
{
"tool": "Bash",
"command": "git *"
},
{
"tool": "Bash",
"command": "npm *"
}
],
"deny": [
{
"tool": "Bash",
"command": "rm -rf /"
}
]
}
}

5. Usage Tips

1. Quickly Switching AI Assistants

In Claude Code, you can use Kimi Code by specifying the tool:

Use kimi-code to analyze the complexity of this function

2. Leveraging Kimi’s Long-Context Advantage

For scenarios that require analyzing large amounts of code or documents:

Please use kimi-code to read the entire src directory of the project and analyze the code architecture

3. Using Claude and Kimi Together

First use kimi-code to analyze the potential issues in this code, then use Claude to give repair suggestions

4. Config File Hot Reload

Claude Code supports hot reloading of the config file—no restart needed after modifying settings.json:

# Run inside Claude Code
/reload

6. Troubleshooting Common Issues

Issue 1: MCP Server Connection Failure

Symptom: The prompt Failed to connect to MCP server

Solutions:

  1. Check whether the API Key is correct
  2. Confirm the network can reach the Kimi API
  3. Check the logs: ~/.claude/logs/mcp-server.log
# Test API connectivity
curl https://api.moonshot.cn/v1/models \
-H "Authorization: Bearer $KIMI_API_KEY"

Issue 2: Permission Denied

Symptom: Tool execution is blocked

Solutions:
Add an allow rule in settings.json’s permissions:

{
"permissions": {
"allow": [
{
"tool": "kimi-code",
"command": "*"
}
]
}
}

Issue 3: Environment Variables Not Taking Effect

Symptom: The prompt says the API Key isn’t set

Solutions:

  1. Confirm the environment variable names are correct
  2. Use absolute paths instead of relative paths
  3. Restart the Claude Code session

Issue 4: Garbled Chinese Output

Solution:
Add this to settings.json:

{
"env": {
"LANG": "zh_CN.UTF-8",
"LC_ALL": "zh_CN.UTF-8"
}
}

7. Advanced Configuration

Customizing Kimi Model Parameters

{
"mcpServers": {
"kimi-code": {
"command": "npx",
"args": ["-y", "@kimi/code-mcp@latest"],
"env": {
"KIMI_API_KEY": "${KIMI_API_KEY}",
"KIMI_MODEL": "kimi-k2-0711-preview",
"KIMI_TEMPERATURE": "0.3",
"KIMI_MAX_TOKENS": "8192"
}
}
}
}

Configuring a Proxy

If a proxy is needed to access the Kimi API:

{
"env": {
"HTTP_PROXY": "http://127.0.0.1:7890",
"HTTPS_PROXY": "http://127.0.0.1:7890",
"KIMI_API_KEY": "your-api-key"
}
}

Project-Level Config Overrides

To use a different Kimi config in a specific project:

// <project>/.claude/settings.json
{
"env": {
"KIMI_MODEL": "kimi-k2-0711-preview"
},
"mcpServers": {
"kimi-code": {
"command": "npx",
"args": ["-y", "@kimi/code-mcp@latest"],
"env": {
"KIMI_API_KEY": "${KIMI_API_KEY}"
}
}
}
}

8. Best Practices

  1. Key management: Don’t hardcode the API Key in the config file—inject it via environment variables

    # In ~/.zshrc or ~/.bashrc
    export KIMI_API_KEY="your-api-key"
  2. Version pinning: Pin the MCP server version to avoid unexpected updates

    "args": ["-y", "@kimi/code-mcp@1.0.0"]
  3. Layered configuration: Set base settings globally and override specific needs per project

  4. Regular backups: Keep a good copy of your settings.json config

  5. Log monitoring: Regularly check MCP logs to troubleshoot issues

    tail -f ~/.claude/logs/mcp-server.log

9. Summary

By configuring Kimi Code in Claude Code, you can:

  • Switch flexibly: Choose the most suitable AI assistant based on the task
  • Complement strengths: Leverage Claude’s coding ability and Kimi’s long-context advantage
  • Unified experience: Manage multiple AI tools in one interface

Once configured, you can freely invoke Kimi Code within Claude Code, enjoying a doubled AI coding experience!


Related resources:

If you have any questions, feel free to leave a comment and discuss!

文章作者:阿文
文章链接: https://www.awen.me/post/7f7fb257.html
版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 阿文的博客!
本文于 2026-04-03 10:00 发布,已超过半年(197天),请注意甄别内容是否已过期。

评论

0 条评论
😀😃😄 😁😅😂 🤣😊😇 🙂🙃😉 😌😍🥰 😘😗😙 😚😋😛 😝😜🤪 🤨🧐🤓 😎🥸🤩 🥳😏😒 😞😔😟 😕🙁☹️ 😣😖😫 😩🥺😢 😭😤😠 😡🤬🤯 😳🥵🥶 😱😨😰 😥😓🤗 🤔🤭🤫 🤥😶😐 😑😬🙄 😯😦😧 😮😲🥱 😴🤤😪 😵🤐🥴 🤢🤮🤧 😷🤒🤕 🤑🤠😈 👿👹👺 🤡💩👻 💀☠️👽 👾🤖🎃 😺😸😹 😻😼😽 🙀😿😾 👍👎👏 🙌👐🤲 🤝🤜🤛 ✌️🤞🤟 🤘👌🤏 👈👉👆 👇☝️✋ 🤚🖐️🖖 👋🤙💪 🦾🖕✍️ 🙏💅🤳 💯💢💥 💫💦💨 🕳️💣💬 👁️‍🗨️🗨️🗯️ 💭💤❤️ 🧡💛💚 💙💜🖤 🤍🤎💔 ❣️💕💞 💓💗💖 💘💝💟 ☮️✝️☪️ 🕉️☸️✡️ 🔯🕎☯️ ☦️🛐⛎ ♈♉♊ ♋♌♍ ♎♏♐ ♑♒♓ 🆔⚛️🉑 ☢️☣️📴 📳🈶🈚 🈸🈺🈷️ ✴️🆚💮 🉐㊙️㊗️ 🈴🈵🈹 🈲🅰️🅱️ 🆎🆑🅾️ 🆘❌⭕ 🛑⛔📛 🚫💯💢 ♨️🚷🚯 🚳🚱🔞 📵🚭❗ ❕❓❔ ‼️⁉️🔅 🔆〽️⚠️ 🚸🔱⚜️ 🔰♻️✅ 🈯💹❇️ ✳️❎🌐 💠Ⓜ️🌀 💤🏧🚾 ♿🅿️🈳 🈂🛂🛃 🛄🛅🛗 🚀🛸🚁 🚉🚆🚅 ✈️🛫🛬 🛩️💺🛰️
加载中...

留言反馈

😀😃😄 😁😅😂 🤣😊😇 🙂🙃😉 😌😍🥰 😘😗😙 😚😋😛 😝😜🤪 🤨🧐🤓 😎🥸🤩 🥳😏😒 😞😔😟 😕🙁☹️ 😣😖😫 😩🥺😢 😭😤😠 😡🤬🤯 😳🥵🥶 😱😨😰 😥😓🤗 🤔🤭🤫 🤥😶😐 😑😬🙄 😯😦😧 😮😲🥱 😴🤤😪 😵🤐🥴 🤢🤮🤧 😷🤒🤕 🤑🤠😈 👿👹👺 🤡💩👻 💀☠️👽 👾🤖🎃 😺😸😹 😻😼😽 🙀😿😾 👍👎👏 🙌👐🤲 🤝🤜🤛 ✌️🤞🤟 🤘👌🤏 👈👉👆 👇☝️✋ 🤚🖐️🖖 👋🤙💪 🦾🖕✍️ 🙏💅🤳 💯💢💥 💫💦💨 🕳️💣💬 👁️‍🗨️🗨️🗯️ 💭💤❤️ 🧡💛💚 💙💜🖤 🤍🤎💔 ❣️💕💞 💓💗💖 💘💝💟 ☮️✝️☪️ 🕉️☸️✡️ 🔯🕎☯️ ☦️🛐⛎ ♈♉♊ ♋♌♍ ♎♏♐ ♑♒♓ 🆔⚛️🉑 ☢️☣️📴 📳🈶🈚 🈸🈺🈷️ ✴️🆚💮 🉐㊙️㊗️ 🈴🈵🈹 🈲🅰️🅱️ 🆎🆑🅾️ 🆘❌⭕ 🛑⛔📛 🚫💯💢 ♨️🚷🚯 🚳🚱🔞 📵🚭❗ ❕❓❔ ‼️⁉️🔅 🔆〽️⚠️ 🚸🔱⚜️ 🔰♻️✅ 🈯💹❇️ ✳️❎🌐 💠Ⓜ️🌀 💤🏧🚾 ♿🅿️🈳 🈂🛂🛃 🛄🛅🛗 🚀🛸🚁 🚉🚆🚅 ✈️🛫🛬 🛩️💺🛰️