# Ollama on Windows: install it, download a model and use it with a coding agent

A Bitflow Solutions guide. Web version: https://bitflow-solutions.com/en/guias-tecnicas/ollama-local-models-coding-agent/

## What you’ll learn

- What **Ollama** is and why you would run AI models on your own machine.
- How to install Ollama on Windows and check that it works.
- How to download a model, try it in the terminal and manage the models you have downloaded.
- How to set the context length that coding agents need.
- How to connect an agent (**OpenCode** or **Claude Code**) to your local model.

## Prerequisites

- **Windows 10 22H2** or later (Home or Pro); no administrator rights needed. macOS 14 or later and Linux also work.
- A graphics card helps a lot: **NVIDIA** with driver 551.61 or later, or a compatible **AMD** card. Without one it runs on the processor, more slowly.
- Disk space: around 4 GB for Ollama, plus whatever each model takes (from a few GB to hundreds).
- For the last step, an installed agent: OpenCode or Claude Code (see the basic setup guide for an AI coding agent).

## Step by step

### Install Ollama

```powershell
# Option 1: the Windows installer (OllamaSetup.exe, at https://ollama.com/download)
# Option 2: from PowerShell
irm https://ollama.com/install.ps1 | iex

# Check the version and that the service responds
ollama -v
curl.exe http://localhost:11434
```

```bash
# Linux (and macOS)
curl -fsSL https://ollama.com/install.sh | sh
ollama -v
```

### Download and manage models

```powershell
# Download a model and chat with it in the terminal (leave with /bye)
ollama pull qwen3.5
ollama run qwen3.5

# Manage your models
ollama ls                 # the models you have downloaded
ollama ps                 # the ones loaded right now (and whether they use GPU or CPU)
ollama stop qwen3.5       # unload the model from memory
ollama rm qwen3.5         # delete the model from disk
```

| Model | Tag | Approximate download |
|---|---|---|
| Qwen3.5 | qwen3.5 (9b) | 7 GB |
| Qwen2.5-Coder | qwen2.5-coder:7b / :14b / :32b | 4.7 / 9 / 20 GB |
| Devstral | devstral (24b) | 14 GB |
| gpt-oss | gpt-oss:20b | 14 GB |
| Qwen3-Coder | qwen3-coder (30b) | 19 GB |

### Local API

```powershell
# Ollama's native API (PowerShell adaptation of the curl example in the documentation)
Invoke-RestMethod -Uri http://localhost:11434/api/generate -Method Post -ContentType 'application/json' `
  -Body '{"model":"qwen3.5","prompt":"Write a Python function that adds two numbers","stream":false}'

# OpenAI-compatible API, for tools that already use it:
#   http://localhost:11434/v1/   (they ask for a key, but Ollama ignores it)
```

### Context for agents (OLLAMA_CONTEXT_LENGTH)

1. Quit Ollama from its icon in the taskbar.
2. Search for "environment variables" in Settings and open "Edit environment variables for your account".
3. Create the variable OLLAMA_CONTEXT_LENGTH with the value 64000.
4. Click OK and open Ollama again from the Start menu.

### Connect an agent

```powershell
# Open an agent already connected to Ollama (if you do not give a model, it lets you choose)
ollama launch opencode --model qwen3.5
ollama launch claude --model qwen3.5

# Only configure OpenCode to use Ollama, without opening it
ollama launch opencode --config
```

```powershell
# Claude Code against Ollama, by hand (only for this PowerShell window)
$env:ANTHROPIC_AUTH_TOKEN = "ollama"
$env:ANTHROPIC_API_KEY = ""
$env:ANTHROPIC_BASE_URL = "http://localhost:11434"
claude --model qwen3.5
# Inside Claude Code, /status shows what it is connecting to
```

## Common errors

- **curl.exe http://localhost:11434 does not respond**: Ollama is not running. Open it from the Start menu (its icon should appear in the taskbar) and try again. Check the logs in `%LOCALAPPDATA%\Ollama` (`server.log` and `app.log`).
- **The model is very slow**: Look at `ollama ps`: if the PROCESSOR column shows CPU, or a split between CPU and GPU, the model does not fit in your graphics card’s memory. Use a smaller model or reduce the context. Also check that your NVIDIA driver is 551.61 or later.
- **The agent does not use its tools properly or “forgets” earlier work**: The context is too small. Raise `OLLAMA_CONTEXT_LENGTH` to 64000 or more (step 5) and restart Ollama. A model designed for coding also helps.
- **I changed an environment variable and nothing happened**: Ollama reads its variables when it starts. Quit it from the taskbar icon (closing the window is not enough) and open it again from the Start menu.
- **I am running out of disk space**: Check what you have downloaded with `ollama ls` and delete what you do not use with `ollama rm`. Models are stored in `C:\Users\<user>\.ollama\models`; to store them on another disk, set `OLLAMA_MODELS` as in step 5.
- **It does not download models behind the company proxy**: Set the `HTTPS_PROXY` variable to the proxy address (do not use `HTTP_PROXY`) and restart Ollama.

## Next steps

- Set up the agent, its context and its permissions (see the basic setup guide for an AI coding agent).
- Compare several models from the library on the same task from your project before choosing one.
- Integrate the local API into your applications through the OpenAI compatibility (`http://localhost:11434/v1/`).
- Combine local models for tasks involving sensitive data with cloud models for the most complex ones.
