Kimi Code CLI: Moonshot AI's Open-Source Terminal Agent Takes on Claude Code
Kimi Code CLI Ultra-Detailed Tutorial, with Source Code
Author: A programmer wrestling with AI in the terminal
1. Why This Is Needed
Last Thursday at 2 a.m., I was still fixing a bug in a legacy project.
The requirement was simple: change an API's response format from XML to JSON. Sounds easy? In reality, the XML parsing code for this module was scattered across 5 files, each with its own way of handling things.
I spent 3 hours manually grepping, reading, modifying, and testing. After the changes, I found I'd missed a spot—an edge case wasn't covered.
That's when I thought: I've already used Claude Code, and it works well, but it's closed-source. I wanted an open-source alternative, preferably one I could tinker with myself.
So I discovered Kimi Code CLI.
Released by Moonshot AI, it has 8.4k GitHub stars and an Apache-2.0 open-source license. Its positioning is clear: an AI programming agent in the terminal, targeting Claude Code and Gemini CLI as competitors.
I tried it for a week, and the result—it's genuinely impressive.
2. Environment Setup
2.1 System Requirements
- Linux / macOS / Windows (PowerShell)
- Python 3.12–3.14 (3.13 recommended)
- Network access to the Moonshot AI API
2.2 Installation
A single command does it:
curl -LsSf https://code.kimi.com/install.sh | bash
Windows users use PowerShell:
Invoke-RestMethod https://code.kimi.com/install.ps1 | Invoke-Expression
The installation script automatically installs uv (a Python package manager) for you, then uses uv to install kimi-cli.
Verify it:
kimi --version
# Output similar to: kimi-cli 1.41.0
⚠️ Pitfall 1: The first time you run
kimi, it might be painfully slow. macOS security checks will block it. Go to "System Settings → Privacy & Security → Developer Tools" and add your terminal application; it'll be fast afterward.
2.3 Login Configuration
Enter your project directory and run kimi:
cd your-project
kimi
On first launch, you'll be prompted to configure an API source. Type /login:
/ login
Choose a platform—Kimi Code is recommended; it automatically opens a browser for OAuth authorization. Choosing other platforms requires manually entering an API key.
After configuration, it saves automatically and restarts; no further action is needed.
3. Core Usage
3.1 Basic Interaction
Once inside kimi, just talk to it directly:
> Help me look at this project's directory structure
It will list it out for you.
If the project doesn't have an AGENTS.md file, run /init:
/init
Kimi analyzes the project structure and automatically generates this file, allowing it to better understand your coding conventions afterward.
3.2 Real-World Case: XML to JSON
Back to that 2 a.m. bug. This time I used Kimi:
> Change the XML responses in this project to JSON format, keeping the original logic unchanged
It started working:
- Scanned the codebase—found all XML-related files
- Generated a plan—listed the files to change and specific modification points
- Executed modifications—changed files one by one
- Verified—ran tests to confirm nothing broke
The whole process took about 5 minutes. I checked, and almost everything was changed correctly; only one edge case was missed, which I manually patched.
Compared to the 3 hours of manual changes last time, this saved at least 2.5 hours.
3.3 Terminal Command Mode
Press Ctrl-X to switch to shell command mode:
> Directly execute ls -la
You can run shell commands without exiting kimi, which is quite convenient.
⚠️ Pitfall 2: Built-in commands like
cdare currently unsupported. To change directories, you must exitkimiand re-enter.
3.4 Web UI Mode
If the terminal interface isn't intuitive enough, you can open the Web UI:
kimi web
This opens a graphical interface in your local browser, supporting session management, file references, and code highlighting.
3.5 VS Code Integration
There's an official VS Code extension:
- Open VS Code
- Go to the extension marketplace and search for "Kimi Code"
- Install
moonshot-ai.kimi-code - Log in and start using it
The interface is similar to the Claude Code extension: a sidebar chat with code block operations.
3.6 ACP Integration (Zed / JetBrains)
If you use Zed or JetBrains IDEs, you can use the Agent Client Protocol:
First, log in with /login, then add this to your IDE configuration:
{
"agent_servers": {
"Kimi Code CLI": {
"type": "custom",
"command": "kimi",
"args": ["acp"],
"env": {}
}
}
}
Restart the IDE and it's ready to use.
3.7 Zsh Integration
Install a plugin and press Ctrl-X to directly enter agent mode:
git clone https://github.com/MoonshotAI/zsh-kimi-cli.git \
${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/kimi-cli
Then add kimi-cli to the plugins list in ~/.zshrc:
plugins=(... kimi-cli)
3.8 MCP Support
Kimi has built-in MCP (Model Context Protocol) management:
# Add an HTTP-type MCP server
kimi mcp add --transport http context7 https://mcp.context7.com/mcp --header "CONTEXT7_API_KEY: your-key"
# Add an OAuth-authenticated MCP server
kimi mcp add --transport http --auth oauth linear https://mcp.linear.app/mcp
# Add a stdio-type MCP server
kimi mcp add --transport stdio chrome-devtools -- npx chrome-devtools-mcp@latest
# View configured servers
kimi mcp list
# Remove a server
kimi mcp remove chrome-devtools
4. Performance Comparison
I tried the same task with three tools:
| Tool | Time | Accuracy | Notes |
|---|---|---|---|
| Claude Code | ~3 min | 95% | Requires internet, closed-source |
| Kimi Code CLI | ~5 min | 90% | Open-source, self-hostable |
| Manual | ~45 min | 100% | Pure human effort |
Kimi is slightly slower, but accuracy is comparable. The key point is open-source—you can deploy the model yourself, and data stays within your internal network, which is important for certain scenarios.
5. FAQ
Q1: How to choose between Kimi Code CLI and Claude Code?
Choose Kimi when:
- You need open-source / self-hostable
- Data is sensitive and cannot leave the internal network
- You want to tinker with the underlying system
Choose Claude Code when:
- You pursue ultimate accuracy
- You don't want to fiddle with configuration
- You've already subscribed to Anthropic
Q2: Why are responses sometimes slow?
Possible reasons:
- Network issues—Kimi's API can be unstable domestically at times
- The project is too large—first-time analysis of the project structure takes time
- High model load—Moonshot's servers sometimes have queues
Solution: Try /model to switch models, or wait a few minutes and try again.
Q3: Can it be deployed locally?
Yes, but it's a bit troublesome. Kimi Code CLI defaults to using Moonshot's API. To run it locally, you need to set up a compatible API server yourself. The official documentation doesn't detail this; the community is working on it, but it's not yet mature.
Q4: How does it compare to Cursor?
Cursor is an IDE; Kimi is a CLI tool. Their positioning is different.
- Cursor: Suitable for daily coding; AI modifies code directly in the editor
- Kimi: Suitable for batch tasks, complex refactoring, terminal automation
I use both, switching depending on the scenario.
Q5: Is there a charge?
Kimi Code CLI itself is free. Using Moonshot's API has a free quota; exceeding it incurs charges. Check the official website for specifics.
6. Summary
Kimi Code CLI is currently one of the best open-source AI programming CLIs out there.
Pros:
- Open-source, auditable
- Full-featured (CLI + Web UI + IDE integration + MCP)
- Good Chinese language support (it's domestic, after all)
- Sufficient free quota
Cons:
- Occasionally slow
- Local deployment is not yet mature
- Community ecosystem is smaller than Claude Code's
If you're looking for an open-source alternative to Claude Code, or want to try an AI programming agent, Kimi Code CLI is worth picking up.
If you found this helpful, feel free to like and bookmark ❤️ For more practical AI tool tutorials, follow me for first access~