Claude Code can connect to Kimi K3, but only through Kimi Code’s Anthropic-compatible endpoint, not through the Kimi Open Platform API. Use a Kimi Code API key, set https://api.kimi.com/coding/ as the Base URL, choose a model ID available to the account, and validate tool calls before using the setup on real projects.
This guide is for developers who want Kimi K3 inside Claude Code, administrators standardizing terminal agents for remote teams, and users troubleshooting 401 errors, missing models, or context-window changes.
Last updated August 1, 2026. Configuration details were checked against the official Kimi Code Claude Code guide, model documentation, error reference, and Anthropic Claude Code documentation.
The first decision is choosing the correct Kimi service
>The most common failed setup is not caused by Claude Code. It comes from mixing credentials and endpoints from two separate Kimi systems.
Kimi Code is designed for terminal and IDE coding agents. Its Anthropic-compatible Base URL is:
https://api.kimi.com/coding/
The Kimi Open Platform uses a different API system and a different Base URL:
https://api.moonshot.cn/v1
Those credentials are not interchangeable. A key created for the Open Platform will not become a valid Kimi Code credential merely because the model name looks correct. Kimi’s official documentation identifies the wrong service, wrong Base URL, and wrong key as common causes of authentication failures. (Kimi Code Claude Code guide)
| Decision point | Kimi Code | Kimi Open Platform |
|---|---|---|
| Best fit | Claude Code, terminal agents, IDE coding workflows | Product APIs, application backends, general model integration |
| Anthropic-compatible Base URL | https://api.kimi.com/coding/ |
Not the Kimi Code endpoint |
| OpenAI-compatible Base URL | https://api.kimi.com/coding/v1 |
https://api.moonshot.cn/v1 |
| Credential source | Kimi Code Console | Kimi Open Platform account |
| Billing model | Membership benefits with usage and frequency limits | Usage-based platform billing |
| Correct choice for Claude Code | Yes | No |
A typical failure looks like this: a developer copies an Open Platform key, sets ANTHROPIC_BASE_URL to the Kimi Open Platform address, and then receives a 401 or a provider-specific model error. Replacing only the model ID usually does not fix it because the authentication system is still wrong.
Kimi Code’s official documentation also warns against changing the client identity or User-Agent used by supported tools. The safer approach is to keep Claude Code’s normal client behavior and change only the provider endpoint, credential, and model configuration. (Kimi Code documentation)
Before continuing, confirm four conditions:
- Claude Code is installed and starts from the terminal.
- The Kimi account has Kimi Code access and permission for the intended model.
- The API key was created in the Kimi Code Console.
- A separate test directory is ready so the first agent requests cannot modify a production repository.
Claude Code Connect Kimi K3 with a clean environment
>Anthropic’s current setup documentation lists Node.js 18 or later and at least 4 GB of RAM for Claude Code. The official installation command is:
npm install -g @anthropic-ai/claude-code
After installation, check the local installation before configuring the provider:
claude doctor
Anthropic documents claude doctor as the diagnostic command for checking the installation type and local setup. (Anthropic Claude Code getting started guide)
Create a disposable test directory:
mkdir -p ~/claude-kimi-k3-test
cd ~/claude-kimi-k3-test
printf '{"name":"claude-kimi-k3-test"}\n' > package.json
The test directory should contain only harmless files. Do not start with a repository that contains deployment credentials, customer data, private SSH keys, or destructive scripts.
Create the Kimi Code credential in the official console and keep the full value outside shell history where possible. Kimi’s documentation states that API keys are shown only when created, so losing the value normally requires creating a replacement key. (Kimi Code Claude Code guide)
For macOS and Linux, configure the Anthropic-compatible endpoint as follows:
export ANTHROPIC_BASE_URL="https://api.kimi.com/coding/"
export ANTHROPIC_API_KEY="<KIMI_CODE_API_KEY>"
export ANTHROPIC_MODEL="k3-256k"
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
For PowerShell, use the equivalent session variables:
$env:ANTHROPIC_BASE_URL="https://api.kimi.com/coding/"
$env:ANTHROPIC_API_KEY="<KIMI_CODE_API_KEY>"
$env:ANTHROPIC_MODEL="k3-256k"
$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
The key is intentionally represented by a placeholder. A real key should never be pasted into a public tutorial, committed to .env, or placed in a shell script that will be shared with a team.
What should be entered as the Kimi K3 Anthropic Base URL? Use https://api.kimi.com/coding/ for Claude Code. Do not append /v1/messages when setting ANTHROPIC_BASE_URL; Claude Code constructs the request path for the Anthropic protocol. The complete Messages endpoint is useful for direct API testing, but it is not the same configuration field.
The k3-256k model is the safer first choice for routine coding, small repositories, and single-file edits. Kimi’s model documentation lists it as the 256K-context K3 variant. The standard k3 model can be configured for a context window of up to 1,048,576 tokens when the account and client settings support it. (Kimi Code model documentation)
The first five minutes should prove the connection
>Do not begin by asking the agent to refactor a real application. First verify the provider, authentication, model response, streaming behavior, and read-only file access.
Start Claude Code inside the test directory and run:
/status
A successful setup should show the Kimi Code Anthropic Base URL:
https://api.kimi.com/coding/
The displayed model label may still resemble a Claude model because Claude Code controls part of the interface. The Base URL and the actual response behavior are more useful signals than the label alone.
Then run a read-only request:
Read package.json only. Return the project name and the exact sentence READY. Do not edit files or run shell commands.
For a non-interactive check, use Claude Code’s print mode:
claude -p "Read package.json only. Return the project name and the exact sentence READY. Do not run commands." \
--output-format json \
--verbose
Anthropic’s CLI reference documents -p, JSON output, verbose output, and model selection as supported command-line controls. (Anthropic Claude Code CLI reference)
Record three pieces of evidence:
- The HTTP status code, if it appears in verbose output.
- The exact error text, if the request fails.
- Whether Claude Code can read the file without requesting unrelated access.
A direct Anthropic-format request can isolate the provider from Claude Code itself:
curl -sS https://api.kimi.com/coding/v1/messages \
-H "x-api-key: ${ANTHROPIC_API_KEY}" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "k3-256k",
"max_tokens": 64,
"messages": [
{
"role": "user",
"content": "Reply with READY."
}
]
}'
This request uses the standard model ID k3-256k. The special k3[1m] form belongs to Claude Code environment-variable configuration and should not be copied into a direct API request or another tool’s model field.
Important: If the direct request works but Claude Code fails, investigate Claude Code onboarding, environment-variable scope, or client configuration. If both fail, investigate the key, Base URL, account permission, and model access first.
The first hour must test agent behavior, not only chat
>A successful text reply proves very little. Claude Code is useful because it can inspect files, propose edits, execute approved commands, and coordinate several tool calls. Kimi K3 should therefore be tested as an agent inside the same controlled directory.
Use this sequence:
- Ask Claude Code to list the files it can see without changing anything.
- Ask it to read
package.jsonand explain the project entry point. - Add a harmless file such as
agent-test.txt. - Ask it to modify that file with a known sentence.
- Ask it to run a non-destructive command such as
pwdorgit diff -- agent-test.txt. - Ask it to explain the change and stop.
Example prompt:
Inspect this test directory. Read package.json, create agent-test.txt, write "Kimi K3 agent test" into it, and show the resulting diff. Do not access parent directories.
This sequence tests file reading, file editing, command execution, permission prompts, and the final response. It also exposes a common false positive: a provider may answer ordinary messages while failing when Claude Code sends tool-use blocks, permission metadata, or a longer conversation history.
Kimi K3 supports low, high, and max thinking levels. The official mapping for Claude Code maps low to low effort, medium and high to high effort, and xhigh or max to max effort. The default is high when no effort is specified.
For routine implementation work, high is a reasonable baseline. Use max only after checking response time, quota behavior, and team policy. Disabling thinking can route requests away from K3, so a test that unintentionally turns thinking off may not represent the selected model.
Long-context changes require a new session plan
>How should Kimi K3 long context be configured in Claude Code? Use the standard k3 model with Claude Code’s explicit 1M context settings when the account has the required access:
export ANTHROPIC_MODEL="k3[1m]"
export CLAUDE_CODE_AUTO_COMPACT_WINDOW="1048576"
export CLAUDE_CODE_MAX_CONTEXT_TOKENS="1048576"
The k3[1m] value is the Claude Code environment-variable form for requesting a 1M context window. In other API clients, use k3 without the bracket suffix.
The 256K configuration is:
export ANTHROPIC_MODEL="k3-256k"
export CLAUDE_CODE_AUTO_COMPACT_WINDOW="262144"
export CLAUDE_CODE_MAX_CONTEXT_TOKENS="262144"
A model switch should not be treated as a cosmetic change. If the existing session already contains more context than the target model can accept, the client may compact, reject the request, or preserve unsupported historical blocks incorrectly. The safer approach is to compact before switching and create a new session when the history still exceeds the target.
Use this order:
- Save or commit any important code changes.
- Run the session’s compact command if available.
- Confirm that the compressed summary still contains the task, constraints, and pending files.
- Start a new session if the context is still above the target.
- Set the new model and context variables.
- Re-run a small read-only request before resuming edits.
A new session is also safer when the old history contains images, video, unsupported content blocks, or provider-specific reasoning data. The exact behavior can depend on the Claude Code version and the Kimi Code compatibility layer, so a clean session is usually faster than repeatedly retrying a damaged conversation.
Error handling should follow status codes and exact text
>What should be done when Claude Code says the Kimi K3 model does not exist? First inspect the exact model string. If the error mentions k3[1m], confirm that the value is being used only in Claude Code environment variables. For direct API requests and third-party model fields, replace it with k3. If the account does not support K3, switch to a model shown as available in the Kimi Code account rather than guessing another name.
Use this diagnostic order:
- 401 or invalid key: verify that the key came from Kimi Code Console, not the Kimi Open Platform. Check for hidden whitespace and confirm that
ANTHROPIC_API_KEYexists in the same terminal session that startsclaude. - 401 with model ID text: check spelling, suffixes, and the account’s model permission. Do not use a Claude model name as a substitute for a Kimi model ID.
- 402 or membership verification error: confirm that the Kimi Code membership is active and that the account can access the selected model. Retrying may help with a temporary verification issue, but repeated failures require checking account status.
- 400 related to thinking or request format: check the effort value. Unknown effort values can produce a 400 response.
- Context overflow: compact the current session, lower the target context, or start a new session before switching models.
- Successful chat but failed tools: repeat the file-read and command-execution tests. The issue may be in tool-use compatibility or permission handling rather than authentication.
The official error reference groups Kimi Code failures around authentication, account verification, model selection, request format, and context conditions. (Kimi Code error reference)
Do not solve every error by changing several variables at once. Change one item, repeat the same low-risk request, and keep a short record of the status code and response text. This prevents a working configuration from becoming impossible to reproduce.
Team rollout needs isolation and rollback
>A personal terminal setup is not a production configuration. Before a remote team shares Claude Code with Kimi K3, complete an acceptance pass across five areas.
Credential isolation: Give each developer or environment a separate, revocable key where the account policy allows it. Never place a personal key in a shared shell profile, repository, image, or team chat.
Minimal permissions: Start with a dedicated test project and restrict the directories Claude Code can access. Shared environments should not automatically expose home directories, SSH folders, cloud credentials, or unrelated repositories.
Quota ownership: Kimi Code membership limits and usage benefits belong to the account that owns the credential. A shared key makes it difficult to identify who consumed capacity, which project caused failures, or whether a usage spike came from an agent loop.
Version control: Record the Claude Code version, the selected Kimi model ID, the Base URL, context settings, and the date of the last successful validation. Do not lock a stale workaround without checking the current official Kimi Code documentation.
Fallback behavior: Define a rollback model before a production task starts. A practical policy is to keep k3-256k as the default for ordinary coding, use k3[1m] only for approved long-context tasks, and retain an alternative provider configuration outside the repository. The fallback should be tested, not merely written into a document.
Teams that need a repeatable remote workstation should separate the machine layer from the model layer. A managed Mac environment can provide a consistent shell, Node.js installation, project permissions, and credential-injection policy, while the Kimi model settings remain replaceable. Before choosing that route, review Zilmac’s cloud Mac environment options and Mac support scope so the operating system, access method, and support boundary are clear.
When a cloud Mac is better than copying a local setup
>A local Mac is usually the better choice for one developer who needs stable long-term access, physical devices, or direct control of the machine. The current approach becomes weaker when a remote team must reproduce the same Claude Code installation, isolate credentials, preserve a clean test environment, and hand the workspace between operators.
The practical disadvantages are specific:
- Personal laptops often carry mixed credentials and unrelated repositories.
- Team members can silently use different Node.js, Claude Code, or shell versions.
- A shared API key makes quota ownership and incident review difficult.
- Rebuilding a failed environment consumes more time than changing a model variable.
- A laptop that sleeps, changes networks, or leaves the office is a poor unattended agent host.
For short experiments, migration tests, and temporary agent workloads, renting a Mac through Zilmac can provide a cleaner boundary than copying one developer’s terminal profile into a shared environment. The decision still depends on workload: long-running heavy use may justify buying dedicated hardware, while tasks requiring physical USB devices may not fit a remote Mac at all. Readers planning a persistent setup can compare Mac VPS plans with the requirements of their Claude Code workflow before moving credentials or repositories.
The key is to validate the model integration first, then choose where it should run. Claude Code can connect to Kimi K3 once the Kimi Code endpoint, key, model ID, context mode, and rollback process are kept separate from the Open Platform configuration.
Run Your AI Development Workflow on a Remote Mac
Deploy a dedicated Mac from Zilmac for a stable macOS environment.
Access your remote Mac from anywhere without maintaining local hardware. — View Plan Options