kimi-code/apps/kimi-code
Kai 02da587795
feat(cli): wait for background subagents before exiting kimi -p (#1347)
* feat(agent-core): guide the model away from repeating denied or failed tool calls

- system.md: add a diagnose-before-retrying paragraph next to the existing
  permission-denial guidance, covering failed tool calls
- permission: when the user rejects an approval on the main agent, tell the
  model not to re-attempt the exact same call (sub agents already had an
  equivalent hint)

* fix(agent-core): close abandoned tool exchanges and dedupe duplicate tool_use ids

A turn that dies between a recorded tool.call and its paired tool.result
(e.g. a transcript write failure mid-batch) used to leave
pendingToolResultIds open forever: every later message was stranded in
deferredMessages and user input was silently swallowed.

- runOneTurn now defensively closes any dangling tool calls when a turn
  ends (completed, cancelled, or failed), synthesizing an error result
  that names the cause, with a warn log and a tool_exchange_abandoned
  telemetry event
- the projector drops assistant tool calls whose id already appeared
  earlier (first occurrence wins): a duplicate id is wire-invalid on
  strict providers and not repairable by the strict resend; reported via
  the existing projection-repair log and telemetry
- resume-side closePendingToolResults now logs what it closes (warn for
  a mid-history gap, info for the routine trailing interruption)

* chore: add changesets for tool exchange fixes

* fix(agent-core): scope duplicate tool_use id dedup to the strict resend

Unconditional dedup regressed providers that emit per-response counter
ids (e.g. call_0 in every step) and accept their own duplicates: later
tool exchanges silently vanished from the projected history, and a
duplicate call's own recorded result was left dangling.

- the dedupe pass is now opt-in via dedupeDuplicateToolCalls and enabled
  only in strictMessages, so the normal projection keeps the history the
  provider produced
- the pass also drops every tool result after the first for an id, so no
  dangling tool message survives; when the kept call has no result of
  its own, the surviving one is reattached by the adjacency repair
- kosong now classifies the Anthropic "tool_use ids must be unique" 400
  as a recoverable request-structure error so it triggers the strict
  resend

* feat(cli): wait for background subagents before exiting kimi -p

When `background.keep_alive_on_exit` is enabled, `kimi -p` now waits for
all background subagents to reach a terminal state before exiting, bounded
by `background.print_wait_ceiling_s` (default 3600s). This lets concurrent
background subagents run to completion in single-turn runs instead of being
torn down when the main agent's turn ends.
2026-07-03 16:56:16 +08:00
..
scripts feat(kimi-code): vendor @moonshot-ai/pi-tui (#1254) 2026-07-01 20:23:35 +08:00
src feat(cli): wait for background subagents before exiting kimi -p (#1347) 2026-07-03 16:56:16 +08:00
test feat(cli): wait for background subagents before exiting kimi -p (#1347) 2026-07-03 16:56:16 +08:00
.gitignore feat(kimi-code): vendor @moonshot-ai/pi-tui (#1254) 2026-07-01 20:23:35 +08:00
AGENTS.md feat(cli): unify TUI dialog interaction and visuals (#363) 2026-06-03 19:31:07 +08:00
CHANGELOG.md ci: release packages (#1291) 2026-07-02 21:56:42 +08:00
package.json ci: release packages (#1291) 2026-07-02 21:56:42 +08:00
README.md docs: mention Windows Git Bash requirement (#419) 2026-06-04 17:04:02 +08:00
tsconfig.dev.json feat(web): introduce Kimi web app and daemon gateway (#625) 2026-06-17 20:53:46 +08:00
tsconfig.json feat(web): introduce Kimi web app and daemon gateway (#625) 2026-06-17 20:53:46 +08:00
tsdown.config.ts fix: fix bundle (#956) 2026-06-22 13:59:57 +08:00
tsdown.native.config.ts feat(vis): faithful wire.jsonl rendering + built-in kimi vis command (#788) 2026-06-16 16:54:14 +08:00
vitest.config.ts chore: use raw query imports for prompt sources (#682) 2026-06-12 11:47:44 +08:00

@moonshot-ai/kimi-code

The Starting Point for Next-Gen Agents

npm License Docs

What is Kimi Code CLI

Kimi Code CLI is an AI coding agent that runs in your terminal. It can read and edit code, run shell commands, search files, fetch web pages, and choose the next step based on the feedback it receives. It works out of the box with Moonshot AI's Kimi models and can also be configured to use other compatible providers.

Install

The recommended install path is the official script. It does not require Node.js to be installed first.

  • macOS / Linux:
curl -fsSL https://code.kimi.com/kimi-code/install.sh | bash
  • Windows (PowerShell):
irm https://code.kimi.com/kimi-code/install.ps1 | iex

On Windows, install Git for Windows before first launch because Kimi Code CLI uses the bundled Git Bash as its shell environment. If Git Bash is installed in a custom location, set KIMI_SHELL_PATH to the absolute path of bash.exe.

Then run it with a new Terminal session:

kimi --version

Alternative: npm

If you prefer npm, use Node.js 22.19.0 or later:

npm install -g @moonshot-ai/kimi-code

Or with pnpm:

pnpm add -g @moonshot-ai/kimi-code

For upgrade and uninstall instructions, see the Getting Started guide.

Quick Start

Open a project and start the interactive UI:

cd your-project
kimi

On first launch, run /login inside Kimi Code CLI and choose either Kimi Code OAuth or a Kimi Platform API key. After login, try a first task:

Take a look at this project and explain the main directories.

Key Features

  • Single-binary distribution. Install with one command — no Node.js setup, no PATH gymnastics, no global module conflicts.
  • Blazing-fast startup. The TUI is ready in milliseconds, so opening a session never feels heavy.
  • Polished TUI. A carefully tuned interface designed for long, focused agent sessions.
  • Video input. Drop a screen recording or demo clip into the chat — let the agent watch instead of typing out what's hard to describe in words.
  • AI-native MCP configuration. Add, edit, and authenticate Model Context Protocol servers conversationally via /mcp-config — no hand-editing JSON.
  • Subagents for focused, parallel work. Dispatch built-in coder, explore, and plan subagents in isolated context windows; the main conversation stays clean.
  • Lifecycle hooks. Run local commands at key points — gate risky tool calls, audit decisions, fire desktop notifications, wire into your own automation.

Documentation

Repository & Issues

License

MIT