Kimi CLI

repository·main·Indexed 27 days ago

https://github.com/moonshotai/kimi-cli

An 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.

Tokens
73K
Snippets
185
Records
454
Agent score
94%

What's inside kimi-cli

  1. Understand ACPKaos Architecture

    main

    ACPKaos is a variant of LocalKaos designed 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: exec calls are redirected to ACP terminal operations.
    • File Reading: readtext calls are redirected to ACP fs/read_text_file.
    • File Writing: writetext calls are redirected to ACP fs/write_text_file.
    • File Appending: Uses ACP only if both readTextFile and writeTextFile capabilities are supported; otherwise, it falls back to LocalKaos.

    Important Limitation: Because stat, exists, and is_file checks currently use LocalKaos, the system may not recognize files that exist only in an ACP editor's unsaved buffers. These files will return false for existence checks until they are saved to the local disk.

  2. Understand Agent Skills vs Plugins

    main

    Kimi Code CLI uses two distinct extension mechanisms:

    • Skills: Knowledge-based guidance provided via a SKILL.md file. 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.

  3. Kimi Code CLI usage modes

    main

    Kimi 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].
  4. Use built-in tools and manage security

    main

    Kimi 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 diff preview for user review.
    • Use the --yolo or --auto-approve flag to bypass manual approval prompts.
  5. Understand Kimi CLI Architecture and Modes

    main

    Kimi 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 stdio to 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.

  6. Manage sessions and context

    main

    Session Management

    • Resuming Sessions: Use --continue, --session, or the /sessions slash 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 /compact to compress the current context to save tokens/space.
  7. Override provider settings with environment variables

    main

    Environment 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": Use KIMI_* environment variables.
    • For providers with type = "openai_legacy" or type = "openai_responses": Use OPENAI_* environment variables.
    • Other provider types do not support environment variable overrides.

    Refer to the environment variables documentation for a full list of supported keys.

  8. Enable YOLO mode for automatic approvals

    main

    YOLO mode automatically approves all tool calls to remove approval friction. It does not prevent the agent from asking clarifying questions via AskUserQuestion if a decision is ambiguous. When active, a yellow YOLO badge appears in the status bar.

    To enable YOLO mode:

    • Start the CLI with the --yolo flag.
    • Toggle it during runtime using the /yolo command.
    • Set default_yolo = true in your configuration file for permanent activation.
    # Enable at startup
    kimi --yolo
    
    # Or toggle during runtime
    /yolo
  9. Workflow for Plan Mode

    main

    When operating in Plan Mode, follow this structured workflow:

    1. 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.
    2. Explore Codebase: Use read-only tools like Glob, Grep, and ReadFile for quick lookups.
    3. Design Approach: Formulate an implementation strategy based on your findings.
    4. Write Plan: Document the implementation approach in a plan file.
    5. Present for Approval: Use ExitPlanMode to present the final plan to the user for sign-off.