# How to Use Kimi-Code for Code Analysis: Complete Guide to TUI and ACP Workflows

> Master Kimi-Code for code analysis with our guide. Explore TUI and ACP workflows to understand and leverage its powerful sub-agents for insights.

- Repository: [Moonshot AI/kimi-code](https://github.com/MoonshotAI/kimi-code)
- Tags: how-to-guide
- Published: 2026-08-11

---

**Kimi-Code analyzes codebases through an interactive terminal UI or programmatically via the Agent Client Protocol (ACP), using sub-agents like `explore` to search indexed repositories and generate structured insights.**

Kimi-Code is an AI-powered coding assistant developed by MoonshotAI that runs in a terminal UI (TUI) and can be integrated into editors through the Agent Client Protocol (ACP). Whether you need quick architectural overviews or deep programmatic analysis, Kimi-Code provides two distinct interfaces—interactive and headless—to fit your workflow.

## Architecture Overview: How Kimi-Code Analyzes Code

Understanding Kimi-Code's layered architecture helps you choose the right entry point for code analysis.

### Core Components

- **CLI/TUI** (`apps/kimi-code/src/tui`) – Renders the terminal interface, handles keyboard input, and drives session lifecycle.
- **Agent Engine v1** (`packages/agent-core`) – Orchestrates agents, manages sub-agents, tool selection, and turn-based interaction.
- **Agent Engine v2** (`packages/agent-core-v2`) – DI-driven engine with lifecycle scopes (`App → Workspace → Session → Agent`) used by the server side.
- **Protocol Layer** (`packages/protocol`) – Zod-validated request/response schemas and WebSocket control messages.
- **Transcript Store** (`packages/transcript`) – Immutable log of all interactions for replay and debugging.
- **Search Index** (`packages/minidb`) – Fast full-text search backed by JSON document store with WAL persistence.
- **Server** (`packages/kap-server`) – Exposes REST + WebSocket endpoints for remote agents via ACP.

The **search index** in `packages/minidb` and the **transcript store** in [`packages/transcript/src/store/transcriptStore.ts`](https://github.com/MoonshotAI/kimi-code/blob/main/packages/transcript/src/store/transcriptStore.ts) are particularly critical for code analysis, enabling fast lookups and complete session reproducibility.

## Interactive TUI Workflow for Code Analysis

The terminal interface provides the fastest path to analyzing code.

### Step 1: Launch and Authenticate

Run `kimi` in your project directory. The TUI boots in milliseconds thanks to aggressive lazy loading.

```bash
cd /path/to/project
kimi

```

Once loaded, authenticate:

```

/login

```

Use OAuth or an API key depending on your setup.

### Step 2: Request Analysis

Type natural-language queries directly:

```

Explain the architecture of the agent-core package

```

### Step 3: Agent Selection and Execution

Kimi-Code's engine automatically selects the **explore sub-agent** defined in [`packages/agent-core-v2/src/features/explore/profile/explore.ts`](https://github.com/MoonshotAI/kimi-code/blob/main/packages/agent-core-v2/src/features/explore/profile/explore.ts). This agent:

1. Queries the **MiniDB search index** ([`packages/minidb/src/minidb.ts`](https://github.com/MoonshotAI/kimi-code/blob/main/packages/minidb/src/minidb.ts)) for relevant files
2. Executes targeted searches across the codebase
3. Synthesizes findings into a structured response

### Step 4: Interact with Results

The TUI displays results with follow-up actions:

- Open files directly in your configured editor
- Run shell commands suggested by the agent
- Spawn the **coder sub-agent** to implement changes based on analysis

## Programmatic ACP Analysis with Klient

For integration into scripts, CI pipelines, or IDE extensions, use the ACP client.

### Minimal Analysis Script

```typescript
import { createKlient } from '#/packages/klient';

// Connect to locally-running Kimi-Code server
const klient = await createKlient({ url: 'http://localhost:3000/api/v1' });

// Start a new session
const session = await klient.session.create({});

// Ask the explore agent to summarize the agent-core package
const reply = await session.agent('explore').ask(
  'Give me a high-level overview of the agent-core package and its main entry points.'
);

console.log(reply.text);

```

The `klient` facade in [`packages/klient/src/client.ts`](https://github.com/MoonshotAI/kimi-code/blob/main/packages/klient/src/client.ts) wraps the protocol defined in `packages/protocol`, handling WebSocket connections, request validation, and response streaming.

### Starting the Server

First, launch the Kimi-Code server that powers ACP connections:

```bash
kimi server --port 3000

# or for ACP specifically

kimi /acp

```

The server entry point in [`packages/kap-server/src/server.ts`](https://github.com/MoonshotAI/kimi-code/blob/main/packages/kap-server/src/server.ts) initializes the v2 agent engine, registers features like `explore`, and exposes REST endpoints at `/api/v1`.

## Deep-Dive: Key Analysis Features

### Full-Text Search with MiniDB

The `packages/minidb` layer provides Kimi-Code's fast code search. Unlike naive grep, it maintains a persisted JSON document store with:

- Write-ahead logging for durability
- Full-text indexing with ranking
- Incremental updates as files change

This enables the **explore agent** to answer queries like "find all usages of the Session class" in sub-second times even on large repositories.

### Session Replay and Debugging

Every interaction is stored immutably in [`packages/transcript/src/store/transcriptStore.ts`](https://github.com/MoonshotAI/kimi-code/blob/main/packages/transcript/src/store/transcriptStore.ts). Benefits include:

- Complete conversation history with tool calls and their outputs
- Step-by-step replay via `apps/kimi-inspect` UI
- Export to markdown for documentation
- Regression testing of agent behavior

### Sub-Agent Specialization

Kimi-Code routes analysis tasks to specialized agents:

| Agent | Purpose | Source Location |
|-------|---------|-----------------|
| **explore** | Codebase navigation, architecture summaries, finding definitions | [`packages/agent-core-v2/src/features/explore/profile/explore.ts`](https://github.com/MoonshotAI/kimi-code/blob/main/packages/agent-core-v2/src/features/explore/profile/explore.ts) |
| **coder** | Implementation, refactoring, test generation | [`packages/agent-core-v2/src/features/coder/profile/coder.ts`](https://github.com/MoonshotAI/kimi-code/blob/main/packages/agent-core-v2/src/features/coder/profile/coder.ts) |
| **plan** | Task decomposition, design documentation | [`packages/agent-core-v2/src/features/plan/profile/plan.ts`](https://github.com/MoonshotAI/kimi-code/blob/main/packages/agent-core-v2/src/features/plan/profile/plan.ts) |

## Performance Optimization for Large Codebases

When analyzing massive repositories, Kimi-Code employs several strategies:

- **Lazy indexing** – Only relevant files are loaded into MiniDB per query
- **Input latency tracking** – [`apps/kimi-code/src/tui/utils/input-latency.ts`](https://github.com/MoonshotAI/kimi-code/blob/main/apps/kimi-code/src/tui/utils/input-latency.ts) measures UI responsiveness
- **Streaming responses** – Partial results appear before completion
- **Agent context windows** – v2 engine manages memory across long sessions

## Summary

- **Kimi-Code offers two analysis modes**: interactive TUI (`kimi` command) and programmatic ACP (`klient` library)
- **Core analysis pipeline**: explore sub-agent → MiniDB search → synthesized response with source citations
- **Key integration points**: `packages/klient` for clients, `packages/kap-server` for servers, `packages/protocol` for custom implementations
- **All sessions are reproducible** via the immutable transcript store in `packages/transcript`

## Frequently Asked Questions

### Can I use Kimi-Code for code analysis without the terminal UI?

Yes. Run `kimi server` or `kimi /acp` to start the backend, then use `createKlient()` from `packages/klient` to drive analysis programmatically. This enables headless operation in CI/CD pipelines or custom tools.

### How does the explore agent find relevant code so quickly?

It queries the MiniDB full-text index ([`packages/minidb/src/minidb.ts`](https://github.com/MoonshotAI/kimi-code/blob/main/packages/minidb/src/minidb.ts)), which maintains a persisted, incrementally updated search layer over your repository. This beats raw filesystem traversal by orders of magnitude.

### Where are my analysis sessions stored?

All turns, tool calls, and responses are written to the **transcript store** ([`packages/transcript/src/store/transcriptStore.ts`](https://github.com/MoonshotAI/kimi-code/blob/main/packages/transcript/src/store/transcriptStore.ts)). You can replay sessions via `kimi-inspect` or export them for documentation.

### Can I extend Kimi-Code with custom analysis agents?

Yes. The v2 agent engine in `packages/agent-core-v2` uses dependency injection and feature registration. Implement the `Feature` interface, register your agent profile, and the engine will route appropriate queries to it.