| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
An opencode plugin that makes the Kimi Code path in opencode work like the official kimi-cli, using Kimi-specific extensions instead of just a generic OpenAI-compatible provider.
Compared with stock opencode Kimi setups, this plugin:
Contributor and agent documentation lives in AGENTS.md.
Recommended:
opencode plugin opencode-kimi-full --globalThat installs the published package and adds the plugin to your global opencode config, so opencode auth login -p kimi-for-coding-oauth works from any directory.
From a local checkout:
opencode plugin /absolute/path/to/opencode-kimi-full --globalThat is the command you want when you are editing this repo and want opencode to load your working tree. Changing files in a checkout does nothing unless opencode is pointed at that checkout path.
If you prefer managing plugin registration manually, add the plugin to the plugin list in ~/.config/opencode/opencode.json or a project-local .opencode/opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-kimi-full"]
}For a local checkout, point the plugin entry at the repo root instead of the npm package name:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["/absolute/path/to/opencode-kimi-full"]
}If you use a project-local .opencode/opencode.json, the plugin only exists when you run opencode inside that project tree. If you want opencode auth login to work from anywhere, use the --global install above.
After the plugin is installed and login works, paste this provider entry into ~/.config/opencode/opencode.json or .opencode/opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"kimi-for-coding-oauth": {
"name": "Kimi For Coding (OAuth)",
"npm": "@ai-sdk/openai-compatible",
"options": {
"baseURL": "https://api.kimi.com/coding/v1"
},
"models": {
"kimi-for-coding": {
"name": "Kimi For Coding",
"attachment": true,
"reasoning": true,
"modalities": {
"input": ["text", "image"],
"output": ["text"]
},
"options": {},
"variants": {
"off": { "reasoning_effort": "off" },
"auto": { "reasoning_effort": "auto" },
"low": { "reasoning_effort": "low" },
"medium": { "reasoning_effort": "medium" },
"high": { "reasoning_effort": "high" }
}
}
}
}
}
}Important: The attachment and modalities fields are required for image input to work. Without them, opencode strips image parts before they reach Kimi. If you previously pasted an older config block without these fields, update it.
This block is for using the model after login. It does not register the auth provider by itself. What makes opencode auth login -p kimi-for-coding-oauth work is the plugin being loaded via opencode plugin ... or the plugin array above.
Use these two ids exactly as written:
Note. The provider id is intentionally not kimi-for-coding. That id is already published by models.dev and points at a static-API-key flow using a different SDK and auth shape. Using a distinct id keeps the two paths from colliding under a single opencode auth login entry.
opencode auth login -p kimi-for-coding-oauthThen complete the device-flow approval in your browser.
During login the plugin:
Access tokens refresh automatically while you use the model.
Troubleshooting: Unknown provider "kimi-for-coding-oauth"That error means opencode did not load this plugin at all. The Kimi OAuth flow has not started yet.
The usual causes are:
Fastest fix:
opencode gates image input on model metadata. If your config block is missing attachment: true and modalities, opencode strips image parts before they reach Kimi.
Fix: update your config block to match the one in Configure above -- specifically add "attachment": true and "modalities": { "input": ["text", "image"], "output": ["text"] } to the model entry.
The plugin also backfills these capabilities at runtime from /coding/v1/models discovery, but the static config must be correct for the initial request.
Login and refresh detailsSelect kimi-for-coding-oauth/kimi-for-coding in opencode.
The default variant-cycle keybind is Ctrl+T. The variants map as follows:
These variants only affect Kimi's reasoning request fields. They do not switch models or auth paths. In practice:
Effort levels xhigh and max are clamped to high, matching kimi-cli's behavior (Kimi's backend does not support higher tiers).
Every kimi-for-coding request also gets prompt_cache_key set to opencode's session id. That mirrors kimi-cli's cache hint so follow-up turns in the same session can reuse Kimi's prompt cache.
The plugin registers a /kimi:usage TUI slash command that shows your Kimi Code subscription usage (weekly and rolling-window limits) in a compact dialog. Run it from the opencode command palette.
Stock opencode can already talk to generic Moonshot and OpenAI-compatible endpoints. This plugin exists for the Kimi Code path specifically: it brings the official Kimi OAuth flow and Kimi-specific request behavior into opencode without sharing kimi-cli's credential files.
What it adds over the generic route.
| Field | Wire shape | Purpose |
|---|---|---|
| prompt_cache_key | top-level body, snake_case, set to opencode's sessionID | Opt-in, session-scoped cache key, mirroring kimi-cli. |
| thinking + reasoning_effort | thinking: { type: "enabled" | "disabled" } with sibling reasoning_effort: "low" | "medium" | "high" | Sent together, matching kimi-cli. xhigh/max clamped to high. |
| Seven X-Msh-* headers + UA | User-Agent, X-Msh-Platform, X-Msh-Version, X-Msh-Device-Name, X-Msh-Device-Model, X-Msh-Device-Id, X-Msh-Os-Version | Matches kimi-cli's _common_headers() at the pinned KIMI_CLI_VERSION. |
| /coding/v1/models discovery | id, display_name, context_length, supports_image_in, supports_video_in | Supplies the authoritative wire model slug plus runtime model metadata. |
| ~/.kimi/device_id | UUID persisted on disk, embedded in X-Msh-Device-Id | Sends the same X-Msh-Device-Id as a locally-installed kimi-cli. |
Effort-to-field mapping used by the plugin:
| user effort | reasoning_effort | thinking |
|---|---|---|
| auto | (omitted) | (omitted) -- server picks dynamically |
| off | (omitted) | { type: "disabled" } |
| low / medium / high | same string | { type: "enabled" } |
| xhigh / max | "high" (clamped) | { type: "enabled" } |
| Path | Purpose |
|---|---|
| ~/.kimi/device_id | Stable UUID used in X-Msh-Device-Id. Shared with kimi-cli. |
| opencode auth store (auth.json in opencode's XDG data dir; on Linux typically ~/.local/share/opencode/auth.json) | Token storage, managed by opencode through client.auth.*; the plugin also live-reads this entry to avoid stale workspace auth snapshots during refresh. |
No other state is persisted. Credentials are never written to ~/.kimi/credentials/; that path belongs to kimi-cli, and sharing it would cause refresh-token races between the two clients.
Architecture at a glance opencode core
──────────────────────────────────────────────────
auth.login ──> plugin.auth.authorize() device-code flow, poll
└──> oauth.ts
chat ────────> plugin.loader() custom fetch that:
├──> ensureFresh() proactive refresh
└──> kimiHeaders() 7 X-Msh-* headers
/models slug discovery
401 -> force-refresh + retry
chat.params ─> plugin "chat.params" thinking / reasoning_effort /
prompt_cache_key
/kimi:usage ─> tui.tsx subscription usage dialog
└──> usage.ts
A full description of the invariants that keep this working is in AGENTS.md, under "Architecture" and "Contracts to keep intact".
MIT.
| Back | FazBrowse Home | New Git URL |