melwyn.class
← All playbooks
Free
12 minUpdated 2026-06-30

Run Claude Code directly on GLM, Kimi, or DeepSeek

Skip the middleman. Point Claude Code straight at a provider's own endpoint for the lowest price, often a flat coding plan, with the trade-offs mapped.

The outcome

By the end you'll have Claude Code driving GLM, Kimi, or DeepSeek through the provider's own endpoint, on the cheapest plan each one offers.

  • Claude Code installed (the terminal CLI, or the VS Code extension)
  • An account and API key from at least one of GLM, Kimi, or DeepSeek
  • Ten minutes and a text editor for one config file
I work in:

OpenRouter is the easy on-ramp: one key, every model. But it takes a small cut and bills by the token. Once you know which open model you like, going straight to its maker is usually cheaper, and GLM, Kimi, and DeepSeek each sell a flat monthly coding plan that undercuts per-token rates. Each one runs its own Claude Code endpoint, so the move is always the same: change the address and the key in one file. New to all this? Start with the OpenRouter guide, then come back here to cut the bill.

In a hurry? Let Claude set it up

Copy this into your working Claude Code or claude.ai. It asks which provider you want, then walks you through the rest, one step at a time.

I want to run Claude Code directly on an open-source model's own endpoint instead of Claude, to cut my costs. Walk me through it on my machine, one step at a time, and wait for me to confirm each step.

1. Ask me which provider I want (GLM from Z.AI, Kimi from Moonshot, or DeepSeek) and whether I use the terminal or the VS Code extension.
2. Help me create or open the config file ~/.claude/settings.json with the exact commands for my OS. Remind me not to type the bare file path into the terminal, since that just tries to run it.
3. Point me to that provider's API key page and help me create a key.
4. Help me set the "env" block to that provider's Anthropic endpoint: ANTHROPIC_BASE_URL to https://api.z.ai/api/anthropic for GLM, https://api.moonshot.ai/anthropic for Kimi, or https://api.deepseek.com/anthropic for DeepSeek; ANTHROPIC_AUTH_TOKEN to my key; ANTHROPIC_API_KEY left empty.
5. Tell me how to restart Claude Code and run /status to confirm it is on the provider.
6. If I'm in VS Code, explain the integrated terminal versus the sidebar.

