Ollama coding agents on self-hosted models

Coding agents can run against models on your own Ollama server so source code stays on your network. This page covers the launch command, context length needs, model choice for code and the controls that keep code inside your infrastructure.

On this page

What Ollama coding agents on self-hosted models change for your team

A team that wants coding agents such as Claude Code, Codex CLI or OpenCode without sending source code to a hosted model provider can point those agents at a self-hosted Ollama server. The work that decides whether this is safe and useful sits in three places: the server, the model and the network path between them. The agent is the easy part. Ollama is an open source runtime licensed under the MIT license, so the runtime itself carries no per-seat or usage fee on your own hardware, and the Ollama pricing page states that running models on your own hardware is always unlimited. Your team still pays for the hardware, the operations time to keep the server patched and the engineering time to wire each agent up and test it.

Two defaults shape the security design. The local API at localhost:11434 does not require authentication, so any process or user that can reach that port can send requests to the models. Ollama also states that when it runs locally it does not see your prompts or data, and cloud features can be switched off with OLLAMA_NO_CLOUD=1 or the server configuration file. Those statements describe the local runtime, not your network. If you move the bind address with OLLAMA_HOST so that developer laptops or a build server can reach a shared machine, you become responsible for authentication, transport protection and access logging in front of an API that has none. The Ollama FAQ covers the bind address and proxy options, and that is the document to review with your security team before rollout.

Several details must be confirmed before you commit to a design, because this page does not state them as fact. Confirm the exact ollama launch syntax and the flags your Ollama version accepts, since the command is new enough that examples in blogs may differ from your release. For each agent, confirm whether it accepts a custom endpoint, which environment variables or configuration keys set that endpoint and whether it expects an Anthropic-compatible or OpenAI-compatible interface. Confirm the context length each agent needs for multi-file edits and whether your chosen model supports it on your hardware. Ask the vendor or check your own test environment for each item, and record the answers in the scope document so the quote and the acceptance tests use the same assumptions.

How a coding agent on self-hosted models sends requests

The request starts at the agent CLI on a developer workstation and passes through an optional reverse proxy with authentication before reaching Ollama on an internal host. Ollama binds to 127.0.0.1:11434 by default, so the bind address must be changed with OLLAMA_HOST before other machines can reach it. Ollama then runs the model on the GPU using weights from the local model store. Check that OLLAMA_NO_CLOUD=1 is set, since the only path out of the network is the optional cloud branch.

Requests stay inside the network unless a cloud model is selected.

Choosing between Claude Code, Codex CLI and OpenCode

Claude Code is built around Anthropic's Messages API, so the question for a self-hosted setup is whether Ollama's Anthropic-compatible endpoint covers the requests it sends. Point the agent at the local server by setting the base URL environment variable to your Ollama host and port, and set the model name to one the server has pulled. Confirm the exact variable names and any auth token handling against Claude Code's own documentation and the Ollama FAQ, because the supplied facts do not confirm per-agent support.

  • Endpoint wiring: the base URL variable must point at the Ollama server, not at Anthropic's hosted API.
  • API surface: confirm that Ollama's Anthropic-compatible messages endpoint handles the tool calls and streaming that Claude Code uses.
  • Model selection: check that the chosen local model supports tool use well enough for multi-step edits.
  • Credentials: confirm whether a placeholder token is required and that no hosted key leaks into a local session.
  • Test before rollout: run a read-only task, then an edit with tool approval, and confirm no request leaves your network.

Check that the agent's traffic goes only to your server by reviewing network logs during the test.

Ollama settings that shape agent performance and exposure

This table compares the Ollama server settings that decide how coding agents reach the server, how many requests run at once and where models and prompts stay. Read each row against the setup you have: a single developer, a shared team server or a restricted network. The main takeaway is that the defaults suit one person on one machine, and a shared server needs deliberate values before several agents run against it.

