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 (2)

Collapse
 
adnan_bachard profile image
Adnan Bachard •

Clear and simple

Collapse
 
hamza_kebir_3a70cac2620d1 profile image
Hamza Kebir •

Well done, bro! 👏