Start by asking which provider and setup I'm on.
  1. 1. Put your config in one file

    Direct providers use the exact same file as the OpenRouter setup: ~/.claude/settings.json, read by Claude Code everywhere it runs. You'll fill in an env block with three values: the provider's address, your key, and a blank Anthropic key. Never opened this file? The walkthrough below has the exact commands, or copy the prompt at the top to let Claude do it.

    ~/.claude/settings.json. The next steps fill in the values.
    {
      "env": {
        "ANTHROPIC_BASE_URL": "...",
        "ANTHROPIC_AUTH_TOKEN": "...",
        "ANTHROPIC_API_KEY": ""
      }
    }
    Never opened this file? Create and open it, step by step

    The file sits in a hidden .claude folder in your home directory. Run these in a terminal to create it, then open it in an editor. On Windows, use PowerShell.

    macOS or Linux: create the folder and the empty file
    mkdir -p ~/.claude
    touch ~/.claude/settings.json
    Then open it in an editor
    code ~/.claude/settings.json     # opens it in VS Code
    
    # "code" not found? In VS Code press Cmd+Shift+P and run
    # "Shell Command: Install 'code' command in PATH", then try again.
    # No VS Code? Open it in TextEdit instead:
    open -e ~/.claude/settings.json

    Watch out

    Do not type ~/.claude/settings.json on its own and press enter. The shell treats it as a program, tries to run the file, and you get "permission denied". A path always needs a command in front of it, like code or open -e.

    Windows (PowerShell): create it, then open it in Notepad
    mkdir "$HOME\.claude" -Force
    notepad "$HOME\.claude\settings.json"

    Paste your provider's env block from step 3 into the file, then save and close. If the file already had something in it, keep it and add the env block inside the outer curly braces.

  2. 2. Pick a provider and get a key

    Three good options, each with its own Claude Code endpoint. GLM 5.2 from Z.AI is the strongest all-rounder and the most tuned for coding agents. Kimi K2 from Moonshot is fast and cheap. DeepSeek is the budget pick with a generous coding plan. Pick one, make an account, and create an API key. The links go to each provider's setup docs, which show where to get the key and confirm the current endpoint.

  3. 3. Paste your provider's endpoint

    Same file, same env block, only two values change: the address and the key. Pick your provider's block, paste it into ~/.claude/settings.json, and drop in your key. You usually don't set a model name at all, because these endpoints map Claude's own names (Opus, Sonnet, Haiku) onto their models for you. Each block also sets two safety lines for a non-Claude model: CLAUDE_CODE_DISABLE_1M_CONTEXT (stops the [1m] tag these endpoints reject) and CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING (stops the thinking mode the VS Code sidebar errors on). After you paste, fully quit and reopen Claude Code, since it reads the file only at startup, then run /status to confirm the endpoint is your provider.

    GLM (Z.AI). For Kimi or DeepSeek, open the block below.
    {
      "env": {
        "ANTHROPIC_BASE_URL": "https://api.z.ai/api/anthropic",
        "ANTHROPIC_AUTH_TOKEN": "your-z-ai-key",
        "ANTHROPIC_API_KEY": "",
        "CLAUDE_CODE_DISABLE_1M_CONTEXT": "1",
        "CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING": "1"
      }
    }
    Kimi and DeepSeek blocks
    Kimi (Moonshot)
    {
      "env": {
        "ANTHROPIC_BASE_URL": "https://api.moonshot.ai/anthropic",
        "ANTHROPIC_AUTH_TOKEN": "your-moonshot-key",
        "ANTHROPIC_API_KEY": "",
        "CLAUDE_CODE_DISABLE_1M_CONTEXT": "1",
        "CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING": "1"
      }
    }
    DeepSeek
    {
      "env": {
        "ANTHROPIC_BASE_URL": "https://api.deepseek.com/anthropic",
        "ANTHROPIC_AUTH_TOKEN": "your-deepseek-key",
        "ANTHROPIC_API_KEY": "",
        "CLAUDE_CODE_DISABLE_1M_CONTEXT": "1",
        "CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING": "1"
      }
    }
    Restart Claude Code, then check /status. The endpoint should be your provider.
    Claude Code
  4. 4. Use it in VS Code, terminal and sidebar

    VS Code has two ways to run Claude Code, and they read your settings differently. The integrated terminal is just a terminal: open it, type claude, and you're on the provider, because it runs the same command that reads your file. The sidebar, the chat panel, is the catch. It checks your login before it ever reads ~/.claude/settings.json, so on a custom endpoint it never sees your key and bounces to the Anthropic sign-in screen. The fix is to give the extension its own copy of the values: open VS Code's own settings with Cmd+Shift+P and "Preferences: Open User Settings (JSON)," add them under claudeCode.environmentVariables as below, then reload with Cmd+Shift+P and "Developer: Reload Window." If you don't need the sidebar, the simpler move is to keep your provider work in the integrated terminal, which just works.

    To put the VS Code sidebar on the provider too, add this to VS Code's own settings (not the file above), then reload the window. GLM shown; swap the URL for Kimi or DeepSeek.
    // VS Code settings.json, not ~/.claude/settings.json
    {
      "claudeCode.environmentVariables": [
        { "name": "ANTHROPIC_BASE_URL", "value": "https://api.z.ai/api/anthropic" },
        { "name": "ANTHROPIC_AUTH_TOKEN", "value": "your-z-ai-key" },
        { "name": "ANTHROPIC_API_KEY", "value": "" }
      ]
    }
    The sidebar on a custom endpoint can bounce to this. Use the integrated terminal, or set the extension's env values too.
    Claude Code
    Sign in to Claude
    The extension didn't pick up your custom endpoint.
    Fix: set claudeCode.environmentVariables, or use the terminal.
  5. 5. Know when to switch back to Claude

    The trade-offs match any open model: prompt caching may not carry through, so watch the provider's own dashboard for the true cost, and weaker models wander on long, tool-heavy runs. One thing weighs heavier going direct: GLM, Kimi, and DeepSeek are all hosted in China, so for client work or anything sensitive, check each provider's data and retention terms before you send real code. Send routine, high-volume work here, and keep deep, sensitive, multi-file work on Claude.

Note

Stuck? "Issue with the selected model (...[1m])" means CLAUDE_CODE_DISABLE_1M_CONTEXT is missing; add it and restart. "Unsupported content type: redacted_thinking" in the VS Code sidebar is a known extension bug; CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING calms it and the integrated terminal avoids it. Edited the file but nothing changed? Settings load only at startup, so fully quit and reopen. Bounced to the Anthropic login? Run /logout once, then restart. To go back to Claude, delete the env block and restart.

Watch out

Going direct means your code is handled by a provider hosted in China. For anything covered by a client agreement or privacy rule, read their data terms first, or keep that work on Claude.

Tip

If you'll lean on one model daily, look for the provider's flat coding plan rather than per-token billing. It is usually the cheapest way to run an open model in Claude Code.