Deploy OpenCode Claude

Run the OpenCode agent on Anthropic Claude models

Deploy OpenCode Claude

Just deployed

/data

Deploy and Host self hosted OpenCode Claude (Self-Hosted AI Coding Agent Setup) on Railway

This template runs a self-hosted OpenCode server on Railway, set up for Anthropic Claude models.

About Hosting OpenCode Claude open-source software on Railway (self hosted OpenCode running on Anthropic Claude models template)

This template runs one opencode service from the official OpenCode image with a persistent volume at /data. Model choices go in opencode.json under /data/home/.config/opencode.

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

Claude Code is the easy default if you're happy on one vendor's terminal agent and its billing, but you give up control over the harness and the provider mix.

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 Claude 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 Claude self hosting

A VPS works too, but setup time, persistence and HTTPS differ a lot by platform.

ProviderWhat You Get with RailwayWhat You Get with the Other Provider
DigitalOceanOne click deploy, a persistent volume at /data for provider keys, and HTTPS on a public domain.A full droplet you control, but you set up Docker, the proxy and certificates yourself.
AWSA single service with volume and domain wired up, no IAM or VPC work.Deep networking and IAM control, with a steeper learning curve for one small box.
HetznerManaged HTTPS and persistence, so no babysitting between redeploys.Low cost per core, but you own updates, firewall rules and renewals.

Railway trades some control for much less infrastructure work.

Common Use Cases for hosted OpenCode Claude

  • Day-to-day refactors: Open the OpenCode domain in your browser, log in, and run Claude Sonnet against your repo in /data/workspace. Nothing needs installing on each laptop.
  • Cheap side tasks: Set a lighter model as "small_model": "anthropic/your-model-id" in opencode.json (confirm the id in /models) so auxiliary work doesn't use your main model.
  • Team model picker: Use provider.anthropic.whitelist to limit the picker to agreed Claude models, or blacklist something like claude-opus-5-5 to hide it.
  • Credentials that persist: Save your key once with /connect and it stays in /data/home/.local/share/opencode/auth.json on the volume through redeploys.
  • Side-by-side checks: Keep Anthropic and another provider configured in one instance and compare outputs on the same task.

Dependencies for OpenCode Claude Docker hosted on Railway

This template is a single service, so the moving parts are few. OpenCode serves its API and web UI from one process, so no database or reverse proxy is needed.

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

You get one service with a public domain on port 4096 and one persistent volume at /data.

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

The image is ghcr.io/onepush-dev/opencode:1.19.3, pinned by tag, with OPENCODE_DISABLE_AUTOUPDATE set to true, so you upgrade by changing the tag.

How does OpenCode Claude compare against other ways to run Claude models in a terminal coding agent

