How Kimi Code Performs Code Reviews: A Deep Dive into the Plan-Review Workflow
Kimi Code performs code reviews through a structured "plan-review" workflow that separates generation, decision, and persistence into three coordinated subsystems: plan mode with ExitPlanMode, the ACP approval engine, and transcript-based session handling.
Kimi Code, the AI-powered coding assistant from MoonshotAI, implements automated code reviews through a deterministic, auditable architecture. Unlike simple diff-based tools, it uses a plan-review workflow that generates actionable plans, routes them through a permission layer, and persists the full interaction for replay and debugging. This article examines the source implementation in the MoonshotAI/kimi-code repository.
The Three Core Subsystems
Kimi Code's review architecture cleanly separates concerns across three subsystems. This separation enables consistent behavior across CLI, VS Code, and web interfaces while maintaining full auditability.
Plan Mode and ExitPlanMode Tool
The review process begins when a developer invokes the review skill—typically via /review <file>. This triggers plan mode, a special session state where Kimi Code generates a Markdown plan file describing proposed changes.
The critical transition happens in packages/agent-core/src/tools/builtin/planning/exit-plan-mode.ts. When editing completes, the ExitPlanMode tool executes and emits a plan_review display payload:
// From packages/agent-core/src/tools/builtin/planning/exit-plan-mode.ts (line 110)
if (toolName === 'ExitPlanMode' || display?.kind === 'plan_review') {
const payload: ToolInputDisplay = {
kind: 'plan_review',
plan: planMarkdown, // rendered plan text
options: [
{ label: 'Approve' },
{ label: 'Revise' }
],
};
// payload sent to approval subsystem
}
This payload contains the rendered plan and a default option set. The kind: 'plan_review' discriminator allows downstream components to recognize and handle review-specific displays.
ACP Permission and Approval Engine
The plan_review payload passes to the ACP (Approval Control Plane) in packages/acp-server/src/approval.ts. Here, the system transforms the display into canonical permission options:
// From packages/acp-server/src/approval.ts (lines 78-91)
if (req.display.kind === 'plan_review') {
const options = [
{ id: 'plan_approve', label: 'Approve' },
{ id: 'plan_revise', label: 'Revise' },
// plugin-provided options appear as plan_opt_<i>
];
return { ...req, options };
}
The ACP expands the simple display into structured option IDs that the permission service can interpret deterministically. This expansion happens at lines 78-91, where the server detects display.kind === 'plan_review' and builds the canonical option set.
Session Transcript and Persistence
Every review interaction is recorded in the transcript store, enabling replay, search, and audit. The plan_review display is exposed via packages/kap-server/src/routes/transcript.ts for TUI and web clients:
// From packages/kap-server/src/routes/transcript.ts (lines 562-660)
app.get('/api/v1/transcript/:sessionId', async (req, res) => {
const d = await transcript.getDisplay(req.params.sessionId);
if (d.kind !== 'plan_review') return res.status(404).end();
res.json({ plan: d.plan, options: d.options });
});
This endpoint (spanning lines 562-660 in the source) ensures the review state is accessible to any authorized client.
End-to-End Review Flow
Understanding how Kimi Code performs code reviews requires tracing the complete execution path:
-
Skill invocation: User runs
/review src/app.ts. The skill loader writes a temporary plan file and enters plan mode. -
Plan generation: Kimi Code edits the plan through built-in tools or automated suggestions.
-
ExitPlanMode execution: The tool validates
display?.kind === 'plan_review'and packages the payload. -
ACP processing:
acp-serverdetects the review kind, creates option IDs (plan_approve,plan_revise,plan_opt_<i>), and forwards to the UI. -
User decision: The permission service interprets the choice:
plan_approve→ finalize plan, exit plan modeplan_revise→ re-enter plan mode for editingplan_opt_<i>→ custom plugin handlers
-
Transcript recording: Events like
plan_submittedandplan_resolvedpersist for later analysis.
Permission Service Choice Handling
The permission service implements the state transition logic based on user selection:
// Permission service interpretation
switch (choice.id) {
case 'plan_approve':
// finalize plan, exit plan mode
session.exitPlanMode({ accepted: true });
break;
case 'plan_revise':
// re-enter plan mode for further edits
session.enterPlanMode({ revision: true });
break;
default:
// handle custom option IDs from plugins
pluginRegistry.handleCustomOption(choice.id);
}
This design allows extensible review workflows: plugins can inject additional options via the plan_opt_<i> naming convention without modifying core logic.
Key Implementation Files
| File | Purpose |
|---|---|
packages/agent-core/src/tools/builtin/planning/exit-plan-mode.ts |
Creates plan_review display payload (core trigger) |
packages/acp-server/src/approval.ts |
Transforms review requests into permission options |
packages/kap-server/src/routes/transcript.ts |
Serves review displays via HTTP API |
apps/kimi-code/src/tui/reverse-rpc/approval/adapter.ts |
TUI client-side review handling |
packages/transcript/src/model/meta.ts |
Defines plan metadata (reviewPath, version) |
packages/node-sdk/test/session-skills.test.ts |
End-to-end review skill tests |
Summary
-
Kimi Code performs code reviews through a three-layer architecture: plan generation, permission routing, and transcript persistence.
-
The ExitPlanMode tool in
packages/agent-corecreates the canonicalplan_reviewpayload that triggers the workflow. -
The ACP server expands review displays into actionable permission options with stable IDs like
plan_approveandplan_revise. -
Full session recording enables debugging, compliance, and replay across all supported front-ends.
-
The design supports plugin-extensible options via the
plan_opt_<i>namespace without core modifications.
Frequently Asked Questions
How does Kimi Code enter plan mode for a review?
The review skill triggers plan mode when invoked with /review <file>. The skill loader writes a temporary plan file and switches the session state, as tested in packages/node-sdk/test/session-skills.test.ts. This initialization happens before any ExitPlanMode tool execution.
What happens when a user selects "Revise" in a code review?
The permission service receives choice.id === 'plan_revise' and re-enters plan mode, allowing further edits to the plan file. This creates a loop where the user can iteratively refine proposals before final approval. The round-trip is recorded in the transcript with plan_submitted and subsequent events.
Can custom review options be added to Kimi Code's workflow?
Yes. Plugins can inject additional options that appear as plan_opt_<i> IDs in the ACP expansion. The permission service's default case handler routes these to registered plugins, enabling domain-specific review workflows without modifying packages/acp-server/src/approval.ts.
Where is the review state stored for audit purposes?
The transcript subsystem in packages/transcript persists all review interactions. Plan metadata including reviewPath and version is defined in packages/transcript/src/model/meta.ts, while packages/kap-server/src/routes/transcript.ts exposes this data via the /api/v1/transcript endpoint.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →