DEV Community

upendra manike
upendra manike

Posted on

# ๐Ÿš€ Running Claude Code Locally with Ollama (No Token Cost)

Until recently, using Claude for coding workflows meant relying on paid API usage.

Now, thereโ€™s a powerful workaround:

๐Ÿ‘‰ You can run Claude Code against a local Ollama endpoint, using open-source models like qwen2.5:3b.

This enables a fully local AI coding assistant โ€” no per-token billing, and full control over your environment.


โš™๏ธ Setup Guide

1. Install Ollama

brew install ollama
Enter fullscreen mode Exit fullscreen mode

2. Pull a Coding Model

ollama pull qwen2.5:3b
Enter fullscreen mode Exit fullscreen mode

3. Install Claude Code

npm install -g @anthropic-ai/claude-code
Enter fullscreen mode Exit fullscreen mode

4. Configure Local Endpoint

export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_BASE_URL=http://localhost:11434
Enter fullscreen mode Exit fullscreen mode

5. Run Claude Code Locally

claude --model qwen2.5:3b
Enter fullscreen mode Exit fullscreen mode

๐Ÿง  What This Actually Does

Instead of sending requests to Anthropicโ€™s servers, Claude Code:

  • Calls a local API (Ollama)
  • Uses an open-source LLM
  • Executes agentic workflows on your machine

โœจ Benefits

  • No API cost โ†’ completely free usage
  • Privacy-first โ†’ your code never leaves your system
  • Flexible models โ†’ switch between different open-source LLMs
  • Offline capability โ†’ works without internet

โš ๏ธ Limitations

Letโ€™s be honest:

  • Not equivalent to Claude Sonnet/Opus quality
  • Smaller models struggle with complex reasoning
  • Performance depends on your hardware

For example:

  • 3B models โ†’ fast but limited
  • 7Bโ€“13B โ†’ balanced
  • 30B+ โ†’ powerful but slow on laptops

๐Ÿ’ก When to Use This

Best use cases:

  • Local development assistant
  • Code autocomplete / small tasks
  • Privacy-sensitive projects
  • Cost-sensitive workflows

๐Ÿš€ Final Thoughts

This setup represents a shift toward:

Local-first AI development

While cloud models still lead in performance, local setups are becoming increasingly practical for everyday workflows.

And for developers, this means:

๐Ÿ‘‰ More control
๐Ÿ‘‰ Lower cost
๐Ÿ‘‰ Faster experimentation


โญ If you're building with local AI agents, Iโ€™d love to hear your setup.

Top comments (0)