SettingFits bestWhat changes when several agents hit one server
OLLAMA_HOSTSingle developer: leave the default 127.0.0.1:11434 so only the local machine reaches the API. Shared team server: bind deliberately and put an authenticating proxy in front. Restricted network: bind only to an approved internal interface.The default bind means remote agents cannot connect at all. Widening it exposes an API that has no built-in authentication, so every agent host needs a controlled path, such as a reverse proxy with access checks.
OLLAMA_NUM_PARALLELSingle developer: the default of 1 parallel request per model is usually enough for one agent session. Shared team server: raise it only after checking memory headroom.Agents issue many sequential and overlapping requests. At the default, concurrent agents queue behind each other, and higher values use more memory per loaded model, so test with your real agent workload.
OLLAMA_MAX_LOADED_MODELSSingle developer: the default is usually sufficient. Shared team server: set it to the number of distinct models your agents need so they are not unloaded and reloaded.Default is 3 times the GPU count, or 3 on CPU. If agents switch between models, each switch can force a reload, which adds latency and competes for the same memory.
OLLAMA_MAX_QUEUESingle developer: the default of 512 queued requests is rarely reached. Shared team server: confirm the value suits how many agents you expect to run at once.The default holds up to 512 queued requests. A queue that fills during a busy period means new agent requests are refused, so agents may fail rather than wait, and you should confirm how your clients handle that.
OLLAMA_MODELSSingle developer: the default folder in your user profile is fine. Shared team server: place models on a volume with planned capacity and backups. Restricted network: store models on approved media.Shared servers hold several large model files, so storage location affects capacity planning, backup scope and who can write new model versions. Confirm the folder permissions on multi-user hosts.
OLLAMA_NO_CLOUDSingle developer: optional. Shared team server and restricted network: set to 1 when source code must not leave the network through cloud features.Every agent on the server shares the same cloud setting. Confirm that the agent clients themselves do not send code to hosted endpoints, since the server setting does not control the client.

Why context length and concurrency decide agent quality

Coding agents send far larger prompts than a chat window ever does. Each turn can carry file contents, tool results, search output, diffs and the full conversation history, so the prompt grows as the session goes on. If the model's context window is smaller than what the agent sends, the server truncates or the agent loses earlier instructions, and the model starts edits from an incomplete picture of the repository. Context length also drives memory use, because the key-value cache grows with it on top of the weights. Before you pick a model or a GPU, confirm the default context length in the Ollama documentation and the model's own card, then size memory for the context your agents will actually use, not for a short chat test. The hardware sizing guidance in the Ollama hardware and GPU sizing hub covers how to work through those figures.

Concurrency is the second constraint, and it is easy to miss in a pilot with one developer. By default Ollama handles one parallel request per model through OLLAMA_NUM_PARALLEL, so when several developers run agent sessions against the same model, the requests line up behind each other. Agent sessions are not short requests. A single agent run can issue many model calls in sequence, so a developer who looks idle may still hold the slot. Requests wait in a queue controlled by OLLAMA_MAX_QUEUE, which has a default of 512 queued requests. A large queue keeps requests from being rejected, but it also means a developer waits longer for each response, and the agent's own timeouts may fire first. Ask the team to measure how many agent sessions will run at peak, and set OLLAMA_NUM_PARALLEL and the queue limit against that number. Raising parallelism also raises memory use, so the setting has to be checked against the context length you chose.

Model choice for code: the four tests to run

A model that answers chat questions well may still fail as a coding agent. The tests below check whether a candidate model can drive the agent, edit your code correctly, use the context it needs and respond fast enough on the hardware you plan to buy or already run.

Tool-calling reliability in the agent

Coding agents call tools to read files, run commands and apply edits, so the model must emit tool calls in the format the agent expects. Run the planned agent (for example Claude Code, Codex CLI or OpenCode) against the candidate model on a few read-only tasks first, then on tasks that write files. Record malformed calls, repeated calls and tasks abandoned midway, because these failures cost more time than slow answers.

Code editing accuracy on your repositories

Public benchmarks do not show how a model handles your framework versions, naming conventions and internal libraries. Pick three or four real tickets from your own repositories, with known correct fixes, and ask the model to make the change. Review each diff for unrelated edits, broken imports and tests it quietly skipped, and keep the notes so you can compare candidates on the same tasks.

Context length the agent actually uses

Agents send large prompts that include file contents, search results and conversation history, and the context length you configure in Ollama sets how much of that the model can see. Check what the agent sends on a realistic task, then confirm the model and your memory budget support that length. If the context is truncated silently, the model will edit code it has only partly read.

Response speed on planned hardware

Agent loops send many requests, so latency compounds across each step of a task. Measure time to first token and total time for one of your real tasks on the exact GPU or CPU that will serve it, not on a developer laptop. Ask whether the model fits in memory without spilling to the CPU, since that change can slow responses sharply.

License terms for each model

The MIT license covers Ollama itself, but each model carries its own license with its own limits on commercial use, redistribution and acceptable use. Read the license file that ships with each model before approving it for developers, and record the version you tested. Have legal or compliance review any model whose terms restrict use in products or by employees in certain sectors.

