Skip to content

Claude Code

Claude Code is a programming agent product from Anthropic. Its interface, configuration options, and supported capabilities may change across versions. This guide describes a general integration approach: forwarding Claude Code model requests to the Kimi Code API through environment variables.

Before You Start

  • Make sure you have subscribed to Kimi membership and activated Kimi Code benefits.
  • Obtain an API Key:
    1. Go to the Kimi Code Console;
    2. Click "Create API Key", enter a name and confirm;
    3. Copy the generated key and keep it safe (the full key cannot be viewed again after closing the dialog).

Kimi Code Console

Configuration

Claude Code is a command-line programming assistant launched by Anthropic. By configuring environment variables to connect it to Kimi's API endpoint, you can directly call Kimi Code's AI capabilities within Claude Code and enjoy the Kimi Code programming experience in a familiar terminal interface.

Install Claude Code

For installation instructions, please refer to the Claude Code official documentation.

Run Script to Skip Login

After installation, do not start Claude directly. Execute the following script in the terminal first to skip Anthropic's default login flow:

sh
node --eval "
// enable third party model support and fast mode
const claudeJsonFilePath = path.join(os.homedir(), '.claude.json');
if (fs.existsSync(claudeJsonFilePath)) {
    const content = JSON.parse(fs.readFileSync(claudeJsonFilePath, 'utf-8'));
    fs.writeFileSync(claudeJsonFilePath, JSON.stringify({ ...content, penguinModeOrgEnabled: true, hasCompletedOnboarding: true }, null, 2), 'utf-8');
} else {
    fs.writeFileSync(claudeJsonFilePath, JSON.stringify({ penguinModeOrgEnabled: true, hasCompletedOnboarding: true }), 'utf-8');
}

// delete old model id
const claudeSettingsJsonFilePath = path.join(os.homedir(), '.claude', 'settings.json');
if (fs.existsSync(claudeSettingsJsonFilePath)) {
    const content = JSON.parse(fs.readFileSync(claudeSettingsJsonFilePath, 'utf-8'));
    if (typeof content === 'object' && typeof content.env === 'object') {
        for (const element of [
            'ANTHROPIC_MODEL',
            'ANTHROPIC_SMALL_FAST_MODEL',
            'CLAUDE_CODE_SUBAGENT_MODEL',
            'ANTHROPIC_DEFAULT_FABLE_MODEL',
            'ANTHROPIC_DEFAULT_FABLE_MODEL_NAME',
            'ANTHROPIC_DEFAULT_OPUS_MODEL',
            'ANTHROPIC_DEFAULT_OPUS_MODEL_NAME',
            'ANTHROPIC_DEFAULT_SONNET_MODEL',
            'ANTHROPIC_DEFAULT_SONNET_MODEL_NAME',
            'ANTHROPIC_DEFAULT_HAIKU_MODEL',
            'ANTHROPIC_DEFAULT_HAIKU_MODEL_NAME',
        ]) {
            delete content.env[element];
        }
        fs.writeFileSync(claudeSettingsJsonFilePath, JSON.stringify(content, null, 2), 'utf-8');
    }
}
"

Set Environment Variables and Start

First check your membership tier to confirm which models and context windows you can use, then copy the matching configuration:

PlanAvailable ModelsAvailable Context Limit
Andantekimi-for-coding262144
Moderatok3 or kimi-for-coding262144
Allegretto and abovek3, kimi-for-coding, kimi-for-coding-highspeed1048576 for K3, 262144 for the K2.7 Code series

K3 1M context configuration:

The k3[1m] form is only needed for Claude Code env vars

k3[1m] (with the surrounding quotes) explicitly tells Claude Code to use a 1M context window. In any other scenario — API requests, the Model ID field of other third-party tools — just use k3.

sh
export ANTHROPIC_BASE_URL=https://api.kimi.com/coding/
export ANTHROPIC_API_KEY=Your API Key

export ANTHROPIC_MODEL="k3[1m]"
export ANTHROPIC_DEFAULT_FABLE_MODEL=$ANTHROPIC_MODEL
export ANTHROPIC_DEFAULT_OPUS_MODEL=$ANTHROPIC_MODEL
export ANTHROPIC_DEFAULT_SONNET_MODEL=$ANTHROPIC_MODEL
export ANTHROPIC_DEFAULT_HAIKU_MODEL=$ANTHROPIC_MODEL
export CLAUDE_CODE_SUBAGENT_MODEL=$ANTHROPIC_MODEL
export CLAUDE_CODE_EFFORT_LEVEL=high
export CLAUDE_CODE_AUTO_COMPACT_WINDOW=1048576
export CLAUDE_CODE_MAX_CONTEXT_TOKENS=1048576

