Ollama Local AI Programming Assistant
This chapter customizes a local model dedicated to coding, runoob-coder, and connects it to VS Code and Claude Code, building a completely offline programming assistant with no token costs.
The core work is three things: choose the right code model, write a good coding Modelfile, and connect to handy tools.
Step 1: choose a code model, VRAM has the final say
The capability gap between code models is more pronounced than for chat models, but the barrier is also higher; choose according to your VRAM:
| Your hardware | Recommended model | Expected performance |
|---|---|---|
| 24GB+ VRAM | qwen3-coder | Dedicated code model, strongest cross-file understanding; 30B-class parameters demand a lot of VRAM, and long contexts need more headroom |
| 16GB RAM, no discrete GPU | qwen3.5:9b customized version | Enough for daily completion, code explanation, and writing unit tests |
| Old machine with 8GB RAM | qwen3.5:4b / 0.8b customized version | Lightweight Q&A; leave complex tasks to the cloud |
No need to regret not having enough VRAM to run qwen3-coder: use the :cloud tag to call the cloud version directly; code-sensitive teams should remember to go through compliance first.
Choose which to pull based on hardware:
ollama pull qwen3-coder # 24GB+ 显存
ollama pull qwen3.5:9b # 16GB 内存
Step 2: write a Modelfile for the coding scenario
A bare model can write usable code but is not "professional" - no comments, tends to digress, arbitrary formatting. Use a Modelfile to solidify coding standards:
Example
File path: Modelfile
With 24GB+ VRAM, replace the base with qwen3-coder
FROM qwen3.5:9b
SYSTEM
""
"
You are the programming assistant of the RUNOOB team; follow these guidelines:
- Prefer giving complete, directly runnable code rather than snippets
- Write Chinese comments for each key step, explaining "
Why
"
3. Follow PEP 8 (Python) or the language's official style
4. When dealing with unfamiliar APIs, remind to check official docs and do not fabricate interfaces
5. Answer structure: one-sentence idea - code - notes
"
""
Keep code scenarios stable by lowering randomness
PARAMETER temperature
0.2
Agent/editor scenarios have large code contexts, so give enough window
PARAMETER num_ctx
65536
Build the dedicated coding model:
ollama create runoob-coder -f Modelfile
To verify it is "well trained", test with three standard tasks: make a function directly usable (check completeness), explain a piece of old code with pitfalls (check understanding), and ask for unit tests (check guideline compliance). Only after all three pass, connect it to the editor.
num_ctx 65536 is prepared for editor and Agent scenarios: they stuff entire files or even multiple files into the context. When VRAM is tight, reduce to 32768 and use ollama ps to check whether PROCESSOR is still 100% GPU.
Step 3: connect to your editor
A customized model is no different from a bare model in the eyes of tools; the connection method is exactly the same as in Part 11.
VS Code Chat integration
After installing the official Ollama extension, just select runoob-coder in the Chat model picker; no other configuration needed.
Claude Code integration
Example
One-click method
ollama launch claude
--model
runoob-coder
Manual method: point environment variables to local, use the customized model name
export
ANTHROPIC_AUTH_TOKEN
=ollama
export
ANTHROPIC_BASE_URL
=http:
//
localhost:
11434
claude
--model
runoob-coder
After integration, Claude Code's file editing, command execution, and multi-turn refactoring capabilities are all driven by the local model; before long tasks, remember to confirm the context window is set as described above.
Effect comparison and model switching strategy
Different tasks should use models of different scales; solidify the selection strategy to avoid agonizing each time:
| Task Type | Recommended model | Reason |
|---|---|---|
| Function completion, code explanation, writing unit tests | runoob-coder (local) | Fast, free, private |
| Cross-file refactoring, complex debugging | qwen3-coder or cloud flagship | Need stronger long-context understanding |
| Batch generation, scripted processing | Local small model + API | Zero-cost volume running |
Switching cost must be low enough for switching to actually happen:
Example
Switch models directly in the terminal chat without exiting
/
load qwen3-coder
In VS Code just click in the model picker
In Claude Code specify with --model at startup
A practical combined strategy: hand 90% of daily requests to a small local model, and switch to a large or cloud model only for genuinely tough problems. Ollama's coexistence of multiple tags makes this "tiered" strategy cost nothing to switch.