DEV Community

Cover image for How to Run Claude Code With Ollama and Local Models for Free
Federico Moretti
Federico Moretti

Posted on

How to Run Claude Code With Ollama and Local Models for Free

Yes, Ollama now officially supports Claude Code: I was just giving it a try, following a tutorial I found on the web, when an announce suddenly appeared on LinkedIn. Then, I updated my setup to fit the new configuration suggestions; it runs with GPT-OSS, Qwen3-Coder, and GLM-4.7.

The Power of Claude Code Locally

I already knew Claude Code. It was recently activated on my company account: the funny thing is that I’ve never used it for work yet. But I wanted to learn how to use it because it is a highly sought-after tool on the market. However, I had no intention of paying for it or keeping the company laptop on after work.

So I decided to test it with an LLM model locally, following a guide I found online: unfortunately, I ran into the same problems as its author. Some sample models are too slow, while others do not support Anthropic APIs such as CodeGemma, which does not allow functions to be invoked.

The best solution is to use one of the models mentioned by Ollama. They are on average heavier than I would have liked to try, but at the moment it seems like the optimal compromise. I’m talking about GPT-OSS, Qwen3-Coder, or GLM-4.7. I opted for the second one, because the first one doesn’t work well with CPUs.

Install Claude Code on macOS

Installation on macOS and Linux (or any other UNIX-like operating system) is identical. At this stage, you should not even change what Anthropic officially recommends. Just be careful with permissions: it is not recommended to be root, but in my case I had to reassign the ownership of the folder.

curl -fsSL https://claude.ai/install.sh | bash
Enter fullscreen mode Exit fullscreen mode

Once installed, it is recommended to export certain variables from the terminal emulator profile. You can do this manually or launch the program from Ollama: I opted for the first option, so I don’t have to go through the latter every time. Of course, if you intend to use a model stored in the cloud, you must add an API key.

nano ~/.zshrc

  export ANTHROPIC_AUTH_TOKEN=ollama
  export ANTHROPIC_API_KEY=""
  export ANTHROPIC_BASE_URL=http://localhost:11434

source ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

You can use whichever editor you prefer, just remember to insert the three strings at the bottom of the file that is correct for your terminal — I use Zsh, for example. Now you need to download one of the compatible models before starting the program: if you already have one locally, you can skip the next step.

Download GPT-OSS, Qwen3-Coder, or GLM-4.7

I assume you have already installed Ollama for your platform. If you haven’t done so, I recommend using the executable installer that you can find on the official website. Ensure that it’s running and that the installed version is 0.14.0 or later: I’m using version 0.15.0. Then, download the model you prefer.

ollama pull qwen3-coder
Enter fullscreen mode Exit fullscreen mode

Replace qwen3-coder with gpt-oss for the OpenAI model or with glm-4.7-flash: glm-4.7 is only available on the cloud (and therefore requires a paid subscription). Once the download is complete, you can proceed with running Claude Code. It is possible that the first time you run it in a new folder, it will ask for write permission.

ollama launch claude
Enter fullscreen mode Exit fullscreen mode

Alternatively, you can use the claude command directly: if you do not specify one, it will ask you which model to use from those available. I always have at least a couple. I don’t know what it does if there is only one: in theory, it should proceed without further requests. The interesting thing would be to integrate it with an IDE.

Tips and Tricks

The best thing to do is to create a CLAUDE.md file in the root folder of your project. Here you can specify details such as the framework, libraries, and best practices to follow when creating or modifying components. It should automatically recognize certain solutions such as EditorConfig and Prettier.

Running Claude Code in a generic path on your machine is pretty much useless, because the tool needs to access the files it needs to modify. It is not the best tool for starting from scratch: it is useful when starting from an already existing project. I still need to figure out which model is best for JavaScript, Python, and Rust.

As I mentioned, the best idea is to associate Claude Code with an IDE: if you use VS Code, there is an official extension, while for Antigravity I have not yet figured out if it is possible to replace the default agent and, if so, how. Otherwise, you can always open a terminal under the tab and follow the changes live.

If you’d like, follow me on Bluesky and/or GitHub for more contents. I enjoy networking.

Top comments (0)