Claude Code + Ollama: Coding with a Local Model
Claude Code is Anthropic's agentic coding tool. It reads your project, edits files, and runs commands from the terminal. With Ollama, you can run it on a model hosted on your own machine instead of in the cloud.
Why local models?
- Your code never leaves your machine
- No API costs
- Works offline
In this guide, you'll install Claude Code, run it inside IntelliJ IDEA, connect it to Ollama, and test it on a small Java project.
Step 1: Install Claude Code
Install it globally with npm:
npm install -g @anthropic-ai/claude-code
Then open a terminal and run:
claude
If the Claude Code prompt appears, the installation worked.
Step 2: Run It Inside IntelliJ IDEA
You don't need to leave your IDE. Open your project in IntelliJ, open the built-in terminal (View β Tool Windows β Terminal), and run:
claude
Claude Code now has access to your project files and works right next to your code.
Step 3: Connect It to Ollama
Ollama exposes an Anthropic-compatible API, so Claude Code can talk to a local model.
1. Install Ollama
Ollama lets you download and run language models on your own machine. Your code never leaves your computer and there is no per-request cost.
On https://ollama.com you can create a free account. The dashboard shows your free quota for cloud models. For the rest of this tutorial (100% local), it isn't required.
2. Pull a coding model:
ollama pull qwen3.5:9b
3. Point Claude Code at Ollama:
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_BASE_URL=http://localhost:11434
claude --model qwen3.5:9b
On Windows PowerShell, use $env:ANTHROPIC_AUTH_TOKEN="ollama" and $env:ANTHROPIC_BASE_URL="http://localhost:11434" instead of export.
Alternatively, let Ollama handle the setup with one command, using --model
ollama launch claude --model qwen3.5:9b
Step 4: Build a Demo Project
Let's test the setup with a small Java project: a console task manager.
Create an empty Java project in IntelliJ, open the terminal, start Claude Code, and give it this prompt:
Create a simple Java console app: a task manager. Users can add,
list, complete and delete tasks. Save tasks to a text file so they
persist. Keep it to 2-3 classes.
Claude Code will plan the work, create the files, fix the errors, and ask for your permission before making changes. Approve the actions and watch it work.
Then run the app and try it out:
Notice that it doesn't only generate code. It also creates the files, runs the program, and fixes its own errors.
Cloud vs Local: Quick Comparison
| Cloud Claude | Local model (Ollama) | |
|---|---|---|
| Privacy | Code is sent to the API | Stays on your machine |
| Cost | Subscription / API | Free |
| Speed | Fast | Depends on your hardware |
| Quality | Highest | Good for small tasks |
Conclusion
Claude Code with Ollama is a practical way to try agentic coding without sending your code anywhere, as long as your machine can handle the model. Start with a small project like this one, then try it on your own code.
Thanks for reading!








Top comments (15)
2.1.300 reportedly cut 19,045 prompt tokens, handy for 9b models.
Thanks for the tip! I can't confirm the exact number, but lower prompt overhead definitely helps small models since the system prompt eats into the context window.
Local is the right place for the cheap steps. A lot of a session is reads, so the split matters. Does the review step still go to the cloud model?
Great question! In this demo everything ran locally, so I haven't tested a split yet. Local for reading and boilerplate, and a cloud model for the final review, sounds like the sweet spot. I am planning on trying it and cover it in a follow-up.
@mohammed_sebaa_2610 Local for the reads, cloud for the final review. A missed error costs the most at the review, so that is where the better model earns its price.
Great job, Mohammed! Your explanation is so clear and helpful for beginners. Keep it up, and best of luck! π
Thank you! Means a lot, and glad you found it helpful!
Clear and simple
Thank You !
Well done, bro! π
Thank you !
I found this very useful. Thank you for sharing this clear and practical guide! π
You're very welcome! Glad you found the guide useful! π
Great tutorial. A practical way to explore local AI-assisted coding with Ollama and Claude Code. Thanks for sharing
You're welcome! Thanks for reading, glad it was useful!