跳到正文
DEV Community· TheCodeStreet·· 2 小時前AI 評分65

Claude Code 在 VS Code 連接 Ollama 與 Qwen 3.8 (27B) 的免登入設定教學

Claude Code for Free in VS Code: No Login, No API Key (Ollama + Qwen 3.8)

AI 導讀

TheCodeStreet 示範如何在 VS Code 設定 Claude Code,讓 Anthropic 官方擴充功能透過 Ollama 在本機執行 qwen3.8:27b,毋須登入或 API key。

正文

Last time I ran Claude Code for free in the terminal. A lot of you asked the obvious follow-up: can I do this inside VS Code?

Yes. The official Claude Code extension can skip the Claude login entirely and talk to a model running on your own PC. No API key, no subscription, no bill. Then I gave it one prompt and it built a full Space Shooter game.

How it works

The extension normally sends your prompts to Anthropic's cloud. We point it at Ollama instead, which runs Qwen 3.8 locally on localhost:11434.

Piece Job
VS Code + Claude Code extension The editor and the agent you chat with
Ollama Runs the model and serves it on port 11434
Qwen 3.8 (27B) Actually writes the code

How you use Claude Code doesn't change. Only where the model runs does.

Before you start

  • VS Code (any recent version)
  • ~32 GB of memory between RAM and VRAM
  • ~20 GB free disk (the model is ~18 GB)
  • A GPU helps a lot (24 GB VRAM is ideal). Without one it still runs, just slower. ## 1. Install Ollama and pull the model

Windows: grab the installer from ollama.com. macOS / Linux:

curl -fsSL https://ollama.com/install.sh | sh
ollama --version   # needs 0.15 or newer
ollama pull qwen3.8:27b

Quick sanity check: ollama run qwen3.8:27b, say hi, then /bye.

2. Install the extension

Ctrl + Shift + X → search Claude Code → make sure the publisher is Anthropic → Install.

3. Set four environment variables (this skips the login)

Open Settings (Ctrl + ,), search Claude Code: Environment Variables, click Edit in settings.json and add:

[
  { "name": "ANTHROPIC_AUTH_TOKEN", "value": "ollama" },
  { "name": "ANTHROPIC_API_KEY",    "value": "ollama" },
  { "name": "ANTHROPIC_BASE_URL",   "value": "http://localhost:11434" },
  { "name": "ANTHROPIC_MODEL",      "value": "qwen3.8:27b" }
]

The two keys are placeholders. Ollama ignores them, but their presence stops the extension asking you to sign in. ANTHROPIC_BASE_URL is the real trick: it sends everything to your machine instead of the cloud.

Save, then Ctrl + Shift + P → Developer: Reload Window.

4. Map every model to Qwen with settings.local.json

The env vars configure the extension. This file configures your project, so nothing ever reaches for a paid model. Create .claude/settings.local.json in your project:

{
  "env": {
    "ANTHROPIC_BASE_URL": "http://127.0.0.1:11434",
    "ANTHROPIC_AUTH_TOKEN": "ollama",
    "ANTHROPIC_API_KEY": "",
    "ANTHROPIC_MODEL": "qwen3.8:27b",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "qwen3.8:27b",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "qwen3.8:27b",
    "ANTHROPIC_DEFAULT_FABLE_MODEL": "qwen3.8:27b",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "qwen3.8:27b",
    "CLAUDE_CODE_SUBAGENT_MODEL": "qwen3.8:27b",
    "CLAUDE_CODE_MAX_CONTEXT_TOKENS": "65536"
  }
}

The ANTHROPIC_DEFAULT_*_MODEL lines cover every built-in model choice, and CLAUDE_CODE_SUBAGENT_MODEL covers sub-agents.

💡 The context here is 64k, so set Ollama's context length to 64k too, or it will quietly forget your files mid-task. This file is machine-specific, so keep it out of Git.

5. The test: one prompt, one game

I opened the Claude Code panel and pasted:

Build a complete, visually stunning Space Shooter game in a single HTML file
using HTML, CSS, and JavaScript. Use Canvas for smooth gameplay, neon space
visuals, animated stars, player movement, shooting, enemy waves, particle
explosions, power-ups, score, lives, increasing difficulty, a boss fight,
and a game-over/restart screen. Make it responsive, polished, and fun to play
with keyboard controls. Keep all code in one index.html file with no external
libraries. Ensure everything works correctly.

A few minutes later: animated stars, a ship that moves and shoots, enemy waves, explosions and a boss with its own health bar. All of it generated locally, no tokens counted. (Gameplay is in the video above.)

The honest part

It's slower and less sharp than the hosted Claude models. But for side projects, learning and prototypes, a complete working game for $0 is hard to argue with.

Quick fixes if you get stuck:

  • Still asks you to log in: re-check all four env vars, save, reload the window.
  • Connection refused: Ollama isn't running. Open the app or run ollama serve.
  • Model not found: the name must match qwen3.8:27b exactly in both files.

- Slow or forgetful: set Ollama's context to 64k, close GPU-heavy apps, make sure the model fits in VRAM.

Full guide with requirements, a variable-by-variable breakdown and an FAQ is on my blog: Claude Code For Free in VS Code: Full Setup Guide.

Prefer the terminal? I covered that setup here: I Run Claude Code for $0 with Ollama + Qwen 3.8.

Which local model are you using for coding right now? And what should I make it build next? 👇

來源:DEV Community · dev.to