Deploy OpenCode Ollama

Run the OpenCode agent on open models served by Ollama

Deploy OpenCode Ollama

Just deployed

/data

Deploy and Host self hosted OpenCode Ollama (Open-Source AI Coding Agent on Open Models) on Railway

This template runs the OpenCode agent as a self-hosted server on Railway and wires it to models served by Ollama, either a CPU-only Ollama service in the same project or Ollama Cloud.

About Hosting OpenCode Ollama open-source software on Railway (self hosted OpenCode with Ollama template)

This template runs one service: the OpenCode server image with its embedded web UI on port 4096, a volume at /data, and basic auth with a generated password. Ollama is not included.

Why Deploy OpenCode Ollama, the Claude Code alternative on Railway (Railway Free Trial)

Claude Code bills per token through Anthropic. The $5 trial covers setup, so you can measure how slow CPU inference really is before committing.

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying OpenCode Ollama on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.

Railway vs Other Hosting Providers and VPS for OpenCode Ollama self hosting

Railway ships OpenCode with a domain, volume and private networking; a VPS gives you a blank machine.

ProviderWhat You Get with RailwayWhat You Get with the Other Provider
DigitalOceanTemplate deploy, HTTPS domain, /data volume, private Ollama addressBlank Droplet: install Docker, Ollama, OpenCode, TLS and auth
AWSSame template, managed restarts, Ollama on the private networkEC2 plus security groups, EBS, reverse proxy, separate Ollama setup
HetznerTemplate and persistent volume, no OS patching, dashboard logsBare server: you own updates, firewall and Ollama tuning

Common Use Cases for hosted OpenCode Ollama

  • Keep code off third-party model APIs: point the provider at your own Ollama service so prompts, diffs, and repo context stay on infrastructure you control instead of going to Anthropic or OpenAI.
  • Try open coding models like Qwen coder variants: pull a Qwen coder model that advertises the tools capability and let the agent read files, run tests, and patch code without paying per token.
  • Run Ollama Cloud models without a GPU: if CPU inference on Railway feels too slow, switch baseURL to https://ollama.com/v1 with an API key and keep the same opencode.json shape.
  • Pair a cheap local model with a strong hosted one: use a small Ollama model for quick edits and renames, and keep a hosted provider configured for the hard refactors when quality matters more than cost.
  • Get offline-style privacy for a client codebase: contract work with strict data rules fits a self-hosted Ollama behind basic auth, where the only traffic leaving Railway is the model pull itself.

Dependencies for OpenCode Ollama Docker hosted on Railway

This template ships one service, and it isn't the one doing inference. Ollama is added separately in the same project.

Deployment Dependencies for Managed OpenCode Ollama Service (AI Coding Agent)

Set OPENCODE_SERVER_PASSWORD (generated, 32 chars; the entrypoint refuses to start if empty), OPENCODE_SERVER_USERNAME=opencode, OPENCODE_HOSTNAME=0.0.0.0, OPENCODE_WORKSPACE=/data/workspace, HOME=/data/home, PORT=4096, RAILWAY_DEPLOYMENT_DRAINING_SECONDS=30.

Add ollama/ollama yourself: port 11434, volume at /root/.ollama, OLLAMA_HOST=[::]:11434 for the IPv6 private network. No GPUs on Railway, so inference is CPU-only.

Implementation Details for OpenCode Ollama (Using OpenCode official docker image)

The entrypoint runs opencode serve --hostname 0.0.0.0 --port 4096 with tini as PID 1, serving the API and web UI. Health checks hit /site.webmanifest, the only path without auth.

How does OpenCode Ollama compare against other ways to run a coding agent on open models

OpenCode vs Claude Code (Claude Code Alternative)

  • Model freedom: It talks to Ollama through an OpenAI-compatible provider, so you can swap to Qwen coder or a hosted key without changing clients.
  • Surface: One server gives you the web UI, API, sessions and MCP; Claude Code is a terminal agent tied to Anthropic.
  • Claude Code wins on: default tool-calling reliability and zero Ollama tuning. Expect worse results from small CPU models.

OpenCode vs Aider (Aider Alternative)

  • Interface: Aider is a git-native terminal pair programmer with Ollama support; OpenCode adds a persistent web UI and multiple sessions.
  • Setup: Both want an OpenAI-compatible endpoint; OpenCode keeps providers in opencode.json on the volume.
  • Aider wins on: a lighter footprint, no server password, and fast one-command edits in a shell.

OpenCode vs Cline (Cline Alternative)

  • Where it runs: Cline is a VS Code extension on your laptop; OpenCode runs on Railway with workspace and model config on a volume.
  • Networking: Cline reaches localhost Ollama; OpenCode uses ollama.railway.internal:11434/v1 on the private network.
  • Cline wins on: native diff review and a GPU laptop that beats Railway CPU inference.

