kimi-code/docs/en/configuration/env-vars.md
qer 5ef66ddfed
feat(tui): redesign /plugins as a tabbed panel (#1025)
* feat(tui): redesign /plugins as a tabbed panel

Split the /plugins manager into Installed / Official / Third-party /
Custom tabs. The Official and Third-party marketplace catalogs load
lazily, so /plugins opens instantly and keeps working offline, with
fetch failures shown inline instead of closing the panel. The tab strip
is shared with the /model provider tabs via the new renderTabStrip
helper.

* fix(tui): show untiered marketplace entries and update badges

Address Codex review feedback on the /plugins tab redesign:

- Untiered marketplace entries (no `tier` field) now appear on the
  Third-party tab instead of being invisible in both marketplace tabs.
- Installed plugins whose marketplace version is newer than the local
  version render an `update <local> → <latest>` badge again, and
  up-to-date plugins show `installed · v<version>` — restoring the
  update visibility the pre-redesign marketplace UI had.

* fix(tui): decode Space for installed-plugin toggle

In terminals that send printable keys via Kitty/CSI-u sequences (e.g. VS
Code's integrated terminal), the Space key arrives as a printable char
rather than a Key.space match, so the Installed-tab Space toggle silently
stopped working. Check both matchesKey(Key.space) and the decoded
printable char to match the MCP selector and other dialogs.

* fix(tui): open custom marketplaces on the Third-party tab

When `/plugins marketplace <source>` points at a custom catalog whose
entries omit `tier`, those entries are classified into the Third-party
tab. Opening on Official left the visible tab empty and Enter could not
install anything, unlike the old marketplace picker which showed all
entries from the supplied source. Open on Third-party when a custom
source is supplied; the default catalog still lands on Official.

* docs(plugins): drop open-url wording and hyphenate Shift-Tab

Address Codex review feedback:

- The marketplace Enter action is install/update only (open-url rows were
  removed), so say "install or update" instead of "open or install" and
  drop the leftover changeset sentence about setup URLs.
- Use `Shift-Tab` (hyphen) instead of `Shift+Tab` to match the docs
  typography convention.

* fix(tui): keep marketplace selection valid while loading

When the Official/Third-party catalog is still loading, `entries` is empty
and pressing ↓ computed `Math.min(-1, selectedIndex + 1)` = -1. The later
Enter then read `entries[-1]` and the first install silently did nothing.
Clamp the index to 0 while there are no entries.

* fix(tui): count tab separators in tab-strip fit check

renderTabStrip declared a strip to fit whenever the sum of tab cell widths
fit, but the returned string also inserts single spaces between tabs via
`segments.join(' ')`. At widths around 43-45 columns for a four-tab strip
this declared a fit while the joined line was wider, so the trailing tab
got truncated instead of showing the `<`/`>` scroll markers. Count the
inter-tab separators in both the full-fit check and the scrolling window
fit check.

* docs(plugins): fix Kimi Datasource redirect anchor

The datasource.md redirect pointed at ./plugins.html#kimi-datasource, but
plugins.md no longer has a `## Kimi Datasource` heading — it is now
`## Official Plugins`. Update the en/zh redirect targets and fallback
links to #official-plugins / #官方插件 so the link lands on an existing
anchor.

* docs(plugins): restore concise Kimi Datasource section

The `## Official Plugins` section had replaced the original
`## Kimi Datasource` section, leaving the datasource.md redirect pointing
at a missing anchor and the Datasource capabilities/usage unreachable.
Restore a concise `## Kimi Datasource` section (intro + OAuth login +
install steps + usage) in both en and zh so the #kimi-datasource anchor
is valid again and the content is reachable.

* docs(plugins): restore Installing-from-GitHub subheading

The tab-redesign rewrite had dropped the `### Installing from GitHub` /
`### 从 GitHub 安装` subheading and its lead sentence, leaving only the
four URL forms. Restore the heading and lead sentence in both en and zh.

* docs(plugins): expand Kimi Datasource and tidy marketplace docs

- Condense the Official / Third-party / Custom tab overview and trust-badge note

- Trim the custom marketplace JSON section to the minimal id + source shape

- Move and expand the Kimi Datasource section with install, usage, and coverage

* docs(plugins): fix heading style and drop Next steps section

- Use sentence case for the Datasource headings (How to use, What you can do)

- Rename the Datasource caveat heading to Billing and limitations / 计费与限制 to avoid a duplicate Notes / 注意事项 anchor

- Remove the Next steps section, which linked back to the on-page Datasource anchor

* fix(tui): repaint plugins panel from current theme palette

The /plugins panel and MCP selector captured a palette snapshot at construction. In auto theme mode, applyResolvedAutoTheme swaps currentTheme.palette and re-renders without remounting the open panel, so it kept stale colors until closed.

Read currentTheme.palette during render instead, drop the colors opt from both components and their call sites, and add a regression test that switches palettes on a mounted panel.

* fix(tui): repaint model tab strip from current theme palette

TabbedModelSelectorComponent cached a palette snapshot in opts and used it only for the tab strip. In auto theme mode the inner model list repaints from currentTheme but the strip kept the old colors until the dialog was closed.

Read currentTheme.palette on the render path instead, drop the colors opt and its three call sites, and add a regression test that switches palettes on a mounted selector and asserts the strip repaints. This removes the last palette snapshot among editor-replacement dialogs.
2026-06-24 13:12:28 +08:00

12 KiB

Environment variables

Kimi Code CLI uses environment variables to control a small number of runtime behaviors — relocating the data directory, turning off telemetry, and temporarily switching models without touching the config file.

::: warning Important: API keys are not configured here Credential variables such as KIMI_API_KEY, ANTHROPIC_API_KEY, and OPENAI_API_KEY are not read automatically from shell environment variables. Running export KIMI_API_KEY=xxx in the terminal does not give any provider its key — they must be written in config.toml under [providers.<name>] or the [providers.<name>.env] sub-table.

The only exception is the KIMI_MODEL_* family, which is an explicit channel that does read credentials from the shell — see Define a model from environment variables.

For background, see Config overrides: provider credentials. :::

Core paths

KIMI_CODE_HOME

Overrides the data root directory; the default is ~/.kimi-code. Once set, the config file, sessions, logs, OAuth credentials, and all other data land under the new path:

export KIMI_CODE_HOME="/path/to/custom/kimi-code"

Make sure the directory is writable. Multiple kimi instances sharing the same KIMI_CODE_HOME will share config and credential files.

For the complete data directory structure, see Data locations.

KIMI_DISABLE_TELEMETRY

Set to 1 to turn off anonymous telemetry reporting (also accepts true, yes, y, case-insensitive):

export KIMI_DISABLE_TELEMETRY=1

KIMI_MODEL_* family

Switch models temporarily without modifying config.toml — when KIMI_MODEL_NAME is set, the CLI synthesizes a temporary provider in memory; the change does not persist after restart. See Define a model from environment variables.

Provider credential key names (written in config.toml)

The key names below are not read directly from the shell — they are key names written inside the [providers.<name>.env] sub-table of config.toml, serving as fallback values for api_key / base_url. The CLI reads only from the config file, not from process.env.

This design lets you keep familiar key name conventions while centralizing secret management in the config file:

[providers.kimi.env]
KIMI_API_KEY = "sk-xxx"
KIMI_BASE_URL = "https://api.moonshot.ai/v1"

Key names per provider:

Key Applicable provider Default
KIMI_API_KEY Kimi / Moonshot None
KIMI_BASE_URL Kimi / Moonshot https://api.moonshot.ai/v1
ANTHROPIC_API_KEY Anthropic None
ANTHROPIC_BASE_URL Anthropic Follows Anthropic SDK default
OPENAI_API_KEY OpenAI (openai and openai_responses) None
OPENAI_BASE_URL OpenAI (openai and openai_responses) https://api.openai.com/v1
GOOGLE_API_KEY Google GenAI, Vertex AI None
VERTEXAI_API_KEY Vertex AI None
GOOGLE_CLOUD_PROJECT Vertex AI None
GOOGLE_CLOUD_LOCATION Vertex AI None

::: warning GOOGLE_APPLICATION_CREDENTIALS (path to a service account JSON file) is the only exception that goes through the system environment variable mechanism — it is read by the Google SDK directly via the standard ADC flow, and the CLI does not participate. All other key names must be placed in the [providers.<name>.env] sub-table to take effect. :::

For the full provider type and field reference, see Providers and models.

OAuth and managed services

This group of variables redirects OAuth authentication and managed service endpoints to a self-hosted or test environment. They are not needed for everyday use.

Variable Purpose Default
KIMI_CODE_OAUTH_HOST OAuth auth host; highest priority Falls back to KIMI_OAUTH_HOST when unset
KIMI_OAUTH_HOST OAuth auth host; fallback for KIMI_CODE_OAUTH_HOST Falls back to https://auth.kimi.com when unset
KIMI_CODE_BASE_URL Managed API base URL used after OAuth login https://api.kimi.com/coding/v1

::: warning KIMI_CODE_BASE_URL (OAuth-managed service, targeting kimi.com) and KIMI_BASE_URL (direct API key connection, targeting moonshot.ai) are two distinct variables. Use each one in its appropriate context. :::

Define a model from environment variables (KIMI_MODEL_*)

Want to switch models for testing without touching config.toml? When KIMI_MODEL_NAME is set, the CLI synthesizes a temporary provider and model alias from the KIMI_MODEL_* variables in memory — nothing is written back to the config file. These variables take priority over default_model in config.toml, but the -m <alias> option at startup still has the highest priority.

export KIMI_MODEL_NAME="kimi-for-coding"
export KIMI_MODEL_API_KEY="YOUR_API_KEY"
export KIMI_MODEL_BASE_URL="https://api.example.com/v1"
export KIMI_MODEL_MAX_CONTEXT_SIZE="262144"
export KIMI_MODEL_CAPABILITIES="image_in,thinking"
kimi

Complete variable list:

Variable Required Purpose Default
KIMI_MODEL_NAME Yes (also the enable switch) Model id sent to the API
KIMI_MODEL_API_KEY Yes API key
KIMI_MODEL_PROVIDER_TYPE No Provider type: kimi, anthropic, openai kimi
KIMI_MODEL_BASE_URL No API base URL Each type has its own default
KIMI_MODEL_MAX_CONTEXT_SIZE No Maximum context length (tokens) 262144 (256 K)
KIMI_MODEL_CAPABILITIES No Comma-separated capability tags, unioned with auto-detected capabilities image_in,thinking
KIMI_MODEL_DISPLAY_NAME No Name shown in /model Falls back to KIMI_MODEL_NAME
KIMI_MODEL_MAX_OUTPUT_SIZE No Per-request output cap (anthropic only) Model default
KIMI_MODEL_REASONING_KEY No Reasoning field name override (openai only) Auto-detected
KIMI_MODEL_DEFAULT_THINKING No Default Thinking toggle for new sessions Follows global default
KIMI_MODEL_THINKING_MODE No Thinking trigger policy: auto/on/off
KIMI_MODEL_THINKING_EFFORT No Thinking effort level: low/medium/high/xhigh/max
KIMI_MODEL_ADAPTIVE_THINKING No Force adaptive thinking on or off (anthropic only) Inferred from model name

If KIMI_MODEL_NAME is set but a required variable is missing, startup fails immediately with a clear error message.

Runtime switches

Switches that control the behavior of subsystems such as telemetry, background tasks, and the plugin marketplace:

Variable Purpose Valid values
KIMI_DISABLE_TELEMETRY Disable anonymous telemetry reporting 1, true, yes, y (case-insensitive)
KIMI_CODE_BACKGROUND_KEEP_ALIVE_ON_EXIT Whether to keep background tasks when the session closes; takes higher priority than config.toml. The default is to stop them on exit Truthy: 1/true/yes/on; falsy: 0/false/no/off
KIMI_CODE_PLUGIN_MARKETPLACE_URL Override the plugin marketplace JSON loaded by /plugins; useful for dev loopback servers, staging CDN files, or alternate marketplace directories https://code.kimi.com/kimi-code/plugins/marketplace.json; also accepts http://, file:// URLs, and local paths
KIMI_CODE_AGENT_SWARM_MAX_CONCURRENCY Cap how many AgentSwarm subagents run concurrently during the initial ramp; leave unset for no cap Positive integer; invalid values fail fast
KIMI_CODE_EXPERIMENTAL_FLAG Enable all registered experimental features for this process; micro_compaction is already enabled by default 1, true, yes, on
KIMI_CODE_EXPERIMENTAL_MICRO_COMPACTION Override [experimental].micro_compaction for this process Truthy or falsy
KIMI_SHELL_PATH Override the Git Bash path on Windows (used when auto-detection fails) Absolute path
KIMI_MODEL_MAX_COMPLETION_TOKENS Hard cap on max_completion_tokens per LLM step; applies to the kimi provider only Positive integer; 0 or negative disables clamping
KIMI_MODEL_TEMPERATURE Sampling temperature for every request; applies to the kimi provider only (global — independent of KIMI_MODEL_NAME) Number, e.g. 0.3
KIMI_MODEL_TOP_P Nucleus-sampling top_p for every request; applies to the kimi provider only (global) Number, e.g. 0.95
KIMI_MODEL_THINKING_KEEP Moonshot preserved-thinking passthrough (thinking.keep); applies to the kimi provider only, and only while Thinking is on A value the API accepts, e.g. all
KIMI_CODE_NO_AUTO_UPDATE Fully disable the update preflight — no check, background install, or prompt. Legacy alias KIMI_CLI_NO_AUTO_UPDATE is also honored Truthy: 1/true/yes/on
KIMI_DISABLE_CRON Disable the scheduled-task tool (CronCreate rejects new schedules; existing tasks do not fire) 1 to disable

Diagnostic logs

These variables control log level and file rotation, read once at process startup:

Variable Purpose Default
KIMI_LOG_LEVEL Log level: off, error, warn, info, debug info
KIMI_LOG_GLOBAL_MAX_BYTES Maximum bytes per global log file 6291456 (6 MB)
KIMI_LOG_GLOBAL_FILES Number of global log files to retain 5
KIMI_LOG_SESSION_MAX_BYTES Maximum bytes per session log file 5242880 (5 MB)
KIMI_LOG_SESSION_FILES Number of session log files to retain 3

System environment variables

The CLI also reads several standard system variables to detect the runtime environment; it does not modify them:

  • HOME: used to resolve the default data path
  • VISUAL, EDITOR: external editor command (VISUAL takes precedence)
  • PATH: used to locate dependencies such as rg, fd, fdfind, and git; on Windows, Git Bash detection checks each git.exe found on PATH, including package-manager shims such as Scoop
  • NO_COLOR, FORCE_COLOR: control color output (following the no-color.org convention)
  • CI: when non-empty and not "0", disables theme detection and falls back to the dark theme
  • TERM_PROGRAM, TERM, TMUX: detect terminal features and notification support
  • DISPLAY, WAYLAND_DISPLAY, XDG_SESSION_TYPE: detect Linux graphical sessions (for clipboard and image features)
  • WSL_DISTRO_NAME, WSLENV: detect WSL for the clipboard PowerShell bridge
  • LOCALAPPDATA: used on Windows as a fallback when probing for the Git Bash installation path

HTTP proxy

Kimi Code honors the standard proxy environment variables for all outbound traffic — model API calls, MCP servers, web tools, telemetry, sign-in, and update checks:

  • HTTP_PROXY / http_proxy: proxy for http:// requests
  • HTTPS_PROXY / https_proxy: proxy for https:// requests
  • ALL_PROXY / all_proxy: fallback proxy used when the scheme-specific variable is unset; this is where a SOCKS proxy is usually set
  • NO_PROXY / no_proxy: comma-separated hosts that bypass the proxy

Both HTTP(S) and SOCKS proxies are supported. A SOCKS proxy is recognized by its scheme — socks5://, socks5h://, socks4://, or socks:// (an alias for socks5://) — and is typically set via ALL_PROXY (the form used by tools like Clash and V2RayN). An HTTP(S) proxy takes precedence over ALL_PROXY for HTTP/HTTPS traffic.

The proxy is applied only when one of these variables is set; otherwise connections are made directly. Loopback hosts (localhost, 127.0.0.1, ::1) always bypass the proxy, so a local server such as a localhost MCP server keeps working when a proxy is configured — add your own internal hosts to NO_PROXY to exempt them too.

Stdio MCP servers that run as Node child processes honor HTTP_PROXY / HTTPS_PROXY / NO_PROXY automatically when the child's Node version supports NODE_USE_ENV_PROXY (Node ≥ 22.21 or ≥ 24.5); SOCKS proxying applies to Kimi Code's own traffic only.

Next steps