Private AI

Local Coding Agent with Ollama: Setup for Six Agents

Checked 2026-10-31

Loading poll...

Install Ollama, pull a tool-capable model, set the context window to 64k, then launch your agent. For Claude Code, Codex or OpenCode the command is ollama launch <agent>. Cline, Aider and Goose take a provider setting instead. Your code stays on your machine when the model is local. We checked each agent's setup against Ollama's docs on 31 October 2026.

The six setups at a glance

Agent

How to point it at Ollama

Context advice from the docs

Claude Code

ollama launch claude, or set ANTHROPIC_BASE_URL=http://localhost:11434

64k or higher

Codex CLI

ollama launch codex, or codex --oss

At least 64k

OpenCode

ollama launch opencode, or an opencode.json provider

64k or higher required

Cline

Settings, API Provider, Ollama

At least 32K

Aider

OLLAMA_API_BASE and aider --model ollama_chat/<model>

Aider sets it for you; see below

Goose

goose configure, pick Ollama

Not stated on the page we read

Agent profiles on this site: Claude Code, OpenAI Codex CLI, OpenCode, Cline, Aider and Goose.

Step 0: the model and the machine

A coding agent does more than chat. It reads files, runs commands and calls tools, so the model must support tool calling. Ollama's library lets you filter for models with tools. Two that fit a single consumer GPU, with sizes from their library pages:

Model

Size

Context

Note

gpt-oss 20B

14 GB

128K

Apache 2.0; 16 GB of memory is enough per the page

Qwen3-Coder 30B

19 GB

256K

Described by the publisher as built for agentic and coding tasks

Both leave room for a 64k context on a 24 GB card, roughly: weights plus about a quarter for cache. Check with ollama ps after the first long task. For larger models, see GPU requirements for LLMs.

Set the context before you launch, because the default depends on VRAM and is only 4k below 24 GiB:

OLLAMA_CONTEXT_LENGTH=65536 ollama serve

Pull the model first so the launcher can find it:

ollama pull qwen3-coder:30b

Claude Code

The quick route:

ollama launch claude

Ollama offers to install Claude Code if it is missing and lets you choose a model. The docs list what carries over: chat, command-line use with Claude Code's permission flow, tool calling with compatible models, file edits, subagents, web search and fetch through Ollama, vision and thinking controls. The manual route sets three variables:

export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL=http://localhost:11434
claude --model qwen3-coder:30b

For scripts and CI, ollama launch claude --model <model> --yes -- -p "how does this repository work?" skips the selectors. The --yes flag pulls the model if needed and requires --model. Which Claude Code features degrade on non-Anthropic models is not documented on the page we read.

Codex CLI

Install Codex with npm install -g @openai/codex, then:

ollama launch codex

Ollama refreshes the model catalog and uses a dedicated Codex profile for the session. Inside Codex, /model switches between installed tool-capable Ollama models. Without the launcher:

codex --oss -m gpt-oss:120b

A persistent profile goes in ~/.codex/ollama-launch.config.toml:

model = "gpt-oss:120b"
model_provider = "ollama-launch"

[model_providers.ollama-launch]
name = "Ollama"
base_url = "http://localhost:11434/v1/"
wire_api = "responses"

Run it with codex --profile ollama-launch. Note a data point: Codex web-search requests through this profile are executed by Ollama, and you need ollama signin to use them. If you want strictly local, disable it with codex --profile ollama-launch -c 'web_search="disabled"'.

OpenCode

ollama launch opencode

OpenCode needs a context length of 64k or higher. The manual route adds a provider to opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ollama": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Ollama",
      "options": { "baseURL": "http://localhost:11434/v1" },
      "models": { "qwen3-coder:30b": { "name": "qwen3-coder:30b" } }
    }
  }
}

The launcher does not overwrite ~/.config/opencode/opencode.json, and models defined only in that file do not show up in the launcher's picker.

Cline

Cline works inside an editor. In Cline's settings, open API Configuration, set the provider to Ollama, choose or type the model, and set the context window to at least 32K. The Ollama docs also describe a route to cloud models through an API key and the base URL https://ollama.com. That sends prompts to Ollama, so skip it if the point is to stay local.

Aider

Aider documents its own setup:

export OLLAMA_API_BASE=http://127.0.0.1:11434
ollama pull qwen3-coder:30b
aider --model ollama_chat/qwen3-coder:30b