Setting up coding agents on self-hosted models with ollama launch

This sequence takes a coding agent from a bare host to a verified setup in which the model runs on your own hardware and source code stays on your network. Each step ends with a check you can record, so the result can be reviewed and repeated.

  1. Choose and prepare the host

    The platform team selects the machine that will run Ollama and the agent, then confirms it has the operating system, disk space and GPU or CPU capacity for the model class you plan to use. Record the OS version, Ollama version and hardware in the configuration record before installing anything. Ask your hardware and GPU sizing guidance to confirm VRAM requirements for your chosen model and context length, because these vary by model and are not fixed in this sequence. Done when the host meets the sizing check and the record exists.

  2. Install Ollama and pin the version

    An administrator installs Ollama on the chosen host using the method for your platform (macOS, Windows, Linux or Docker, all supported by the project). Ollama ships frequent releases, including pre-releases, so install a specific tagged version rather than tracking the latest, and write that version into your change record. Check the release notes on the project's GitHub releases page before every upgrade. Done when the version command reports the pinned release.

  3. Set OLLAMA_HOST only if other machines must connect

    By default Ollama listens on 127.0.0.1 port 11434, which is correct for a single developer workstation running the agent locally. Set OLLAMA_HOST only when the agent runs on a different machine or in a container that must reach the server, and then restrict the listening address to the narrowest interface that works. Ollama's local API has no authentication, so any exposed address needs a network control or authenticating proxy in front of it. Done when the server answers from the intended client and not from unintended networks.

  4. Pull the approved model

    Pull the model your security and engineering leads have approved for code work, using its exact name and tag, and record the model digest reported after the pull. Confirm the model's license terms allow your intended internal use, since model licenses vary independently of Ollama's MIT license. Models are stored in the default model directory unless OLLAMA_MODELS points elsewhere, so confirm that location has enough space and is backed up as your policy requires. Done when the model appears in the local model list with the recorded digest.

  5. Disable cloud features if they are not wanted

    If your policy forbids sending prompts or code to any external service, set OLLAMA_NO_CLOUD=1 in the server environment or in the server configuration file, then restart the server. Ollama states that local runs do not expose your prompts or data to it, but turning off cloud features removes the cloud path entirely and makes the policy enforceable. Confirm the setting took effect by checking that cloud-backed models are unavailable. Done when the environment shows the variable and a cloud-model request fails as expected.

  6. Launch the coding agent through ollama launch

    Run the ollama launch command for your chosen agent, such as Claude Code, Codex CLI or OpenCode, pointing it at the approved local model. The exact command syntax and supported agent names change between releases, so confirm them against the current Ollama documentation and the release notes for the version you pinned before writing it into a runbook. Keep the command in version control so each launch is reproducible. Done when the agent starts and reports the local model as its backend.

  7. Verify the server and the agent on a test repository

    Check that the server answers on port 11434 with a simple request to the local API, confirming the model responds. Then point the agent at a disposable test repository, not production source, and ask it to make a small, specific edit such as renaming a function or adding a comment. Review the diff and confirm the change landed only in the test repository, then check network logs or firewall counters to confirm no unexpected outbound traffic. Done when the edit is correct, the server responds and the traffic check is clean.

  8. Record the tested configuration

    Write down the Ollama version, model name and digest, environment variables, agent name and version, launch command and the results of each check, then store the record with your platform documentation. Repeat the verification after any Ollama or model upgrade, because release changes can alter behavior, syntax or defaults. Ask your security team to review the record against your source code handling policy before developers use the setup on real repositories. Done when the record is approved and linked from your runbook.

Keeping source code on your network

A local model keeps prompts and code on the server your team controls, while a cloud model sends each request out to ollama.com. The difference is set by the model you select and the endpoint the agent calls, not by the agent brand. When an agent such as Claude Code, Codex CLI or OpenCode points at a local Ollama model, the prompts, file excerpts and tool results it sends go to your Ollama server. Ollama states that when it runs locally it does not see your prompts or data, and cloud features can be switched off with OLLAMA_NO_CLOUD=1 or in the server configuration file. Direct cloud inference at ollama.com/api and ollama.com/v1 is different: it requires an API key sent as a Bearer token, and that traffic leaves your network. Before rollout, confirm which model names resolve to local weights and which to cloud, and block outbound access to ollama.com from developer machines if cloud models are not approved.

