Print Mode
Print mode lets Kimi CLI run non-interactively, suitable for scripting and automation scenarios.
Basic usage
Use the --print flag to enable print mode:
# Pass instructions via -c
kimi --print -c "List all Python files in the current directory"
# Pass instructions via stdin
echo "Explain what this code does" | kimi --printPrint mode characteristics:
- Non-interactive: Exits automatically after executing instructions
- Auto-approval: Implicitly enables
--yolomode, all operations are auto-approved - Text output: AI responses are output to stdout
Final message only
Use the --final-message-only option to only output the final assistant message, skipping intermediate tool call processes:
kimi --print -c "Give me a Git commit message based on the current changes" --final-message-only--quiet is a shortcut for --print --output-format text --final-message-only, suitable for scenarios where only the final result is needed:
kimi --quiet -c "Give me a Git commit message based on the current changes"JSON format
Print mode supports JSON format for input and output, convenient for programmatic processing. Both input and output use the Message format.
JSON output
Use --output-format=stream-json to output in JSONL (one JSON per line) format:
kimi --print -c "Hello" --output-format=stream-jsonExample output:
{"role":"assistant","content":"Hello! How can I help you?"}If the AI called tools, assistant messages and tool messages are output sequentially:
{"role":"assistant","content":"Let me check the current directory.","tool_calls":[{"type":"function","id":"tc_1","function":{"name":"Shell","arguments":"{\"command\":\"ls\"}"}}]}
{"role":"tool","tool_call_id":"tc_1","content":"file1.py\nfile2.py"}
{"role":"assistant","content":"There are two Python files in the current directory."}JSON input
Use --input-format=stream-json to receive JSONL format input:
echo '{"role":"user","content":"Hello"}' | kimi --print --input-format=stream-json --output-format=stream-jsonIn this mode, Kimi CLI continuously reads from stdin, processing and outputting responses for each user message received until stdin is closed.
Message format
Both input and output use a unified message format.
User message
{"role": "user", "content": "Your question or instruction"}Array-form content is also supported:
{"role": "user", "content": [{"type": "text", "text": "Your question"}]}Assistant message
{"role": "assistant", "content": "Response content"}Assistant message with tool calls:
{
"role": "assistant",
"content": "Let me execute this command.",
"tool_calls": [
{
"type": "function",
"id": "tc_1",
"function": {
"name": "Shell",
"arguments": "{\"command\":\"ls\"}"
}
}
]
}Tool message
{"role": "tool", "tool_call_id": "tc_1", "content": "Tool execution result"}Use cases
CI/CD integration
Auto-generate code or perform checks in CI workflows:
kimi --print -c "Check if there are any obvious security issues in the src/ directory, output a JSON format report"Batch processing
Combine with shell loops for batch file processing:
for file in src/*.py; do
kimi --print -c "Add type annotations to $file"
doneIntegration with other tools
Use as a backend for other tools, communicating via JSON format:
my-tool | kimi --print --input-format=stream-json --output-format=stream-json | process-output