Skip to main content

Kimi CLI with Claude Code

bex kimi runs Claude Code against Moonshot's Anthropic-compatible endpoint with a key from the Moonshot platform console. One hidden paste on first launch, live verification — and Kimi's sessions, settings and permissions never touch another provider's.

bex kimi

Quickstart

# Claude Code is the runtime — install it once
npm install -g @anthropic-ai/claude-code
# first launch opens the provider console and captures your key once
bex kimi
# everything after the provider name goes straight to claude
bex kimi --continue
# rotate or replace the stored key any time
bex code keys set kimi

How bex kimi works

Documented seams, nothing forked

bex kimi starts your installed Claude Code with ANTHROPIC_BASE_URL pointed at https://api.moonshot.ai/anthropic and your key in ANTHROPIC_AUTH_TOKEN — only Claude Code's documented environment variables, injected at exec time.

An isolated config dir

CLAUDE_CONFIG_DIR is set to ~/.bex/code/claude-kimi (base overridable with BEX_CODE_HOME): settings, history and permissions never collide with another provider, your personal ~/.claude is neither read nor modified, and inherited ANTHROPIC_* values are stripped so nothing leaks in.

One hidden paste, verified live

The first bex kimi opens the provider's API-key console, takes one hidden paste, and verifies the key live against the provider's Messages endpoint — only an explicit 401/403 fails. The key is stored owner-only in ~/.bex/code/keys.toml and injected at launch, never written into a config file.

The environment always wins

A key already set in MOONSHOT_API_KEY / KIMI_API_KEY overrides the stored one — the first set variable wins — so CI jobs and one-off shells can bring their own key without touching keys.toml.

Everything else goes to claude

Arguments after the provider name pass through to claude unchanged: bex kimi --continue resumes your last session, bex kimi -p "one prompt" runs a single prompt, and Claude Code's own --help works as-is.

Manual env vars vs bex kimi

By hand: five exports, every shell

export ANTHROPIC_BASE_URL="https://api.moonshot.ai/anthropic"
export ANTHROPIC_AUTH_TOKEN="<api-key>"
export ANTHROPIC_MODEL="kimi-k3"
export ANTHROPIC_SMALL_FAST_MODEL="kimi-k2.5"
export CLAUDE_CONFIG_DIR="$HOME/.claude-kimi"
claude

Claude Code's provider seams are environment variables, so a manual setup exports the endpoint, the key, both model slots and a config dir — in every new shell, for every provider, with nothing checking that the key actually works.

With bex: one command

bex kimi

bex kimi injects the same variables at exec time, keeps ~/.bex/code/claude-kimi isolated so histories and settings never collide, and verifies your key before Claude Code starts.

Kimi (Moonshot platform) defaults

Default modelkimi-k3
Small/fast modelkimi-k2.5
Base URLhttps://api.moonshot.ai/anthropic
API-key consolehttps://platform.moonshot.ai/console/api-keys
Key environment variablesMOONSHOT_API_KEYKIMI_API_KEY

The default model fills ANTHROPIC_MODEL and the opus/sonnet slots; the small/fast model fills ANTHROPIC_SMALL_FAST_MODEL and the haiku slot. Key environment variables are probed in order — the first set value wins, and the environment always beats the stored key.

What's specific to Kimi (Moonshot platform)

Kimi's specifics are where the key comes from and which of Moonshot's two models answers: bex kimi reads a key issued by the Moonshot platform console and puts the two Kimi ids in different Claude Code slots.

Where does the Kimi API key come from?

Moonshot's platform console. The first bex kimi opens https://platform.moonshot.ai/console/api-keys, takes one hidden paste, and verifies it against https://api.moonshot.ai/anthropic before Claude Code starts. Moonshot's Anthropic-compatible surface sits on the /anthropic path of its ordinary API host, so what you paste is a regular platform key.

What is the difference between the two Kimi models bex sets?

kimi-k3 is the default: it fills ANTHROPIC_MODEL and the opus and sonnet slots, so it does the reasoning and the edits. kimi-k2.5 fills ANTHROPIC_SMALL_FAST_MODEL and the haiku slot, keeping Claude Code's short background calls off the larger model.

Moonshot ships new models often — can I point a slot somewhere else?

Not from your shell: bex kimi strips inherited ANTHROPIC_* values and re-exports the catalog's ids, so the slots are always kimi-k3 and kimi-k2.5. If an id is retired, the provider's own error is surfaced verbatim instead of a silent swap — and the fix is a catalog update, a one-line data change.

The other launchers

All Claude Code launchers