The local Ollama API on port 11434 has no built-in authentication, and it binds to 127.0.0.1 by default. Once you set OLLAMA_HOST so that developers on other machines can reach a shared server, anyone who can reach that port can send prompts and read responses. Put an authenticating reverse proxy in front of it, such as the Nginx setup described in the Ollama FAQ, and restrict the listener to the proxy and the internal network. Developer laptops should reach the proxy over TLS with per-user credentials, and the proxy should be the only path to port 11434. Treat this as a decision to make before the first developer connects, because an open endpoint on a shared network is a source code exposure risk in its own right.

Ollama's behavior and the agent's behavior are separate, and only the agent's documentation tells you what else it sends. Some coding agents perform their own telemetry, error reporting, update checks or plugin downloads, and those calls are not controlled by Ollama settings. For each agent you plan to use, read its documentation and confirm every outbound network call, including any that occur when a non-default endpoint is configured. Then test it: run the agent against your server with a network monitor or egress logs enabled, and record which hosts it contacts. Pin the agent version you tested, because network behavior can change between releases, and repeat the check when you upgrade either the agent or Ollama.

Limits to confirm in your environment before rollout

Coding agents depend on three moving parts: the agent client, the model and the Ollama server that sits between them. Each one can limit what works, so confirm the points below in a test environment before developers start relying on the setup.

Agent version support for Ollama

Not every release of Claude Code, Codex CLI or OpenCode accepts a custom Ollama endpoint or the same environment variables. Pin the agent version you test and confirm with the agent vendor which versions accept a local Ollama endpoint and how the endpoint is configured. Record the result against the exact client version your developers will install, because a silent client update can change the behavior.

Ollama API docs

Tool call support in the chosen model

A coding agent only works well when the model can return structured tool calls for reading files, editing code and running commands. Whether a given model supports this depends on the model itself, not on Ollama alone. Test each candidate model with the agent's real tool workflow, and confirm the tool calling support in the model's own documentation before you standardize on it.

Concurrency on a shared server

Several developers running agents at once share the queue settings on one server. Ollama's defaults allow 1 parallel request per model and a queue of 512 requests, so agent sessions may wait on each other. Load test with the number of concurrent sessions you expect, and tune OLLAMA_NUM_PARALLEL and OLLAMA_MAX_QUEUE against your GPU memory before you promise response times.

Reverse proxy timeouts for long generations

Agent turns can run for minutes while a model generates code, and a reverse proxy in front of Ollama may close idle connections first. Check the read and send timeouts, buffering and streaming settings in your proxy, then confirm that a long generation completes end to end. Your network team should own this check, since the defaults in common proxies are often shorter than an agent turn.

Ollama FAQ

Testing Ollama release changes

Ollama ships frequent releases, and a server upgrade can change model loading, API behavior or default settings that an agent depends on. Keep a staging server, run a fixed set of agent tasks against each candidate release, and compare results before you upgrade production. Review the release notes on the GitHub releases page and treat pre-releases as test-only builds.

Ollama releases

Agent features unavailable with local models

Some agent features depend on a vendor's hosted service, such as built-in web search, cloud-hosted tools or account-linked settings, and may not work when the model runs locally. Ask each agent vendor which features require their cloud service, and list the ones your teams use. Decide in advance how developers should work around any gaps, and document the decision in your rollout guide.

Can coding agents on self-hosted models be set up without outside help?

Can our team set up coding agents on self-hosted models without an outside partner?

Yes, a capable platform or infrastructure team can do it alone, provided it has someone who can run a shared server, manage model storage and put access controls in front of an API that has no built-in authentication. The Ollama runtime is open source under the MIT license, and running models on your own hardware has no per-token fee from Ollama. The harder part is not installation. It is agreeing on which models your developers use, how the server is exposed, how each agent is configured and how the setup is tested before developers depend on it. Teams with little time for that second group of tasks are the ones that usually ask for help.

What does the work cost, and who gets paid for what?

Costs come from four sources: your own staff time, hardware or cloud capacity for the model server, any licenses for the agent tools themselves, and fees for an implementation partner if you hire one. Ollama does not charge per token for models you run on your own hardware. Its pricing page lists paid plans for cloud models, such as Pro at $20 per month ($200 per year), Max at $100 per month, Team at $500 per month and Enterprise at custom pricing, so cloud model use is a separate, recurring cost. A partner's fee is set by a written scope, not by a list price. Ask each vendor for its own current terms, because agent tool licensing changes independently of Ollama.

Which parts of the setup are one-time, and which recur?

