Deploy OpenCode Commands

Reusable slash commands in your hosted OpenCode

Deploy OpenCode Commands

Just deployed

/data

Deploy and Host self hosted OpenCode Commands (AI Coding Agent with Custom Commands) on Railway

This template runs a hosted OpenCode server with reusable slash commands for tests, reviews and releases.

About Hosting OpenCode Commands open-source software on Railway (self hosted OpenCode custom commands template)

This template runs one service, the opencode container from ghcr.io/onepush-dev/opencode:1.19.3, with a single volume mounted at /data.

Railway handles the public domain, the TLS, the volume and the restarts.

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

Claude Code's slash commands are great, but they come with a Claude subscription or API billing and models tied to Anthropic.

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

Self hosting OpenCode Commands means choosing between a managed deploy and setting up a VPS yourself. This table compares the two.

ProviderWhat You Get with RailwayWhat You Get with the Other Provider
DigitalOceanOne click deploy with the volume, HTTPS domain and generated password already wired up.A droplet you configure yourself, including Docker, firewall and TLS.
AWSOne service with a volume at /data and no IAM or VPC setup before first login.Deep EC2 and networking options that pay off at scale but add moving parts.
HetznerA managed deploy from the template, with no SSH or server patching needed.Low cost VPS specs, but you run the OS, updates and certificates yourself.

Your saved commands in .opencode/commands/ live on the volume, so they move with you.

Common Use Cases for hosted OpenCode Commands

  • A /test command that runs the suite and fixes failures: Write test.md with a template that runs the test script, reads the failures, and patches the code until it passes. Type /test from the prompt and the loop runs without retyping instructions.
  • A /review command bound to a read-only agent: Set the agent field to a review agent that cannot edit files, so the command comments on a diff without touching anything. Add a model override if reviews need a stronger model.
  • Commands that inject git diff output: Use shell output injection such as !git diff --stat or !git log --oneline -10 so the agent sees live repo state each run.
  • Per-project commands in the repo: Keep .opencode/commands/ inside each project so the commands travel with the code and match its test and release steps.
  • Team-shared commands: Commit the commands folder to a shared repo so everyone gets the same /release and /changelog commands, with one place to fix a bad prompt.

Dependencies for OpenCode Commands Docker hosted on Railway

The template runs as one service, so the dependency list is short, but the volume layout decides whether your commands survive a redeploy.

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

The service is opencode, built from ghcr.io/onepush-dev/opencode:1.19.3, exposed on a public domain to port 4096, with one volume mounted at /data.

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

Key variables are OPENCODE_SERVER_USERNAME (opencode by default), OPENCODE_SERVER_PASSWORD (generated, 32 characters), OPENCODE_HOSTNAME=0.0.0.0, OPENCODE_WORKSPACE=/data/workspace, HOME=/data/home, OPENCODE_DISABLE_AUTOUPDATE=true and PORT=4096.

How does OpenCode Commands compare against other ways to save reusable prompts for coding agents

Most of these tools save a prompt, but they differ in where the prompt lives, how it takes arguments, and whether it can pull live shell output.

OpenCode Commands vs Claude Code slash commands (Claude Code Alternative)

  • Where it lives: Each command is a markdown file in .opencode/commands/ or a global commands folder, so you can commit it to git.
  • Arguments and injection: $ARGUMENTS, positional $1 and so on, and !command output injection are built in.
  • Model and agent per command: Frontmatter takes agent and model keys, so one command can run on a read-only reviewer agent.
  • Where Claude Code wins: It is more polished out of the box, while OpenCode needs you to set up provider logins yourself.

OpenCode Commands vs Cursor rules (Cursor Alternative)

  • Scope: Cursor rules shape editor behavior, while OpenCode commands are invoked on demand with a slash and a name.
  • Hosting: Cursor runs on your laptop as a proprietary VS Code fork, while OpenCode commands run on a server you control, so the same /review works from any browser.
  • Where Cursor wins: If you live inside the editor, its integrated rules and completion are hard to beat.

