Skip to content

Environment variables

Kimi Code CLI uses environment variables to override default paths, switch OAuth endpoints, and adjust runtime behavior. Most variables are read when the kimi process starts up; a few (such as the telemetry switch, the OAuth lock, and diagnostic logging) are read when the relevant subsystem initializes. Kimi's own variables use the KIMI_* prefix; in addition, the CLI also reads a number of standard system variables.

Note

Provider credentials are not in this list: key variables such as KIMI_API_KEY, ANTHROPIC_API_KEY, OPENAI_API_KEY, and GOOGLE_API_KEY are not read automatically from process.env. They must be written into the [providers.<name>] section of config.toml (as api_key / base_url) or into the [providers.<name>.env] subtable; merely exporting them in your shell will not give a provider credentials automatically. See Configuration overrides and Providers for details.

Core paths

KIMI_CODE_HOME overrides Kimi Code CLI's data root directory, defaulting to ~/.kimi-code. The CLI's own application data, kimi-core's config, the ripgrep cache, and OAuth credentials all land under this directory.

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

For details on the data layout, see Data locations.

Note

Make sure the directory is writable once you set it. Multiple kimi instances that share the same KIMI_CODE_HOME will share both the config and credential files.

Provider credential key names

The following key names appear in the [providers.<name>.env] subtable of config.toml, where they serve as fallback sources for the provider's api_key / base_url. The main kimi process does not read them directly from process.env; only the values keyed under a [providers.<name>.env] subtable are recognized by the provider clients. See Configuration overrides: provider credentials for the full resolution order.

Key nameApplicable providerPurposeDefault
KIMI_API_KEYKimi / MoonshotAPI keyNone
KIMI_BASE_URLKimi / MoonshotAPI base URLhttps://api.moonshot.ai/v1
ANTHROPIC_API_KEYAnthropicAPI keyNone
ANTHROPIC_BASE_URLAnthropicAPI base URLFollows the Anthropic SDK default
OPENAI_API_KEYOpenAI (used by both openai and openai_responses)API keyNone
OPENAI_BASE_URLOpenAI (used by both openai and openai_responses)API base URLhttps://api.openai.com/v1
GOOGLE_API_KEYGoogle GenAI, Vertex AI (as a fallback for VERTEXAI_API_KEY)API keyNone
VERTEXAI_API_KEYVertex AIAPI key (when not using ADC)None
GOOGLE_CLOUD_PROJECTVertex AIGCP project IDNone
GOOGLE_CLOUD_LOCATIONVertex AIGCP regionNone

For example, to pre-populate Kimi credentials in config.toml:

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

Note

GOOGLE_APPLICATION_CREDENTIALS (the path to a service-account JSON file) is read by the Google SDK itself from the shell environment, making it the only key in this group that goes through a system environment variable. It follows Google Cloud's standard ADC flow, and the CLI is not involved in resolving it. Every other key only takes effect when written into a [providers.<name>.env] subtable.

For the full description of provider types and fields, see Providers.

OAuth and the hosted service

The OAuth flow connects to Kimi's official authentication and hosted endpoints by default. The variables below can point them at a self-hosted or test environment.

Environment variablePurposeDefault
KIMI_CODE_OAUTH_HOSTOAuth authentication host; takes the highest precedence— (falls back to KIMI_OAUTH_HOST, then to the hardcoded default below)
KIMI_OAUTH_HOSTOAuth authentication host; used as a fallback for KIMI_CODE_OAUTH_HOST— (falls back to the hardcoded default below)
KIMI_CODE_BASE_URLBase URL of the hosted Kimi API, used for API calls after OAuth loginhttps://api.kimi.com/coding/v1

When neither KIMI_CODE_OAUTH_HOST nor KIMI_OAUTH_HOST is set, the OAuth authentication host uses the hardcoded constant https://auth.kimi.com.

Note

KIMI_CODE_BASE_URL and the KIMI_BASE_URL from the previous section are two different variables: the former targets the OAuth-logged-in hosted service and defaults to kimi.com; the latter targets providers that use a Kimi API key directly and defaults to moonshot.ai. Distinguish them by use case.

Runtime switches