Aider recommends the ollama_chat/ prefix over ollama/. Its docs give a warning worth repeating: Ollama's older 2k default context is very small, and Ollama silently discards context that exceeds the window. By default Aider sizes the window to the request plus 8k tokens for the reply. For a fixed size, a .aider.model.settings.yml file can set num_ctx.

Goose

Run goose configure, choose Configure Providers, select Ollama and enter a model name. In Goose Desktop, open Settings, Configure Provider, pick Ollama and confirm the API host is http://localhost:11434.

Which one to start with

If you want

Start with

The least setup

ollama launch claude or ollama launch opencode

An open-source terminal agent

OpenCode

Work inside VS Code or JetBrains

Cline, or the editor integrations on Ollama's list

Git-centred edits with small diffs

Aider

An OpenAI-style agent with a profile file

Codex CLI

For how these agents compare as products, see AI coding agents and Aider vs Claude Code.

How good will it be

We have not benchmarked local models against hosted ones, and the pages we read make no such comparison. What we can say from the docs is what the setup costs you: a long context window uses memory, and a smaller model has less capacity than a frontier model on tasks with many steps. In practice teams use local models for private repositories, offline work and low-stakes edits, and a hosted model for hard problems.

If your hardware cannot hold a good model, there are two ways forward: rent a GPU and point the agent at it, or use a hosted open-model API. The first is covered in self-hosted AI coding assistant. For price comparisons, see our hosting hub.

Why context length is the make-or-break setting

An agent builds its prompt from your request, the system instructions, the files it has read, tool results and its own earlier steps. That adds up fast. A single medium source file can take several thousand tokens, and a test run can add thousands more. At a 4k window the agent is blind after one or two steps. Ollama's own context-length page sets defaults by memory for this reason, and its integration pages ask for 64k or more.

Two failure modes follow, and they look different.

Silent truncation. Aider's docs warn that Ollama silently discards context beyond the window. The agent does not error. It just stops seeing the start of the conversation and begins to repeat itself or contradict earlier edits. If an agent seems to get dumber as a session lengthens, check the window first.

Memory spill. Raising the context raises the cache. When weights plus cache exceed VRAM, Ollama splits the model across GPU and CPU, and each step slows down. In an agent loop, which makes dozens of calls per task, a slowdown from spill multiplies. Run ollama ps while the agent is working and look at the processor column.

The way to find your limit is to raise the context in steps, 32k, 48k, 64k, and run the same task each time. Stop when ollama ps shows a CPU share or the speed drops sharply, then back off one step.

Permissions and safety on a local model

A local model does not make an agent safe. The agent still runs commands and edits files with your account's rights. Claude Code's permission flow carries over when you launch it through Ollama, per the integration page, so you still approve commands. Keep that on. The other agents have their own approval modes, and defaults differ.

Good habits that apply to all of them:

  1. Work in a git branch so any edit can be reverted.
  2. Run the agent in a container or a throwaway checkout when the task involves untrusted code.
  3. Keep secrets out of the working directory. A local model cannot leak them to a vendor, but an agent can still write them into a file or a log.
  4. Review the diff before you commit, whatever model wrote it.

Using a remote GPU for the agent

If your laptop cannot hold a good model, the agent does not care where the model lives. Everything above works against any base URL. Rent a GPU, run Ollama or vLLM on it, and point the agent at that address through a tunnel or a proxy with authentication. Prices checked on 31 October 2026:

Option

GPU

Price per hour

Holds

Runpod Community

RTX 4090, 24 GB

$0.34

gpt-oss 20B, Qwen3-Coder 30B with tight context

Runpod Secure

L40S, 48 GB

$1.09

Qwen3-Coder 30B with long context

Runpod Secure

A100, 80 GB

$1.79

gpt-oss 120B (65 GB listed)

Lambda

1x H100 SXM, 80 GB

$4.29

The same, faster

An example with figures we chose: a developer uses an L40S for 4 hours a day over 20 working days. That is 80 hours at $1.09, about $87 a month. A 24 GB RTX 4090 on the Community tier for the same hours is about $27. Compare that to what you now spend on a hosted coding subscription before deciding. Some links go through /go/ and may earn us a fee; it never changes our order. See Runpod, Lambda Cloud and the hosting compare.

