Kimi CLI
repository·main·Indexed 27 days ago
https://github.com/moonshotai/kimi-cliAn AI agent for the terminal designed to assist with software development and terminal operations. Kimi CLI can read and edit code, execute shell commands, and search the web. It supports the Agent Client Protocol (ACP) for integration with IDEs like Zed and JetBrains, and provides a Zsh plugin for shell integration. The repository also includes the kimi-sdk for Python, the kosong library for agent orchestration and tool calling, and PyKAOS for OS interaction abstraction.
What's inside kimi-cli
- PyKAOS is a lightweight Python library that provides an abstraction layer for agents to interact with operating systems. It allows for seamless switching between performing file operations and command executions on a local environment or on remote systems via SSH.
Understand ACPKaos Architecture
mainACPKaos is a variant of
LocalKaosdesigned to redirect specific operations to an Agent Client Protocol (ACP) client (such as Zed) while delegating all other operations to the local filesystem. This allows ACP clients to observe and participate in file edits and terminal command executions performed by the agent.Key Redirections:
- Terminal:
execcalls are redirected to ACP terminal operations. - File Reading:
readtextcalls are redirected to ACPfs/read_text_file. - File Writing:
writetextcalls are redirected to ACPfs/write_text_file. - File Appending: Uses ACP only if both
readTextFileandwriteTextFilecapabilities are supported; otherwise, it falls back toLocalKaos.
Important Limitation: Because
stat,exists, andis_filechecks currently useLocalKaos, the system may not recognize files that exist only in an ACP editor's unsaved buffers. These files will returnfalsefor existence checks until they are saved to the local disk.- Terminal:
Understand Agent Skills vs Plugins
mainKimi Code CLI uses two distinct extension mechanisms:
- Skills: Knowledge-based guidance provided via a
SKILL.mdfile. The AI reads and follows these specifications (e.g., code styles, workflows, best practices). - Plugins: Executable tools declared through
plugin.json. The AI can directly invoke these tools to perform actions like API calls, scripts, or database queries.
Use Skills for defining how the AI should think or act, and Plugins for giving the AI tools to perform tasks.
- Skills: Knowledge-based guidance provided via a
Kimi Code CLI usage modes
mainKimi Code CLI provides three primary ways to interact with the AI agent:
- Interactive CLI (
kimi): Chat with the AI in the terminal using natural language or execute shell commands directly. - Browser UI (
kimi web): A graphical interface in your local browser featuring session management, file references, and code highlighting. - Agent integration (
kimi acp): Run as a service to integrate with IDEs and other local agent clients via the [Agent Client Protocol].
- Interactive CLI (
Use built-in tools and manage security
mainKimi CLI includes several built-in tools for agents.
Default Tools:
Task,SetTodoList,Shell,ReadFile,Glob,Grep,WriteFile,StrReplaceFile,SearchWeb,FetchURL.Optional Tools (must be enabled in Agent file):
Think,SendDMail,CreateSubagent.Security & Approvals:
- Tools are restricted by working directory limits.
- File modifications include a
diffpreview for user review. - Use the
--yoloor--auto-approveflag to bypass manual approval prompts.
Understand Kimi CLI Architecture and Modes
mainKimi CLI is designed as an AI-shell that provides an agent kernel through multiple communication modes. Beyond the standard terminal interface, it supports:
- Print mode: For standard output.
- Wire mode: Uses
stdioto accept user prompts and push agent behavior events via a specific format. This mode powers the internal Web UI and VS Code extension. - ACP mode: Provides an ACP server (via
stdio) that allows Kimi CLI to integrate with any ACP client, including JetBrains, Zed, DeepChat, and Alma.
Users can also extend Kimi CLI using MCP tools and skills or customize the agent by providing specific agent files containing system prompts and tool lists.
Initialize project context with /init
mainIf your project lacks anAGENTS.mdfile, run the/initcommand. This allows Kimi Code CLI to analyze your project and generate the file, which helps the AI better understand your project structure and conventions./initManage sessions and context
mainSession Management
- Resuming Sessions: Use
--continue,--session, or the/sessionsslash command to resume previous work. - Session Replay: The CLI supports starting a replay of previous sessions.
Context Control
- Clear Context: Use
/clear(or its alias/reset) to wipe the current conversation context. - Compact Context: Use
/compactto compress the current context to save tokens/space.
- Resuming Sessions: Use
Override provider settings with environment variables
mainEnvironment variables allow you to inject keys or change endpoints without modifying your configuration files. This is ideal for CI/CD or switching environments.
Overrides are determined by the provider
type:- For providers with
type = "kimi": UseKIMI_*environment variables. - For providers with
type = "openai_legacy"ortype = "openai_responses": UseOPENAI_*environment variables. - Other provider types do not support environment variable overrides.
Refer to the environment variables documentation for a full list of supported keys.
- For providers with
Launch and configure Kimi CLI
mainLaunching
To start the Kimi CLI, run the following command in your project directory:
kimiInitial Configuration
Use the
/setupslash command to configure your platform and model settings.Discovering Commands
Use the
/helpslash command to view available commands and usage information.Enable YOLO mode for automatic approvals
mainYOLO mode automatically approves all tool calls to remove approval friction. It does not prevent the agent from asking clarifying questions via
AskUserQuestionif a decision is ambiguous. When active, a yellow YOLO badge appears in the status bar.To enable YOLO mode:
- Start the CLI with the
--yoloflag. - Toggle it during runtime using the
/yolocommand. - Set
default_yolo = truein your configuration file for permanent activation.
# Enable at startup kimi --yolo # Or toggle during runtime /yolo- Start the CLI with the
Workflow for Plan Mode
mainWhen operating in Plan Mode, follow this structured workflow:
- Identify Key Questions: Determine 2-3 critical questions about the codebase. If you are unsure of the structure, use
Agent(subagent_type="explore")to investigate first. - Explore Codebase: Use read-only tools like
Glob,Grep, andReadFilefor quick lookups. - Design Approach: Formulate an implementation strategy based on your findings.
- Write Plan: Document the implementation approach in a plan file.
- Present for Approval: Use
ExitPlanModeto present the final plan to the user for sign-off.
- Identify Key Questions: Determine 2-3 critical questions about the codebase. If you are unsure of the structure, use