Skip to content

feat(cli): add kimi import command for cross-tool session transfer#2141

Open
NOLANeight wants to merge 2 commits into
MoonshotAI:mainfrom
NOLANeight:feat/import-session-from-claude-code
Open

feat(cli): add kimi import command for cross-tool session transfer#2141
NOLANeight wants to merge 2 commits into
MoonshotAI:mainfrom
NOLANeight:feat/import-session-from-claude-code

Conversation

@NOLANeight

@NOLANeight NOLANeight commented Jul 24, 2026

Copy link
Copy Markdown

Summary

Add kimi import CLI command for importing session context from external AI coding tools into Kimi Code. Enables migrating conversation history, tool activity, and project context. Starting with Claude Code support. Closes #2102.

Changes

  • New: apps/kimi-code/src/cli/import/sources/types.ts — SourceParser interface + HandoffContext types
  • New: apps/kimi-code/src/cli/import/sources/claude-code.ts — Claude Code session JSONL parser
  • New: apps/kimi-code/src/cli/sub/import.ts — kimi import CLI command
  • New: apps/kimi-code/test/cli/import.test.ts — 5 tests
  • Modified: apps/kimi-code/src/cli/commands.ts — register import command

Usage

kimi import --from claude-code (interactive), --session, --prompt, --file, --print

How it works

Scans CC sessions → parses JSONL → generates handoff Markdown → harness.createSession() + session.importContext() → persisted, resumable via kimi -r

Verification

pnpm typecheck: clean | oxlint: 0/0 | vitest: 5/5 new, 18/18 total | tested with real CC sessions

Add session import CLI command supporting Claude Code as first source. Closes MoonshotAI#2102.
@changeset-bot

changeset-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9ab749c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1d39c77c62

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

reject(new Error(`${event.code}: ${event.message}`));
return;
}
if (event.type === 'turn.ended') {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Wait only for the main prompt turn to finish

When kimi import --prompt runs a prompt that spawns a subagent or other non-main agent, that agent can emit turn.ended before the main follow-up prompt is done; this listener resolves immediately and the code closes the session afterward, cutting off the active main turn. Track the main agent/turn completion (and non-completed reasons) before resolving.

Useful? React with 👍 / 👎.

for (const tr of toolResults) {
conversation.push({
kind: 'tool-result',
toolName: lastToolCallName || 'tool',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Map tool results by their tool_use_id

When an assistant message contains multiple tool_use blocks before the following user message returns their tool_result blocks, every result is labeled with only the last tool name because tool_use_id is ignored. This corrupts the imported handoff history for common multi-tool turns; keep an id-to-name map and use tr.tool_use_id when building each result.

Useful? React with 👍 / 👎.

}

if (input === 0 && output === 0) return undefined;
return { input, output, ...(cacheRead > 0 ? { cacheRead } : {}), ...(cacheCreation > 0 ? { cacheCreation } : {}) };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Replace conditional spreads for optional fields

This new object literal uses conditional spreads for optional properties, and the same pattern appears later in the new parser; the local coding requirements explicitly say optional object properties should be passed as undefined directly instead. Please rewrite these as direct optional fields so the new import code follows the app-wide convention.

AGENTS.md reference: apps/kimi-code/AGENTS.md:L66-L69

Useful? React with 👍 / 👎.

- Track main agent turn.ended to avoid subagent race condition\n- Use tool_use_id map for multi-tool result labeling\n- Replace conditional spreads with direct undefined assignments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

希望新增功能:转移Claude Code的上下文到KIMI CODE中

1 participant