kimi-cli-runner
Skill20 starsChanged 22 days agoMITView on GitHub
Run the local `kimi` CLI (Kimi Code) in non-interactive prompt mode for arbitrary prompts; supports file-based system/user prompt inputs, isolated default working directory, optional workspace exposure, retries, model fallback, and writing parsed assistant text to a target file.
In this repository34 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- citation-triangulationSkill
- claim-groundingSkill
- claude-cli-runnerSkill
- codex-cli-runnerSkill
- deep-literature-reviewSkill
- derivation-verifySkill
- dsh-cli-runnerSkill
- figure-hygieneSkill
- gemini-cli-runnerSkill
- hep-calcSkill
- hep-mcp-usageSkill
- idea-allocationSkill
- idea-generationSkill
- idea-pairwise-matchSkill
- idea-posteriorSkill
- julia-packageSkill
- julia-perfSkill
- literature-graph-builderSkill
- literature-to-packageSkill
- markdown-hygieneSkill
- numerical-reliability-gateSkill
- opencode-cli-runnerSkill
- paper-reviserSkill
- pdg-lookupSkill
- physics-diagramsSkill
- referee-reviewSkill
- research-harnessSkill
- research-integritySkill
- research-teamSkill
- research-writerSkill
- review-swarmSkill
- zotero-importSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 1 is distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 8
Use this skill when you need to call Kimi Code CLI from the command line without entering the TUI.
- Very specific: line 65
Do not add -y to prompt mode.
- Very specific: line 69
Use --tool-mode workspace only when Kimi should see a real project.
- Very specific: line 78
If a specific --model fails with a model-not-found style error, the runner retries with Kimi's configured default model unless …
- Very specific: line 87
Use kimi provider list --json to inspect the model aliases configured on the current machine before setting --model.
- Very specific: line 88
Use --dry-run for offline validation.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Kimi CLI Runner
Use this skill when you need to call Kimi Code CLI from the command line without entering the TUI.
If you are already running as Kimi, don't use this runner to re-invoke yourself. Keep the call in-host when available. This runner is for reaching Kimi from a different host (Codex / Claude / OpenCode / etc.) for cross-model review, drafting, or synthesis.
Preconditions
kimiis installed:command -v kimipython3is version 3.10 or newer. Older runtimes are rejected before model invocation because the shared monotonic deadline must use the same clock reference across processes.- You are authenticated/configured for Kimi Code CLI. First-time setup is usually
kimi loginor/logininside the TUI. - The official package is
@moonshot-ai/kimi-codeand the executable iskimi.
The exposed command interface was checked against local Kimi Code 2.0.2 and the official CLI reference on 2026-10-01. This metadata check does not establish account readiness or successful inference. Prompt mode uses:
kimi -p "prompt text" --output-format stream-jsonKimi Code currently exposes -p, --prompt <prompt> for headless prompt mode. It does not expose a --prompt-file or stdin prompt flag, so the runner keeps a file-based interface but must pass the merged prompt as one CLI argument internally. Very large prompt packets can exceed OS argument limits; the script fails early with a clear message when the merged prompt is over the configured limit.
Recommended: runner script
SKILL_DIR="${SKILL_DIR:-$(for r in "${CLAUDE_CONFIG_DIR:-$HOME/.claude}" "${CODEX_HOME:-$HOME/.codex}" "$HOME/.config/opencode" "$HOME/.kimi-code"; do [ -d "$r/skills/kimi-cli-runner" ] && echo "$r/skills/kimi-cli-runner" && break; done || true)}"
bash "${SKILL_DIR}/scripts/run_kimi.sh" \
--system-prompt-file /path/to/system.txt \
--prompt-file /path/to/prompt.txt \
--out /path/to/output.txtWith an explicit model and read/write workspace exposure:
SKILL_DIR="${SKILL_DIR:-$(for r in "${CLAUDE_CONFIG_DIR:-$HOME/.claude}" "${CODEX_HOME:-$HOME/.codex}" "$HOME/.config/opencode" "$HOME/.kimi-code"; do [ -d "$r/skills/kimi-cli-runner" ] && echo "$r/skills/kimi-cli-runner" && break; done || true)}"
bash "${SKILL_DIR}/scripts/run_kimi.sh" \
--model kimi-code/kimi-for-coding \
--tool-mode workspace \
--workspace-dir /path/to/project \
--prompt-file /path/to/prompt.txt \
--out /path/to/output.txtDry-run:
SKILL_DIR="${SKILL_DIR:-$(for r in "${CLAUDE_CONFIG_DIR:-$HOME/.claude}" "${CODEX_HOME:-$HOME/.codex}" "$HOME/.config/opencode" "$HOME/.kimi-code"; do [ -d "$r/skills/kimi-cli-runner" ] && echo "$r/skills/kimi-cli-runner" && break; done || true)}"
bash "${SKILL_DIR}/scripts/run_kimi.sh" \
--model kimi-code/kimi-for-coding \
--prompt-file /path/to/prompt.txt \
--out /path/to/output.txt \
--dry-runSafety notes
- Kimi Code prompt mode rejects
--plan,--auto, and--yolocombined with--prompt. - Do not add
-yto prompt mode. The runner rejects the conflicting--yolooption before invocation. - Kimi prompt mode is not a sandbox: it can run tools with automatic approval. Use this runner only with trusted prompts or in an external disposable environment.
- To reduce accidental repo exposure, this runner defaults to
--tool-mode isolated, which runskimi -pfrom a temporary isolated working directory and passes no--add-dir. - By default, the runner also passes an empty temporary
--skills-dir, which prevents Kimi from auto-discovering user/project skills during isolated runs. - Use
--tool-mode workspaceonly when Kimi should see a real project. That mode still runs from a temporary working directory but passes each workspace with Kimi's official--add-dir DIR. --tool-mode isolatedreduces accidental exposure; it is not an OS sandbox and does not prove Kimi cannot access absolute paths or run shell commands.--tool-mode workspaceis explicit workspace access, not a read-only guarantee. Use it only with prompts that are allowed to read or modify that workspace.
Notes
- The runner defaults to
--output-format stream-jsonand writes only assistant text content to--out; tool calls, tool results, metadata, and non-text assistant blocks are not represented in that output file. - Tool result and metadata events are ignored in parsed output.
- Kimi Code may spend a long time in thinking or tool-use before emitting final assistant text.
--timeout-secsbounds the entire invocation, including retries, fallback and backoff (no hard deadline by default; an explicit positive value is a hard cap). Expiry and cancellation terminate locally created CLI process groups and their descendants. This does not attest cancellation of a remote provider job. - If a specific
--modelfails with a model-not-found style error, the runner retries with Kimi's configured default model unless--no-fallbackis set. --max-attemptscaps all CLI calls in this invocation; fallback consumes the same remaining budget.--sleep-secsbackoff consumes the same deadline. Quota exhaustion, the reported billing-cycle usage-limit wording and deterministic permission refusals stop instead of repeating the blocked call. These phrases in successful assistant prose do not turn a completed body into an error; classification runs on failed calls/error diagnostics.- Exit 0 requires nonblank assistant text and successful execution without an error event. Interrupted text is retained as
OUT.partial, without a completedOUT. Every call's raw events, diagnostics and budget receipt remain underOUT.attempts/run.*(or--trace-dir DIR). Requested model aliases are recorded; actual provider model identity remains unknown unless separately attested. A completed invocation is not scientific acceptance. - Deterministic failures (usage/auth/region-ineligibility errors, exit codes 2/126/127, and similar, detected from the exit code and diagnostics) fail immediately with the diagnostic instead of burning the retry backoff; model-not-found keeps its default-model fallback.
- The merged prompt limit defaults to a conservative OS-argument-safe value. Override with
KIMI_MAX_PROMPT_BYTESwhen you know your platform can accept larger prompt arguments. - Repeat
--skills-dir DIRto pass Kimi Code skill directories through to the run. Per official Kimi docs, specifying this flag replaces auto-discovered user and project skill directories. - Pass
--auto-skillsonly when you intentionally want Kimi to auto-discover user/project skills; it is mutually exclusive with explicit--skills-dir. - Use
kimi provider list --jsonto inspect the model aliases configured on the current machine before setting--model. - Use
--dry-runfor offline validation. It prints paths, sizes, hashes, and planned flags, but never prints the full prompt.
Session continuation
--resume-session ID— resume a specific recorded Kimi session (kimi -S ID); the prompt becomes that session's next turn. Treat IDs as opaque and pass the exact ID reported by the installed CLI; do not add or strip a historical prefix.--continue-work-dir— continue the previous session OF THE WORKING DIRECTORY (kimi -c). Kimi scopes-cper working directory — confirmed both by the CLI help and by the on-disksessions/wd_<dir-hash>/layout — so this is non-racy across parallel runs in different directories. Requires--work-dir DIRpointing at the prior run's directory (the runner's default isolated fresh temp dir has no previous session): run 1 with--work-dir D, run 2 with--work-dir D --continue-work-dir.
Continuation requires the original working directory and recorded session identity. It continues the same execution and does not count as independent review. Current metadata-only checks do not establish live session recovery for a configured provider.
Options
| Flag | Default | Description |
--model MODEL | Kimi config default | Configured model alias for this invocation |
--system-prompt-file FILE | none | Optional system instructions, prepended to the user prompt |
--prompt-file FILE | required | User prompt file |
--out PATH | required | Parsed assistant text output file |
--tool-mode MODE | isolated | isolated or workspace; none is accepted as a legacy alias for isolated |
--workspace-dir DIR, --add-dir DIR | current cwd in workspace mode | Repeatable directory exposed via Kimi --add-dir; requires --tool-mode workspace |
--work-dir DIR | temp dir | Session working directory for kimi -p; advanced |
--skills-dir DIR | empty temp dir | Repeatable Kimi Code skills directory |
--auto-skills | off | Do not pass --skills-dir; allow Kimi auto-discovery; mutually exclusive with --skills-dir |
--kimi-bin PATH | kimi | Kimi executable path |
--max-attempts N | 3 | Total CLI calls, including fallback |
--max-retries N | 3 | Deprecated alias for --max-attempts |
--sleep-secs S | 5 | Base exponential backoff |
--timeout-secs S | 0 (no hard budget) | Explicit hard total deadline, including backoff/fallback |
--raw-out FILE | none | Copy raw Kimi stdout from the last attempt to this file for audit/debugging |
--stderr-out FILE | none | Copy raw Kimi stderr from the last attempt to this file for audit/debugging |
--trace-dir DIR | OUT.attempts | Retain every attempt's events, diagnostics and budget receipt in a unique run directory |
--no-fallback | off | Do not retry without --model after model-not-found errors |
--resume-session ID | (none) | Resume a specific recorded Kimi session (kimi -S ID) |
--continue-work-dir | off | Continue the working directory's previous session (kimi -c; requires --work-dir) |
--dry-run | off | Print planned invocation without calling Kimi |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