OpenCode vs Continue (Continue Alternative)

  • Scope: Continue handles inline completion and chat in the IDE; OpenCode is an agent with plan/build modes, commands and MCP.
  • Config: Both take custom OpenAI-compatible providers; OpenCode merges global and project opencode.json.
  • Continue wins on: autocomplete where you type, less setup, and no server to patch.

How to use OpenCode Ollama (the OSS AI coding agent)?

  1. Add an Ollama service (image ollama/ollama, port 11434, volume /root/.ollama, OLLAMA_HOST=[::]:11434) and pull a tool-capable model like qwen2.5-coder:7b.
  2. Raise context: Ollama's default num_ctx is small, so set OLLAMA_CONTEXT_LENGTH=32768 or build a Modelfile with PARAMETER num_ctx 32768.
  3. In a Railway shell on the opencode service, write the provider block into /data/home/.config/opencode/opencode.json:
{"provider":{"ollama":{"npm":"@ai-sdk/openai-compatible","name":"Ollama","options":{"baseURL":"http://ollama.railway.internal:11434/v1"},"models":{"qwen2.5-coder:7b":{"name":"Qwen 7B"}}}}}
  1. Restart OpenCode, select ollama/qwen2.5-coder:7b in the UI, then run a small task. Expect slow CPU responses.

How to self host OpenCode Ollama on other VPS Services (OpenCode self hosting guide)

Clone the Repository

You do not need to clone OpenCode to run it, but grab your project repo so the agent has something to work on.

git clone https://github.com/your-user/your-repo.git
cd your-repo

Install Dependencies

Install OpenCode, then install Ollama and pull a model that supports tool calling.

curl -fsSL https://opencode.ai/install | bash
curl -fsSL https://ollama.com/install.sh | sh
ollama pull qwen2.5-coder:7b

Configure Environment Variables

Set the server password, listen address, and Ollama context size, then point OpenCode at the local Ollama endpoint in opencode.json.

export OPENCODE_SERVER_PASSWORD=your-password
export OLLAMA_CONTEXT_LENGTH=32768

Start the OpenCode Ollama Application

Start Ollama, then start the OpenCode server, and open your domain behind HTTPS.

ollama serve
opencode serve --hostname 0.0.0.0 --port 4096

On Railway the same image, volume, generated password, and Ollama service wiring are already in place, so you only add the provider block.

Official Pricing of OpenCode Ollama (OpenCode pricing)

OpenCode is free and open source under MIT, and Ollama is free to run yourself, so the software costs nothing. Adding the Ollama service adds a RAM-hungry container to the bill, since a 7B model needs several GB of memory.

OpenCode Ollama cloud vs self hosted comparison (Pricing, features, costs, and more)

Two ways to run open models: Ollama Cloud through ollama.com with an API key, or an Ollama service in the same project. Cloud is bigger and faster; self hosted keeps code on the private network but runs CPU-only.

Monthly cost of self hosting OpenCode Ollama on Railway

The OpenCode container costs about $5-15/mo at light use on Railway; the Ollama service usually costs more than that because model RAM is billed while it stays loaded. Ollama Cloud trades that for Ollama's own usage billing. Bigger models cost time, not money.

System Requirements for Hosting OpenCode Ollama on a VPS

A 7B coder model wants 8-16 GB RAM to answer at a usable pace on CPU; 32 GB to keep something larger warm. Count tokens per second, not cores alone.

Frequently Asked Questions (FAQs)

Why do tool calls fail with small models?

Most small models were never trained for tool calling, and Ollama only tags some with the tools capability. The default context is small and truncates the thread, so tool JSON arrives broken.

How much context should I set?

OpenCode's docs suggest 16k to 32k with num_ctx. Set it in a Modelfile (PARAMETER num_ctx 32768) or with OLLAMA_CONTEXT_LENGTH. More context eats RAM and slows CPU inference.

How slow is CPU inference on Railway?

Railway has no GPUs, so a 7B model on a shared vCPU gives a few tokens per second and a turn can take minutes. Ollama Cloud is the escape hatch for speed.

Can I mix Ollama and hosted providers?

Yes. Keep the ollama provider next to Anthropic, OpenAI or OpenRouter in one config and switch models in the UI. Small model for edits, hosted for refactors.

Does Ollama need an API key?

Not for a self-hosted Ollama on the private network. Ollama Cloud at https://ollama.com does. Logins live in auth.json on the volume.

Where does opencode.json live on Railway?

At /data/home/.config/opencode/opencode.json, since HOME points at the volume, so edits survive redeploys. Write it from a shell, then restart OpenCode.


Template Content

More templates in this category

View Template
Chat Chat
Chat Chat, your own unified chat and search to AI platform.

okisdev
117
View Template
NEW
Weaviate
Vector database with hybrid search and an API key-protected API

zer0person
1
View Template
NEW
Möbius v0.1 Personal AI OS
Self-hosted AI agent that builds and runs apps for you, with memory.

bento
1