The one-time work covers building the host, selecting and loading models, configuring the proxy and access layer, and testing each coding agent against the server. These steps are heavier at the start and then mostly settle. The recurring work is ongoing: updating or replacing models as better code models appear, upgrading Ollama when releases ship, reviewing new versions of each agent because their configuration options and network behavior can change, and checking logs for overload or unexpected traffic. Budget for the recurring work as a standing responsibility with a named owner, not as a project that ends at go-live.

What makes the effort grow or shrink?

Four factors move the effort most:

  • Number of developers: more concurrent users need more capacity and tuning of parallel request settings.
  • Hardware: the GPU memory available determines which models and context lengths are practical, so hardware decisions come early.
  • Authentication and SSO: the local Ollama API has no authentication, so putting identity and access control in front of it adds real design and testing work.
  • Repository access: deciding which source code agents can read, write and send to the model server changes both the configuration and the review process.

Smaller teams with one shared server, existing identity services and clear repository boundaries have far less to build.

How long does a pilot take?

A pilot's length depends on how many agents you test, how many models you compare, whether you need SSO in front of the server and how much of the environment is already in place. Teams with an existing server, identity provider and approved hardware can run a narrow pilot with one agent and a small group of developers much faster than teams building the platform from nothing. Ask any partner to state the duration in the written scope, with the entry conditions it assumes, such as access to hardware, accounts and a named contact on your side. Agree on the exit criteria before the pilot starts so that success is measurable.

What should we ask a partner to include in a written quote?

A useful quote lists the scope in specific terms. Ask for the following:

  • The agents, Ollama version and models in scope, with the reason each model was chosen for code work.
  • How the server is exposed, the authentication method, and which SSO or access controls are included.
  • The hardware and environment assumptions, and who provides them.
  • Testing covered for each agent, including what is checked for source code leaving your network.
  • Deliverables such as configuration documentation, runbooks and a handover session.
  • Which recurring support is priced separately, and how model and Ollama upgrades are handled.

Also ask what is excluded, because gaps in the exclusions usually cause the surprises.

Does keeping source code on our network require outside help?

Not necessarily, but it does require deliberate configuration and verification. Ollama states that when it runs locally it does not see your prompts or data, and cloud features can be turned off with the OLLAMA_NO_CLOUD=1 setting or the server configuration file. Your own team should confirm that agents are pointed at the local server, that cloud features are disabled and that the server is not reachable from outside your network. If your team lacks someone to check these settings and the agents' own telemetry behavior, an independent review can help, and DeployOpen's security testing covers this type of setup. Confirm each agent's data handling terms with its vendor, since those are outside Ollama's control.

How DeployOpen scopes and supports self-hosted coding agents

DeployOpen plans and deploys self-hosted coding agents against an Ollama server inside your own infrastructure, so model access, source code and developer tooling stay on your network. The work starts with a written scope that names the agents, models, hardware and network controls involved, then moves through build, testing, documentation and handover.

How we scope

  • Inventory which coding agents, IDEs and terminals developers will use, and confirm each agent's Ollama launch path.
  • Agree the context length target per workload, since agent sessions with large repositories need more memory than chat.
  • Define which model families are approved for code, with licenses reviewed and weights sourced from an approved location.
  • Fix the written scope, deliverables and timeline before work begins, as most engagements are fixed-scope.

How we build

  • Set the Ollama bind address, OLLAMA_NO_CLOUD and model storage path so the server only accepts traffic from your developer network.
  • Place an authenticated reverse proxy in front of the local API, since the local API does not require authentication.
  • Size GPU memory and concurrency settings against the agreed models and expected number of simultaneous developer sessions.
  • Test each agent against the deployed server, checking tool calls, file access limits and that no source code leaves the network.

How we hand over

  • Document the launch commands, environment variables, approved models and the configuration of each developer workstation.
  • Provide a runbook covering model updates, version pinning and the process for testing new Ollama releases before rollout.
  • Deliver the security test findings and fixes, with a retest so your security team sees the final state.
  • Walk your platform and security teams through the setup so they can review and operate it after handover.

How we support

  • Ongoing support, upgrades and continuous testing are available as a retainer, scoped in writing.
  • Retainers can cover Ollama version upgrades, model additions and periodic checks of network exposure and proxy settings.
  • Ask any provider to confirm who handles model license reviews, patch timing and incident response before signing.
  • Ask for the quote to list each recurring component separately, so your team can see what changes when scope grows.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.