The privacy picture changes here. A rented machine belongs to someone else, even if you control the software. Check the host's data terms and choose a secure tier if the code is sensitive. A fixed home or office machine stays the strongest option for private code.

Sharing one model across a team

Once several developers want the same endpoint, set it up as a service. The pieces:

  • A shared box. One GPU server runs the model, ideally with vLLM if more than a few people use it at once. See vLLM.
  • A proxy. Nginx or similar terminates TLS and checks credentials. Ollama has no login of its own. vLLM can check a key with --api-key.
  • A common config. Put the base URL and model name into each agent's config through a shared dotfile or a team setup script, so everyone gets the same behaviour.
  • A pinned model. Everyone should use the same model tag, so that results can be compared and bugs reproduced.
  • A fallback. Decide what happens when the box is down.

The longer team design is in private AI for teams, and the broader assistant discussion is in self-hosted AI coding assistant.

A realistic first day

  1. Morning. Install Ollama. Pull gpt-oss 20B or Qwen3-Coder 30B, whichever fits. Set the context to 32k to start.
  2. Smoke test. Run ollama launch opencode or ollama launch claude in a small repository. Ask it to explain the project. Watch ollama ps.
  3. Raise the window. Move to 64k. Repeat the same question and check speed.
  4. Real task. Pick a small bug or a test to write. Let the agent try. Review the diff.
  5. Afternoon. Try the same task with a hosted model if you have access, and note the difference in quality and time. That comparison is the one that matters, and it is yours to make.
  6. End of day. Decide: keep local for private work, or look at a rented GPU for a bigger model.

Privacy notes

  • Model traffic. With a local model, prompts and files go to localhost:11434 and nowhere else.
  • Extras. Web search and web fetch features run through Ollama, which is an outside service. Turn them off if you need strict locality.
  • Cloud models. Ollama's :cloud tags run on its servers. Ollama says it does not store or log that content and never trains on it. Still, that is not local.
  • The agent's own telemetry. Each agent has its own settings for usage reporting, separate from Ollama.

Troubleshooting

Symptom

Cause

Fix

Agent forgets earlier files

Context too small

Set OLLAMA_CONTEXT_LENGTH=65536 and restart

Very slow after raising context

Model spilled to CPU

ollama ps; use a smaller model

Tool calls fail or loop

Model lacks tool support

Choose a model from Ollama's tools filter

Launcher cannot find a model

Not pulled

ollama pull <model> first

Connection refused

Server not running or wrong host

Start ollama serve; check the base URL

Our take

Ollama's launchers make the first run easy, and the documentation across agents is consistent about the one setting that matters: give the model at least 64k of context. Do that and match model size to your memory. For a developer with a 24 GB GPU or a 32 GB Mac, a 20B to 30B model is a reasonable private assistant. It is not a replacement for a frontier model on hard work. Treat it as a private first pass. This conclusion comes from vendor docs and not from a test we ran.

Related pages

Questions

Which coding agents work with Ollama?

Ollama's docs list Claude Code, Codex CLI, OpenCode, Cline, Goose, Roo Code and others, plus VS Code, JetBrains, Zed and Xcode. Aider documents its own Ollama setup.

What context length should I use?

Ollama says at least 64k tokens for Claude Code, Codex and OpenCode, and at least 32K for Cline. Aider warns that Ollama's old 2k default silently drops context.

Which local model is best for coding?

We make no ranking claim. Qwen3-Coder 30B (19 GB) and gpt-oss 20B (14 GB) are two listed on Ollama that fit a single consumer GPU. Test on your own code.

Is the code sent anywhere?

With a local model, prompts stay on your machine. Web search and cloud models are separate features that do send data to Ollama.

Loading poll...

Sources

  1. docs.ollama.com/quickstart
  2. docs.ollama.com/integrations/claude-code
  3. docs.ollama.com/integrations/codex
  4. docs.ollama.com/integrations/opencode
  5. docs.ollama.com/integrations/cline
  6. docs.ollama.com/integrations/goose
  7. docs.ollama.com/context-length
  8. aider.chat/docs/llms/ollama.html
  9. ollama.com/library/qwen3-coder
  10. ollama.com/library/gpt-oss

Part of the Wbcom Designs family

The all-in-one WordPress community stack

Also ours: wbcomdesigns.comvapvarun.combrndle.com