Entry Points & CLI Commands
kimi-code
Entry Points & CLI Commands
CLI Entry Point
The CLI is registered in pyproject.toml:
[project.scripts]
kimi = "kimi_cli.cli:cli"
kimi-cli = "kimi_cli.cli:cli"Both kimi and kimi-cli commands invoke the same Typer application at src/kimi_cli/cli/__init__.py.
Main Commands
Interactive Session
kimi [OPTIONS] [PROMPT]Starts an interactive shell session. If PROMPT is provided, it's used as the initial input.
Key Options:
--model,-m- Override the LLM model--agent- Specify custom agent YAML file--continue,-c- Continue the most recent session--session- Resume a specific session by ID--yolo- Auto-approve all tool calls--thinking- Enable extended thinking mode--print- Non-interactive output mode
Session Management
kimi session list # List all sessions
kimi session continue # Continue most recent
kimi session archive <id> # Archive a session
kimi session delete <id> # Delete a sessionConfiguration
kimi config show # Show current configuration
kimi config edit # Open config in editor
kimi config path # Show config file pathAuthentication
kimi login # Authenticate with Kimi service
kimi logout # Clear authenticationKimiCLI Class
The main application class at src/kimi_cli/app.py:54:
class KimiCLI:
@staticmethod
async def create(
session: Session,
config: Config,
model_name: str | None = None,
thinking: bool | ThinkingEffort = False,
agent_file: Path | None = None,
mcp_configs: Sequence[MCPServerConfig] | None = None,
yolo: bool = False,
skills_roots: Sequence[Path] = (),
) -> KimiCLI:
# Factory method that initializes all componentsInitialization Sequence
KimiCLI.create()
├── load_config() → Config
├── OAuthManager(config)
├── augment_provider_with_env_vars()
├── create_llm(provider, model) → LLM
├── Runtime.create(config, oauth, llm, session, ...)
│ ├── list_directory(work_dir)
│ ├── load_agents_md(work_dir)
│ ├── Environment.detect()
│ └── discover_skills_from_roots()
├── load_agent(agent_file, runtime, mcp_configs)
│ ├── load_agent_spec(agent_file)
│ ├── _load_system_prompt() with Jinja2
│ ├── toolset.load_tools()
│ └── toolset.load_mcp_tools()
├── Context.restore()
└── KimiSoul(agent, context)
Run Modes
KimiCLI supports multiple execution modes:
Shell Mode (Interactive)
# app.py:248
async def run_shell(self):
"""Interactive terminal UI with rich rendering"""The default mode with full interactive capabilities:
- Rich text rendering
- Approval prompts
- Slash commands
- Session persistence
Print Mode (Non-interactive)
# app.py:326
async def run_print(self, format: Literal["text", "json"]):
"""Non-interactive output to stdout"""For scripting and automation:
text- Human-readable outputjson- Structured JSON output
Wire Stdio Mode
# app.py:355
async def run_wire_stdio(self):
"""Wire protocol over stdio for external UIs"""Exposes the Wire protocol for custom UI implementations.
ACP Server Mode
# app.py:347
async def run_acp(self, port: int):
"""Agent Communication Protocol server"""Runs as an ACP-compatible server for remote access.
Slash Commands
Built-in slash commands are available in interactive mode:
| Command | Description |
|---|---|
/login |
Authenticate with Kimi |
/logout |
Clear authentication |
/clear |
Clear conversation context |
/compact |
Manually trigger context compaction |
/undo |
Revert to previous checkpoint |
/help |
Show available commands |
Skills as Slash Commands
Skills discovered from .agents/ directories are exposed as slash commands:
/skill:my-skill # Invoke a skill
/flow:my-flow # Run a flow-based skillExecution Flow Diagram
┌──────────────────────────────────────────────────────────────┐
│ CLI Entry Point │
│ kimi_cli.cli:cli │
└───────────────────────────┬──────────────────────────────────┘
│
▼
┌─────────────────────────────┐
│ Parse CLI arguments │
│ (Typer + Click) │
└──────────────┬──────────────┘
│
┌──────────────────┼──────────────────┐
│ │ │
▼ ▼ ▼
┌────────────┐ ┌────────────┐ ┌────────────┐
│ Session │ │ Config │ │ Other │
│ Commands │ │ Commands │ │ Commands │
└──────┬─────┘ └──────┬─────┘ └─────┬──────┘
│ │ │
└─────────────────┼────────────────┘
│
▼
┌─────────────────────────────┐
│ KimiCLI.create() │
│ (for session commands) │
└──────────────┬──────────────┘
│
┌──────────────────┼──────────────────┐
│ │ │
▼ ▼ ▼
┌────────────┐ ┌────────────┐ ┌────────────┐
│ run_shell │ │ run_print │ │ run_wire │
│ Interactive│ │ Scripting │ │ External UI│
└────────────┘ └────────────┘ └────────────┘
Session Lifecycle
1. Session Creation/Resume
├── Generate or load session ID (UUID)
├── Create session directory: ~/.kimi/sessions/{id}/
├── Initialize context.jsonl and wire.jsonl
└── Load existing messages if resuming
2. Conversation Loop
├── User input received
├── KimiSoul.run() processes input
├── Messages appended to context
├── Wire events logged
└── Repeat until exit
3. Session End
├── Context saved to file
├── Session metadata updated
└── MCP connections cleaned up
Related Documentation
- Overview - High-level architecture
- Core Logic - Agent loop details
- Configuration - Config options