OpenCode Commands vs Aider (Aider Alternative)

  • Interface: Aider is a git-native terminal tool with no built-in web UI server, while OpenCode serves a web UI and API.
  • Reusable prompts: Aider has no named commands with frontmatter and shell injection, so you retype prompts each time.
  • Where Aider wins: It is mature, Apache-2.0 licensed, and very good at making git commits from the terminal.

OpenCode Commands vs GitHub Copilot prompt files (GitHub Copilot Alternative)

  • Product level only: Our supplied facts do not cover prompt-file specifics, so this stays at the product level.
  • Self hosting: Copilot is a hosted GitHub service, while OpenCode command files sit on a volume you own.
  • Where Copilot wins: It is tightly integrated with GitHub and your editor, and needs no server to run.

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

  1. Open your hosted OpenCode at your Railway domain and sign in with username opencode and the OPENCODE_SERVER_PASSWORD value from the Variables tab.
  2. Clone a repo into /data/workspace, then create .opencode/commands/test.md inside it. For a command you want everywhere, put the file in /data/home/.config/opencode/commands/ instead.
  3. Write the frontmatter (description, agent, model) and a prompt body that uses $ARGUMENTS and shell output injection, like the file below.
  4. Type /test in the prompt, add an argument such as a test path, and send it.
---
description: Run the test suite and fix failures
agent: build
model: anthropic/claude-sonnet-5-5
---
Run the tests for $ARGUMENTS. Here is the recent history: !`git log --oneline -5`
Fix any failures and explain what you changed.

The model line only works if you have a matching provider login or API key set up.

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

Running this on your own VPS takes four steps. Keep the commands folder on disk you can back up.

Clone the Repository

Clone the project the agent will work on, and make a folder for OpenCode's config and command files.

git clone https://github.com/your-org/your-repo.git /srv/workspace/your-repo
mkdir -p /srv/home/.config/opencode/commands

Install Dependencies

Install the OpenCode binary with npm, or use the Docker image ghcr.io/anomalyco/opencode.

npm i -g opencode-ai
opencode --version

Configure Environment Variables

Set a server password so the HTTP server is never open.

export OPENCODE_SERVER_PASSWORD="$(openssl rand -hex 16)"
export OPENCODE_HOSTNAME=0.0.0.0
export HOME=/srv/home
export OPENCODE_DISABLE_AUTOUPDATE=true

Start the OpenCode Commands Application

Start the server on port 4096, put it behind HTTPS with a reverse proxy, then open https://your-domain and type / to confirm your commands like /test appear.

cd /srv/workspace/your-repo
opencode serve --hostname 0.0.0.0 --port 4096

Official Pricing of OpenCode Commands (OpenCode pricing)

OpenCode itself is free and open source under the MIT license, so the custom commands feature costs nothing to use.

What you do pay for is the infrastructure and the models. You also pay your model provider when a command calls an LLM.

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

Self hosting OpenCode Commands trades a monthly bill for some setup and upkeep.

Monthly cost of self hosting OpenCode Commands on Railway

On Railway, one container at light use usually runs about $5-15 per month, and heavy builds or test runs push that higher.

System Requirements for Hosting OpenCode Commands on a VPS

A VPS needs enough memory and disk for the opencode server, your repos, and any test suites your commands trigger.

Frequently Asked Questions (FAQs)

Should I write commands as markdown files or as JSON config entries?

Markdown files are the easier route. Use the "command" object in opencode.json only when you want everything in one config file.

How do $ARGUMENTS and positional values get passed in?

$ARGUMENTS takes the whole argument string, so /component Button swaps in Button.

Is shell output injection safe on a shared server?

Treat it with care. Keep injected commands read-only and avoid feeding in untrusted input.

How do I bind a command to an agent or model?

Set agent in the frontmatter to choose the agent, and model in the provider/model form to override the default for that command.

Can a custom command replace a built-in like /init or /help?

Yes.

Where do global commands live on this template?

Global commands go in /data/home/.config/opencode/commands/, since HOME is /data/home. They sit on the volume, so they survive redeploys.


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