---
title: "Deploy OpenCode"
description: "OpenCode AI coding agent with web UI, password login and persistent storage"
category: "AI/ML"
url: https://railway.com/deploy/opencode-3
---

# Deploy OpenCode

OpenCode AI coding agent with web UI, password login and persistent storage

**[Deploy OpenCode on Railway](https://railway.com/template/opencode-3)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/opencode-3/manifest.json

- **Creator:** Agaz Self-Host
- **Category:** AI/ML

## Template content

### OpenCode https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/png/opencode.png

- **Source:** https://github.com/aalfath/opencode-railway-template
- **Health check:** /healthz
- **Public domain:** Yes

## Documentation

# Deploy and Host OpenCode on Railway

OpenCode is an open-source, MIT-licensed AI coding agent. It reads and edits code, runs commands in a terminal and works with many model providers, including Anthropic, OpenAI, OpenRouter and its own free models. This template runs the OpenCode 2 server and web UI, so you can use the agent from any browser.

## About Hosting OpenCode

Hosting OpenCode means running its server with persistent storage and keeping it behind a login, because the agent can run shell commands. This template builds the official `ghcr.io/anomalyco/opencode` image, pinned by version and digest, from a public GitHub repo. It keeps your workspace, sessions, provider credentials and config on one Railway volume at `/data`, so they survive redeploys. A small gateway adds a password sign-in page in front of OpenCode's web UI and a `/healthz` health check. The password is generated for each deploy, so the deploy form has nothing to fill in. Updates arrive as Railway update notices when the repo bumps the version.

## Common Use Cases

* Run an AI coding agent on your repositories from a browser, on any device
* Keep long agent sessions running in the cloud instead of on your laptop
* Share one always-on coding agent server between your own machines through its API

## Dependencies for OpenCode Hosting

* One Railway service built from `aalfath/opencode-railway-template` (official OpenCode image, pinned by digest)
* One Railway volume at `/data` for the workspace, sessions and credentials

### Deployment Dependencies

* OpenCode source and docs: https://github.com/anomalyco/opencode and https://opencode.ai/docs
* Template repo, changelog and update notes: https://github.com/aalfath/opencode-railway-template
* Optional: an API key or subscription for a model provider. OpenCode's free models work without one.

### Implementation Details

After the deploy finishes:

1. Open the OpenCode service's **Variables** tab and copy `OPENCODE_PASSWORD`.
2. Open the service's Railway domain and sign in with that password.
3. Add the project folder `/data/workspace`, or clone a repository into it from the built-in terminal, for example `git clone https://github.com/YOUR-USER/YOUR-REPO /data/workspace/YOUR-REPO`.
4. Connect your model provider under **Settings → Providers**, or set its usual variable (such as `ANTHROPIC_API_KEY`) on the service.

The CLI and API clients use HTTP Basic auth with the user `opencode` and the same password, for example `opencode --server https://YOUR-DOMAIN`. Tools the agent needs, such as `git`, `gh`, `ssh`, Node.js and Python, are included. OpenCode's self-update is off: new versions reach you as Railway update notices, and the repo's `CHANGELOG.md` lists what changed. Your data stays on the volume when you apply an update.

## Why Deploy OpenCode on Railway?


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 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.



## Similar templates

- [Chat Chat](https://railway.com/deploy/-WWW5r) — Chat Chat, your own unified chat and search to AI platform.
- [Weaviate](https://railway.com/deploy/weaviate-1) — Vector database with hybrid search and an API key-protected API
- [Möbius Personal AI OS](https://railway.com/deploy/mobius-v01-personal-ai-os) — Self-hosted AI agent that builds and runs apps for you, with memory.

Open this page in a browser: https://railway.com/deploy/opencode-3
