kimi-code guide

Overview

kimi-code (lmctl-ai/kimi-code) is the lmctl-maintained fork of Moonshot AI's Kimi Code CLI. It serves as an AI coding agent in the terminal (kimi), a headless JSON-streaming CLI (kimi -p), and an Agent Client Protocol backend (kimi acp) for lmctl, Zed, and JetBrains IDEs. The fork resolves a critical session-restore wedge across ACP and non-ACP hosts and introduces batched delivery of queued prompts.

Fork fix 1: Healing acp-runtime-after-reap on session restore

In stock Kimi Code CLI, when an ACP session (kimi acp) runs, it persists an agent runtime binding of the form acp:<sessionId> inside the session state. If that session is later resumed by a non-ACP host — such as the interactive TUI, kap-server, or headless kimi -p after the ACP process was reaped — the non-ACP host never registers the acp:<sessionId> runtime. As a result, the model continues to chat, but every tool invocation and subagent spawn (coder, explore, plan) fails permanently with runtime <id> does not exist in workspace <id>.

The patch in packages/agent-core-v2/src/agent/runtimeBinding/agentRuntime.ts (submitted upstream as PR #3563 for issue #3562) detects an unregistered runtime binding on first use after session restore and automatically rebinds the session to the host's active local runtime, restoring full tool and subagent execution seamlessly.

Fork fix 2: Batched delivery of queued prompts

In upstream Kimi Code CLI, prompts sent while the agent is busy executing a turn are delivered strictly one at a time, triggering a separate model turn for each queued message. In lmctl multi-agent workflows where coordinators or peers enqueue multiple follow-up instructions during an active turn, single-message delivery causes unnecessary turn churn and partial answers.

This fork (submitted upstream as PR #4052 for issue #4051) delivers all prompts queued at the moment a turn finishes together in the very next turn in FIFO order (each preserved as a distinct user message), allowing the model to read and address the entire batch in a single response. Prompts sent while the agent is idle behave identically to upstream.

Configuration, custom providers, and auto-update protection

The current v2 JavaScript CLI stores its configuration under ~/.kimi-code/ (not legacy ~/.kimi/):