OpenCode Claude vs Claude Code (Anthropic's Terminal Agent Alternative)

  • Model Lock-In: Claude Code is built around Anthropic models, so it is simpler if you only want Claude. OpenCode Claude uses the Anthropic provider but can switch to other providers in the same instance.
  • Hosting Model: Claude Code runs on your laptop. OpenCode Claude runs as a server on Railway with a public domain, so you can reach the agent from a browser or terminal anywhere.
  • Where Claude Code Wins: Anthropic ships Claude Code with first-party polish and fast updates for new Claude features.

OpenCode Claude vs Cursor (VS Code Fork Alternative)

  • Interface: Cursor is a full VS Code fork with inline editing. OpenCode Claude is terminal and web first.
  • Cost Model: Cursor uses paid plans. OpenCode is free and open source, so you pay only the model provider and Railway.
  • Where Cursor Wins: If you want a polished editor with autocomplete and visual diffs, Cursor is the better fit.

OpenCode Claude vs Aider (Open-Source Terminal Pair Programmer Alternative)

  • Server Mode: Aider is a local terminal tool with no built-in web server. OpenCode Claude exposes an HTTP API and web UI on port 4096, so the same agent can be attached from another machine.
  • Persistence: OpenCode Claude keeps provider logins in auth.json on the volume and model choices in opencode.json.
  • Where Aider Wins: Aider is lighter weight and focused on git-driven pair programming, with no server to manage.

OpenCode Claude vs Cline (VS Code Extension Alternative)

  • Runtime: Cline runs as a VS Code extension. OpenCode Claude runs as a standalone server, so it works without any editor.
  • Config: Cline sets providers in its settings panel. OpenCode Claude sets the default model and small_model in opencode.json, which is easy to version and copy between projects.
  • Where Cline Wins: If your work already lives in VS Code, Cline fits better than a separate server you reach over the web.

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

Here is the first-day sequence after deploy. The key step is getting your Anthropic key into the right place so it survives redeploys.

  1. Open the opencode service's Variables tab and note OPENCODE_SERVER_PASSWORD. Optionally set ANTHROPIC_API_KEY there for an environment-based key.

  2. Open the public domain and log in with the username opencode and that password.

  3. In the TUI or web UI, run /connect, select Anthropic, and paste your Console key at the API key prompt. It saves to /data/home/.local/share/opencode/auth.json on the volume.

  4. Run /models to confirm the Anthropic models appear.

  5. Edit opencode.json with a default model and a lighter small_model, checking exact ids in /models first:

{
  "model": "anthropic/claude-sonnet-5-5",
  "small_model": "anthropic/claude-haiku-4-5"
}
  1. Optionally add provider.anthropic.models options, or a blacklist or whitelist, to control the picker.

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

These steps assume a fresh Ubuntu or Debian server with your-domain pointed at it and HTTPS in front.

Clone the Repository

OpenCode is MIT licensed, so you can start from the upstream repo.

git clone https://github.com/anomalyco/opencode.git
cd opencode

Install Dependencies

The install script or npm package both give you the opencode command.

curl -fsSL https://opencode.ai/install | bash
# or
npm i -g opencode-ai

Configure Environment Variables

Set a long server password, since the server refuses to start without one. Point HOME at a disk that survives reboots so provider logins in ~/.local/share/opencode/auth.json are kept.

export OPENCODE_SERVER_PASSWORD='use-a-long-random-string'
export HOME=/srv/opencode/home

Start the OpenCode Claude Application

Bind to port 4096 behind a TLS reverse proxy, then open https://your-domain and sign in as opencode.

opencode serve --hostname 0.0.0.0 --port 4096

Railway handles the HTTPS domain, the persistent volume, and restarts for you, which is most of what you would otherwise rebuild by hand.

Official Pricing of OpenCode Claude (OpenCode pricing)

OpenCode is free and open source under the MIT license, so there is no license fee. Heavy builds or long test runs can push that higher.

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

Running OpenCode on Railway means you pay for the container and the model calls, and nothing else. The software is MIT-licensed and free. Here is what that looks like in practice.

Monthly cost of self hosting OpenCode Claude on Railway

Expect roughly $5 to $15 a month for one container at light use, climbing during heavy builds or test runs. That covers only the Railway side.

System Requirements for Hosting OpenCode Claude on a VPS

On a VPS you need a small Linux machine with enough memory for the OpenCode server plus your largest build, and a persistent disk for the projects folder and auth.json.

Frequently Asked Questions (FAQs)

Where is the Anthropic API key stored, and does it survive redeploys?

Running /connect saves the key to /data/home/.local/share/opencode/auth.json on the persistent volume. Because that path sits under /data, the key survives redeploys.

Should I set ANTHROPIC_API_KEY or use /connect?

Either works. Use one or the other so you know which key is active.

How do I choose the default model in opencode.json?

Add a top-level "model" key in the provider_id/model_id form, such as "model": "anthropic/claude-sonnet-5-5". The -m flag overrides it when you need a different model for one run.

What is small_model, and how do I set it?

small_model is a lighter model OpenCode uses for auxiliary tasks, which helps control cost.

Can I use my Claude Pro or Max subscription instead of an API key?

No. Anthropic does not allow Pro or Max subscription logins through third-party tools, so use an API key from the Anthropic Console on this template.

How do I hide models from the picker with whitelist or blacklist?

Under provider.anthropic in opencode.json, a "whitelist" array narrows the list to the models you name, and a "blacklist" array removes the ones you don't want.


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
Möbius v0.1 Personal AI OS
Self-hosted AI agent that builds and runs apps for you, with memory.

bento
1