How to run Claude Code offline with Ollama and Gemma 4 12B

You will point the Claude Code CLI at a local Ollama server instead of Anthropic's servers, so it runs free and offline on your own laptop. It suits developers with a 16 GB RAM machine who want a private coding agent. You need Ollama, a Gemma model and a text editor.

YouTube video: Run Free Claude Code With Ollama Local, Offline Setup

YouTube’s video details do not confirm captions. Check CC in the player for available tracks.

12 chapters. Tap a step to jump to it.Chapters from the creator
Choose a chapter (12)
Video length
33 min 38 s
Time to do it
45 minutes
Difficulty
Medium
Steps
10

What you need

Steps

  1. Install Ollama from the official site, then start it and confirm the server is actually running before you touch Claude Code.

  2. Check the instructions for your exact model before choosing this setting or amount.

  3. Download Gemma 4 12B through Ollama and wait for the pull to finish.

  4. Install the Claude Code CLI and open your config files in a text editor.

  5. Set ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN so Claude Code talks to your local Ollama server instead of Anthropic.

  6. Add the one line to your.claude.json file so onboarding stops blocking the CLI.

  7. Run ollama launch claude and check the status output shows your local model, not a cloud one.

  8. Create a local settings.json inside the single project so the setup does not override your paid Claude Code account everywhere else.

  9. Raise the context window to 192,000 tokens for a safer auto-compaction margin.

  10. Move Ollama's context slider from the 4,096 token default to 64k, or Claude Code will silently drop everything past 4k.

Tips and common mistakes

Ollama defaults to a 4,096 token context while Claude Code assumes 200k, so fix the slider before you trust long outputs.

Keep the setup scoped to one project with a local settings.json so your normal Claude Code account keeps working elsewhere.

Never commit your API keys or leave them on screen, and do not send confidential or client data through a third party model provider.

Questions

Do I need a paid Claude Code plan for this?

No. The setup uses no subscription, no API key and no card on file, and it keeps working with no internet connection.

Why use Gemma 4 12B instead of the bigger models?

Check the instructions for your exact model before choosing this setting or amount. The 26B and 31B builds are too large for that hardware.

Why does Claude Code ignore part of my prompt?

Ollama's default context is 4,096 tokens while Claude Code assumes 200k. Raise the slider to 64k and the context window to 192,000 tokens.

The notes are drafted automatically from video details and general task knowledge. How the guide was prepared

Report a correction

More in Computers & Phones

See all