DEV Community

SEBAA Mohammed
SEBAA Mohammed

Posted on

Running Claude Code with Ollama and Local Models

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
Enter fullscreen mode Exit fullscreen mode

install claude code via npm

Then open a terminal and run:

claude
Enter fullscreen mode Exit fullscreen mode

run claude code in terminal

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
Enter fullscreen mode Exit fullscreen mode

Running claude code in a terminal in intelij

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
Enter fullscreen mode Exit fullscreen mode

3. Point Claude Code at Ollama:

export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_BASE_URL=http://localhost:11434
claude --model qwen3.5:9b
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

run claude code with specific model

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.
Enter fullscreen mode Exit fullscreen mode

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.

claude code running

claude code running

Then run the app and try it out:

testing program

testing program

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)

Collapse
 
aidiveyt profile image
AI Dive •

2.1.300 reportedly cut 19,045 prompt tokens, handy for 9b models.

Collapse
 
mohammed_sebaa_2610 profile image
SEBAA Mohammed •

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.

Collapse
 
paul_irolla_6b5ae261d0224 profile image
Paul Irolla •

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?

Collapse
 
mohammed_sebaa_2610 profile image
SEBAA Mohammed •

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.

Collapse
 
paul_irolla_6b5ae261d0224 profile image
Paul Irolla •

@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.

Collapse
 
nenhibi profile image
ENHIBI NAJOUA •

Great job, Mohammed! Your explanation is so clear and helpful for beginners. Keep it up, and best of luck! 😊

Collapse
 
mohammed_sebaa_2610 profile image
SEBAA Mohammed •

Thank you! Means a lot, and glad you found it helpful!

Collapse
 
adnan_bachard profile image
Adnan Bachard •

Clear and simple

Collapse
 
mohammed_sebaa_2610 profile image
SEBAA Mohammed •

Thank You !

Collapse
 
hamza_kebir_3a70cac2620d1 profile image
Hamza Kebir •

Well done, bro! πŸ‘

Collapse
 
mohammed_sebaa_2610 profile image
SEBAA Mohammed •

Thank you !

Collapse
 
abdelkhaleq_samili_bcaf90 profile image
abdelkhaleq samili •

I found this very useful. Thank you for sharing this clear and practical guide! πŸ™Œ

Collapse
 
mohammed_sebaa_2610 profile image
SEBAA Mohammed •

You're very welcome! Glad you found the guide useful! πŸ™Œ

Collapse
 
ismail_souifi_725ea8a7454 profile image
ismail souifi •

Great tutorial. A practical way to explore local AI-assisted coding with Ollama and Claude Code. Thanks for sharing

Collapse
 
mohammed_sebaa_2610 profile image
SEBAA Mohammed •

You're welcome! Thanks for reading, glad it was useful!