claude
powershell
$env:ANTHROPIC_BASE_URL="https://api.kimi.com/coding/"
$env:ANTHROPIC_API_KEY="Your API Key"

$env:ANTHROPIC_MODEL="k3[1m]"
$env:ANTHROPIC_DEFAULT_FABLE_MODEL=$env:ANTHROPIC_MODEL
$env:ANTHROPIC_DEFAULT_OPUS_MODEL=$env:ANTHROPIC_MODEL
$env:ANTHROPIC_DEFAULT_SONNET_MODEL=$env:ANTHROPIC_MODEL
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL=$env:ANTHROPIC_MODEL
$env:CLAUDE_CODE_SUBAGENT_MODEL=$env:ANTHROPIC_MODEL
$env:CLAUDE_CODE_EFFORT_LEVEL="high"
$env:CLAUDE_CODE_AUTO_COMPACT_WINDOW="1048576"
$env:CLAUDE_CODE_MAX_CONTEXT_TOKENS="1048576"

claude

Users with K3 256K-only access should use the configuration below:

sh
export ANTHROPIC_BASE_URL=https://api.kimi.com/coding/
export ANTHROPIC_API_KEY=Your API Key

export ANTHROPIC_MODEL=k3
export ANTHROPIC_DEFAULT_FABLE_MODEL=$ANTHROPIC_MODEL
export ANTHROPIC_DEFAULT_OPUS_MODEL=$ANTHROPIC_MODEL
export ANTHROPIC_DEFAULT_SONNET_MODEL=$ANTHROPIC_MODEL
export ANTHROPIC_DEFAULT_HAIKU_MODEL=$ANTHROPIC_MODEL
export CLAUDE_CODE_SUBAGENT_MODEL=$ANTHROPIC_MODEL
export CLAUDE_CODE_EFFORT_LEVEL=high
export CLAUDE_CODE_AUTO_COMPACT_WINDOW=262144
export CLAUDE_CODE_MAX_CONTEXT_TOKENS=262144

claude
powershell
$env:ANTHROPIC_BASE_URL="https://api.kimi.com/coding/"
$env:ANTHROPIC_API_KEY="Your API Key"

$env:ANTHROPIC_MODEL="k3"
$env:ANTHROPIC_DEFAULT_FABLE_MODEL=$env:ANTHROPIC_MODEL
$env:ANTHROPIC_DEFAULT_OPUS_MODEL=$env:ANTHROPIC_MODEL
$env:ANTHROPIC_DEFAULT_SONNET_MODEL=$env:ANTHROPIC_MODEL
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL=$env:ANTHROPIC_MODEL
$env:CLAUDE_CODE_SUBAGENT_MODEL=$env:ANTHROPIC_MODEL
$env:CLAUDE_CODE_EFFORT_LEVEL="high"
$env:CLAUDE_CODE_AUTO_COMPACT_WINDOW="262144"
$env:CLAUDE_CODE_MAX_CONTEXT_TOKENS="262144"

claude

Environment Variable Reference

VariablePurpose
ANTHROPIC_MODELThe model applied by the current configuration
CLAUDE_CODE_EFFORT_LEVELDefault thinking effort level; set to high in the configuration
CLAUDE_CODE_AUTO_COMPACT_WINDOWThreshold for auto-compaction
CLAUDE_CODE_MAX_CONTEXT_TOKENSMaximum context token budget

Switching thinking effort

After starting, type /effort in a session to switch thinking effort levels — no environment variable needed. K3 supports low / high / max; the mapping from Claude Code levels to K3 levels is:

Claude Code levelK3 level
lowlow
mediumhigh (recommended)
highhigh (recommended)
xhighmax
maxmax
Not set (default)high

Note

Disabling thinking routes both K3 and K2.7 Code to K2.6. Keep Thinking on to use K3 / K2.7; for K2.7 Code the shortcut is Option+T on macOS and Alt+T on Windows / Linux.

If prompted whether to use this API key, confirm to proceed. Afterwards, follow the prompts to select your trusted project folder to complete the authorization.

Claude Code Authorize Project Access

Verify After Starting

After starting, enter /status. If the returned information shows Base URL as https://api.kimi.com/coding/, the configuration is successful. Even if the model name still appears as a Claude model, the actual calls are still made to the Kimi Code API.

Claude Code Status Check