Environment variablePurposeValid values / Default
KIMI_DISABLE_TELEMETRYDisable telemetry reporting1, true, t, yes, y (case-insensitive)
KIMI_CODE_BACKGROUND_KEEP_ALIVE_ON_EXITOverride [background].keep_alive_on_exit, controlling whether still-running background tasks are kept when the session closesTrue values: 1, true, yes, on; false values: 0, false, no, off; when unset, reads config.toml, then falls back to true
KIMI_SHELL_PATHOverride the absolute path to Git Bash (bash.exe) on Windows; only needed when auto-detection fails on WindowsNone
KIMI_MODEL_MAX_COMPLETION_TOKENSDesired budget for max_completion_tokens in a single-step LLM request (the actual value is further clamped by the context window and input size); set to 0 or a negative value to disable clamping entirely. Currently effective only for providers of type kimi; for Anthropic and other providers, use [models.<alias>].max_output_size instead (see Config files)Defaults to 32000, influenced by loop_control.reserved_context_size

For example, to disable telemetry on a shared host:

sh
export KIMI_DISABLE_TELEMETRY="1"

KIMI_CODE_BACKGROUND_KEEP_ALIVE_ON_EXIT has higher priority than config.toml. For example, running KIMI_CODE_BACKGROUND_KEEP_ALIVE_ON_EXIT=0 kimi -p "..." temporarily requests stopping background tasks before this process exits, even if the config file sets keep_alive_on_exit = true.

Diagnostic logging

The variables below control kimi's diagnostic logs. Logs are written to two locations: the global diagnostic log at $KIMI_CODE_HOME/logs/kimi-code.log, and each session's own diagnostic log at <sessionDir>/logs/kimi-code.log (see Data locations for path details). All of these variables are read only once at process startup.

Environment variablePurposeDefault
KIMI_LOG_LEVELLog level; one of off, error, warn, info, debuginfo
KIMI_LOG_GLOBAL_MAX_BYTESMaximum bytes per global log file6291456 (6 MB)
KIMI_LOG_GLOBAL_FILESNumber of global log files to retain5
KIMI_LOG_SESSION_MAX_BYTESMaximum bytes per session log file5242880 (5 MB)
KIMI_LOG_SESSION_FILESNumber of session log files to retain3

When an integer variable fails to parse (non-positive integer or non-numeric), it silently falls back to the default value.

Clipboard bridge

KIMI_WSL_CLIPBOARD_IMAGE_PATH is injected automatically by the CLI when it spawns the WSL clipboard helper subprocess, used to pass a temporary image path. The variable is written into the PowerShell subprocess's environment and read by the subprocess script internally; the main kimi process does not read this variable itself. Setting it in an external shell has no effect on the main kimi process — users do not need to manage this variable manually.

System environment variables

Kimi Code CLI also reads a handful of standard system environment variables to detect the runtime environment and pick default behavior:

  • HOME: the user's home directory, used to resolve the default data path.
  • VISUAL, EDITOR: the executable invoked as the external editor, with VISUAL taking precedence.
  • PATH: used to locate external dependencies such as rg and git.
  • NO_COLOR: when set and non-empty, forces color and theme detection off, falling back to the dark theme. Follows the no-color.org convention.
  • FORCE_COLOR: when set to "0", also disables color and theme detection, falling back to the dark theme.
  • CI: when non-empty and not "0", disables theme detection and falls back to the dark theme; the telemetry module also reads this variable to mark the CI environment.
  • LANG: used to tag the locale in the telemetry context (purely as a tag; it does not change CLI behavior).
  • TERM_PROGRAM: used to detect terminal support for OSC 9 notifications (iTerm2, WezTerm, ghostty, WarpTerminal, etc.); also written into the telemetry context.
  • TERM: used to detect terminal support for OSC 9 notifications (xterm-kitty, xterm-ghostty, etc.).
  • TMUX: detects whether the CLI is running inside tmux, used for the terminal notification path.
  • COLORFGBG: detects the terminal color scheme (dark / light).
  • DISPLAY, WAYLAND_DISPLAY, XDG_SESSION_TYPE: detect a Linux graphical session, used by clipboard and image-related features. A XDG_SESSION_TYPE value of wayland is also treated as a Wayland session.
  • WSL_DISTRO_NAME, WSLENV: detect whether the CLI is running inside WSL, used for the PowerShell-bridged clipboard fallback.
  • TERMUX_VERSION: detects whether the CLI is running inside Termux.
  • LOCALAPPDATA: used on Windows when probing for the Git Bash installation path.

These variables follow the usual conventions of each operating system; kimi only reads them and never modifies them.