Why Run Claude Code with Local Models?
Hello everyone. My name's Abhishek and welcome back to my channel. In today's video, let's learn how to run Claude code with local models for absolutely zero cost.
So basically we'll install Claude code, then we will learn how to integrate it with Ollama, which is serving the models locally. And we will do this entire thing in three simple steps in the video. Now you might ask, but Abhishek, why is this important?
This is very, very important for two major reasons. Number one, this setup is absolutely secure because the models are running locally on your machine. If you're working on your office related work or maybe you're building a secure application, you don't have to worry about it.
Number two, cost-effectiveness. Again, because the models are running locally on your machine, you don't need Anthropic API keys, so you don't have to pay for the API usage. But can you really build something with the local models? Are they really efficient? Definitely yes.
If you look at the advancement of local models, for example, the open-source models like GPT-OSS 20 billion parameters or the recent Twin Coder 3 model, they are very, very powerful. In fact, you can achieve most of your tasks with these models.
So that's why you should definitely try this setup on your machine. So without wasting any time, let's get started with the video.
Step 1: Install and Verify Ollama
The configuration is going to be very simple, but just to make it even more easy for you, I created this GitHub gist file.
I'll share the link to this MD file in the description so that after watching the video, if you need any comment, you can copy it from the MD file. Perfect. So the first step is to install Ollama.
You can just head to ollama.com and copy-paste this curl command. The curl command is also in our MD file. Now, this will work on your Windows, Linux, or Mac OS. If you want even more easy way, just click on download Ollama.
I already have Ollama running on my machine. How do you verify that? You can just run Ollama --version. Perfect.
Step 2: Choose and Download a Local LLM
Next step, choose the model. Now, this is important part. If you want to really work using the local LLM models, that is if you want to really set up some projects, if you want to work on your sidekick project, you need a powerful local large language model. What I would recommend is to go with, you know, if I do Ollama LS, this is something that I am using. This is GPT-OSS, 20 billion parameters.
If you want even powerful one, you can go with when coder 3 model. Or if you want a lightweight model, like little lightweight when compared to this, you can go with GLM 4.7 flash model. These are the only three things that I would recommend. Perfect. So, you need to run Ollama pull followed by the model that you're looking for.
This will take time. It can take up to 20 to 30 minutes as well, depending upon your internet speed. Because the GPT-OSS model is 13 GB in size.
Crucial Configuration: Adjusting Context Length
Now, once you're done with this, there is a very, very important step that you have to perform. Lot of times, people miss this step, and they think that Claude code or open Claude is not good with the local models.
The step is you have to head to your Ollama. So, this is my Ollama widget. I have opened the settings. So, once you install Ollama, you will have the widget. Go to the settings, and here, if you scroll down, you will find context length parameter. This is very, very important because context length determines how much your conversation local large language models can remember and generate the response for you.
Let's say you ask it to read a GitHub repository. So, you clone a GitHub repo and you want it to read the complete repository and maybe create a pull request for you making some changes. It's very large context. So, you need to provide your local model or Ollama with that context length. I would recommend go up to 16K or 32K as well. If you have a very powerful local machine with multiple GPUs, you can go up to 128K as well. But at least for my use cases, 32K is good enough.
Perfect.
Step 3: Install Claude Code and Generate a Project
So, now the final step, you have to install Claude and then you have to invoke the local model using Claude and Ollama. This is the command to install Claude code. Again, a very simple curl command and the setup will be done in next 2 to 3 minutes for you.
I also have Claude running. So, I'll go with the final step. This is the most important one.
Ollama launch Claude --model whichever model you want to run. In my case, I want to run GPT OSS 20 billion parameters. So, it says, is this the folder where you want to start Claude? Yes.
Now, I'm in this folder. I'll show you. I'll ask Claude, can you create a simple to-do Go lang project or simple to-do application in Go lang. Okay, let's see. It should create the entire project for us. You can see it is thinking and it also started using I mean it is basically using the tokens, but these are not the API tokens. You'll not be charged by Anthropic because you are using the local models. There you go. So it said this is going to be a main.go. Do you want me to create? We are done. So you can see here cooked for 1 minute 26 seconds. So within 1 minute 26 seconds, it set up the entire project for us.
This is a very simple application and I'm also using my secondary machine. I have a different machine which is more powerful. If I do the same thing on that machine, this should be executed in less than 30 seconds. I'll quickly show you the files here.
And these are all the files that are created. And if I do go run main.go, you can see the to-do application CLI started.
Analyzing Existing Code and Final Thoughts
Not only this, I can switch to an existing application. So I have an existing Python-based application. This is a little more powerful application with database and the front-end user interface. Now I'll ask Claude Code, I switch to the folder. I'll ask Claude Code to explain me the project. Explain this project in simple words.
There you go. So this time it only took I think less than 30 seconds. It explains the entire project. Typically it went through the readme file and it says this is a lightweight application where you have SQLite. These are the dependencies and application is running on port 5002. It also explained steps to run the application locally.
You can also use it for your DevOps and cloud-related tasks, but you have to understand when it comes to DevOps and cloud, you should expect little less accuracy when compared to the coding related tasks. Anyways, this is something that everyone should set up because going ahead, local large language models are going to be the future. It can be for security or it can be for cost-effectiveness.
And make sure you share this video with your network so that they can also have the similar setup. If you have any questions related to this topic, please let me know in the comment section. See you all in the next video. Take care.