# Using Kimi K3 with Claude Code

After configuration, Claude Code's main conversations, background tasks, and sub-agents will all use Kimi K3.

## Prepare a Token

Create an `sk-4ai-...` Token in [Dashboard → Manage Tokens](https://4aicode.com/tokens). Claude Code only requires a 4AICode Token.

## Permanent Configuration (Recommended)

Open `~/.claude/settings.json` and add the following content to `env`. If you already have other Claude Code settings, preserve the existing content and merge the `env` field.

```json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://relay.4aicode.com",
    "ANTHROPIC_AUTH_TOKEN": "sk-4ai-xxxxxxxxxxxxxxxx",
    "ANTHROPIC_MODEL": "kimi-k3",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "kimi-k3",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "kimi-k3",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "kimi-k3",
    "ANTHROPIC_DEFAULT_FABLE_MODEL": "kimi-k3",
    "CLAUDE_CODE_SUBAGENT_MODEL": "kimi-k3",
    "ENABLE_TOOL_SEARCH": "false",
    "CLAUDE_CODE_AUTO_COMPACT_WINDOW": "1048576",
    "CLAUDE_CODE_EFFORT_LEVEL": "max"
  }
}
```

Replace the example Token with your own 4AICode Token. After saving, completely exit and reopen Claude Code.

> `settings.json` contains your Token in plain text. Store it securely and exclude it from Git commits.

## Temporary Configuration

Temporary configuration only applies to the current terminal window and is suitable for trying it out first.


**macOS / Linux**


```bash
export ANTHROPIC_BASE_URL="https://relay.4aicode.com"
export ANTHROPIC_AUTH_TOKEN="sk-4ai-xxxxxxxxxxxxxxxx"
export ANTHROPIC_MODEL="kimi-k3"
export ANTHROPIC_DEFAULT_OPUS_MODEL="kimi-k3"
export ANTHROPIC_DEFAULT_SONNET_MODEL="kimi-k3"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="kimi-k3"
export ANTHROPIC_DEFAULT_FABLE_MODEL="kimi-k3"
export CLAUDE_CODE_SUBAGENT_MODEL="kimi-k3"
export ENABLE_TOOL_SEARCH="false"
export CLAUDE_CODE_AUTO_COMPACT_WINDOW="1048576"
export CLAUDE_CODE_EFFORT_LEVEL="max"
claude
```


**Windows PowerShell**


```powershell
$env:ANTHROPIC_BASE_URL="https://relay.4aicode.com"
$env:ANTHROPIC_AUTH_TOKEN="sk-4ai-xxxxxxxxxxxxxxxx"
$env:ANTHROPIC_MODEL="kimi-k3"
$env:ANTHROPIC_DEFAULT_OPUS_MODEL="kimi-k3"
$env:ANTHROPIC_DEFAULT_SONNET_MODEL="kimi-k3"
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL="kimi-k3"
$env:ANTHROPIC_DEFAULT_FABLE_MODEL="kimi-k3"
$env:CLAUDE_CODE_SUBAGENT_MODEL="kimi-k3"
$env:ENABLE_TOOL_SEARCH="false"
$env:CLAUDE_CODE_AUTO_COMPACT_WINDOW="1048576"
$env:CLAUDE_CODE_EFFORT_LEVEL="max"
claude
```


Keep all the model variables shown in the example. Claude Code uses different model variables for main conversations, summaries, sub-agents, and other scenarios.

## Verify the Configuration

Start Claude Code and enter:

```text
/status
```

Confirm that the Base URL is `https://relay.4aicode.com` and the Model is `kimi-k3`, then send a message to test it.

Claude Code's `/model` menu primarily displays built-in Claude models. Refer to `/status` for the actual Kimi K3 configuration.

## Troubleshooting

| Issue | Solution |
|---|---|
| 401 or invalid Token | Check or recreate the Token on the [Token page](https://4aicode.com/tokens) |
| Model not found | Set all model variables to `kimi-k3`; the model name must not include the `[1m]` suffix |
| Main conversations work, but background tasks fail | Check that the configuration includes Haiku, Fable, and `CLAUDE_CODE_SUBAGENT_MODEL` |
| Tool Search or tool calls behave unexpectedly | Confirm that `ENABLE_TOOL_SEARCH` is set to `false` |
| Changes do not take effect | `settings.json` overrides environment variables with the same names in the terminal. After saving, completely restart Claude Code |

This configuration method is based on the [official Kimi Claude Code guide](https://platform.kimi.com/docs/guide/claude-code-kimi). For configuring standard Claude models and ChatGPT models, see [Claude Configuration](/docs/en/guides/claude).
