MoonshotAI / MoonshotAI/kimi-code
feat: emit thinking in stream-json (JSONL or documented stderr • block)
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 7.5k
- Forks
- 1.2k
- Avg merge
- 11h 53m
- Merged PRs (30d)
- 350
Description
What feature would you like to see?
Please emit model thinking during kimi -p --output-format stream-json. Either of these is enough:
- Preferred for machines: a JSONL field on stdout (
reasoning_content, athinkingcontent block, or athinking.deltameta line), or - Also fine: the documented print-mode
•thinking block on stderr, whichPromptTranscriptWriteralready writes in text-p.
Today thinking.delta events exist and both print drivers forward them to PromptJsonWriter.writeThinkingDelta(), but that method is a no-op. Tool progress still goes to stderr; the resume hint is a stdout meta line. Headless hosts therefore sit silent for the entire reasoning window.
Additional information
Official docs (current docs/en/reference/kimi-command.md)
In
stream-jsonmode, regular replies produce an Assistant message; when the model calls a tool, an Assistant message withtool_callsis emitted first, followed by the corresponding Tool message, then subsequent Assistant messages. Thinking content is not written to JSONL; tool progress and "resuming session" notices are still written to stderr.
Print-mode text (-p without stream-json) documents thinking on stderr:
Output uses a transcript style: thinking content and Assistant text are both prefixed with
•, and wrapped lines are indented by two spaces. Assistant text goes to stdout; thinking, tool progress, and "resuming session" notices go to stderr.
PromptJsonWriter.writeThinkingDelta() is a no-op
apps/kimi-code/src/cli/prompt-render.ts:
export class PromptJsonWriter implements PromptTurnWriter {
// …
writeThinkingDelta(): void {}
Compare PromptTranscriptWriter.writeThinkingDelta, which writes the • block to stderr.
Both print drivers already call it:
apps/kimi-code/src/cli/run-prompt.ts—case 'thinking.delta': outputWriter.writeThinkingDelta(event.delta);apps/kimi-code/src/cli/v2/run-v2-print.ts— same
Same files, still in stream-json:
tool.progresswritesevent.update.textto stderrwriteResumeHint(..., 'stream-json', ...)writes{ "role": "meta", "type": "session.resume_hint", ... }on stdout
Verified on official 0.39.1: a live isolated-home kimi -p … --output-format stream-json capture never emitted a thinking JSONL field or a • stderr block.
Suggested shapes (pick one)
JSONL on stdout:
{"role":"assistant","reasoning_content":"…thinking text…"}
or a content block:
{"role":"assistant","content":[{"type":"thinking","thinking":"…"}]}
or streaming deltas:
{"role":"meta","type":"thinking.delta","delta":"…"}
Or, if you prefer not to change JSONL: write the same • stderr block PromptTranscriptWriter already uses, so stream-json matches the documented print-mode thinking channel.
Related: #3080 (same print path — PromptJsonWriter also drops turn.step.completed usage).
Use case: orchestration hosts that wrap kimi -p --output-format stream-json (same pattern as Claude / Cursor stream-json) have no thinking signal, so the UI shows only a spinner until the first assistant / tool_calls line.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in apps/kimi-code/src/cli/prompt-render.ts, where PromptJsonWriter.writeThinkingDelta() is currently a no-op, and compare it with PromptTranscriptWriter.writeThinkingDelta(). Trace the existing thinking.delta handling in apps/kimi-code/src/cli/run-prompt.ts and apps/kimi-code/src/cli/v2/run-v2-print.ts. Done means stream-json exposes thinking through one documented JSONL or stderr path without breaking the existing tool-progress and resume-hint behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100