How to Customize the Output of Kimi-CLI: Complete Guide to Output Formats
You can customize Kimi-CLI's output by using the --output-format flag alongside the --print UI mode, selecting from built-in formats like text and json, or extending the OutputFormat enum to add custom renderers.
Kimi-CLI, the official command-line interface for MoonshotAI's models, provides granular control over how assistant responses are displayed through its print-based UI system. Whether you need human-readable plain text for terminal interaction or structured JSON for programmatic pipelines, understanding how to customize the output of kimi-cli requires navigating the CLI option definitions, the Print UI controller, and the visualization layer that handles final rendering.
Built-In Output Format Options
Using the --output-format Flag
The primary mechanism for output customization is the --output-format option, defined in the CLI entry point at src/kimi_cli/cli/__init__.py (lines 262-267). This Typer argument accepts values corresponding to the OutputFormat enumeration, defaulting to text when unspecified.
To retrieve structured data suitable for parsing by other tools:
kimi run --print --output-format json "List the top 3 Python data validation libraries"
For standard conversational output:
kimi run --print --output-format text "Explain the concept of lazy evaluation"
Quiet Mode (--quiet)
The --quiet flag provides a convenience shortcut that forces plain text output and displays only the final assistant message, suppressing system messages, metadata headers, and intermediate reasoning chains. According to the source logic, this flag effectively sets --output-format text combined with --final-message-only.
kimi run --quiet "Summarize the key points in 50 words"
Architecture of Output Formatting
CLI Entry Point (src/kimi_cli/cli/__init__.py)
The output format journey begins in src/kimi_cli/cli/__init__.py, where the Typer CLI framework registers the --output-format option (lines 262-267). This definition maps user input strings to the internal OutputFormat type used throughout the application.
Print UI Controller (src/kimi_cli/ui/print/__init__.py)
When you invoke the CLI with the --print flag, the application instantiates the Print UI class located in src/kimi_cli/ui/print/__init__.py. This controller receives the output_format parameter from the CLI and orchestrates the rendering pipeline, passing the format specification down to the visualization layer.
The Visualize Function (src/kimi_cli/ui/print/visualize.py)
The actual rendering logic resides in src/kimi_cli/ui/print/visualize.py within the visualize function. Lines 169-177 contain a match output_format block that branches execution based on the enum value, applying the appropriate formatter before writing to stdout.
Adding Custom Output Formats
To introduce new formats such as YAML, Markdown, or a bespoke binary protocol:
-
Extend the Enum: Add your format identifier to the
OutputFormattype definition, typically located in the types module within the print UI package. -
Implement the Renderer: In
src/kimi_cli/ui/print/visualize.py, add a new case to thematch output_formatblock around line 169. Implement your custom serialization logic to transform the assistant's response into your desired structure. -
Invoke Your Format: Use the new value immediately without modifying CLI argument parsing:
kimi run --print --output-format yaml "Generate a docker-compose configuration"
Python integration example:
from kimi_cli.app import KimiCLI
cli = KimiCLI(
ui="print",
output_format="json", # or your custom format
final_message_only=False,
)
await cli.run("Explain async/await in Python")
Summary
- The
--output-formatflag is defined insrc/kimi_cli/cli/__init__.py(lines 262-267) and accepts values mapped to theOutputFormatenum. - The Print UI class in
src/kimi_cli/ui/print/__init__.pymanages the output pipeline when using--printmode. - Rendering logic branches via a
matchstatement insrc/kimi_cli/ui/print/visualize.py(lines 169-177). - Built-in formats include
text(default) andjson. - The
--quietshortcut forces text output with only the final message displayed. - Custom formats require extending the
OutputFormatenum and adding a corresponding case to the visualizer.
Frequently Asked Questions
What is the default output format in Kimi-CLI?
The default output format is text, which renders the assistant's response as plain, human-readable output directly to the terminal. This default is hardcoded in the option definition within src/kimi_cli/cli/__init__.py.
How do I get JSON output instead of plain text?
Pass --output-format json when running with the --print flag. This routes the response through the JSON renderer in src/kimi_cli/ui/print/visualize.py, outputting a structured payload containing the message content and metadata suitable for programmatic consumption.
Can I create a custom output format like Markdown or YAML?
Yes. To customize the output format, add a new member to the OutputFormat enum and implement the corresponding serialization logic in the match output_format block inside src/kimi_cli/ui/print/visualize.py (around line 169). The CLI will recognize the new string value immediately without requiring changes to the argument parser.
What does the --quiet flag actually do?
The --quiet flag is a convenience shortcut that sets --output-format text and --final-message-only, suppressing system messages, headers, and reasoning chains to display only the final assistant response.
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 →