Railway
All agents

OpenCode + Railway

OpenCode is a powerful open-source AI coding agent built for the terminal. It features a rich TUI interface, multi-session support, and works with over 75 LLM providers including Claude, OpenAI, Gemini, and local models. With built-in agents for development and planning, LSP integration, and Railway CLI access, OpenCode gives you maximum flexibility without vendor lock-in.

Quick start

1

Install OpenCode

Install OpenCode via the quick install script

curl -fsSL https://opencode.ai/install | bash
2

Install Railway CLI

Install Railway CLI and authenticate

npm install -g @railway/cli && railway login
3

Start OpenCode

Launch OpenCode in your project directory

opencode
4

Deploy a full-stack app

OpenCode creates the services, wires up environment variables, and deploys, all from your terminal

Deploy this project to Railway with a Postgres database and Redis cache

Example prompts

Deploy this project to Railway

Add a Redis cache to my project

Check the deployment logs and fix any errors

Set up environment variables for production

Configure health checks and automatic restarts

Create separate staging and production environments

Deploy a Next.js app with Postgres and Redis on Railway

Set up a Python API with Celery workers and Redis broker

Deploy a microservices setup with shared Postgres and private networking

Create a Django app with Postgres, Redis, and background workers on Railway

Railway Skills

Railway Skills extend OpenCode with Railway-specific commands for deploying, managing, and monitoring your projects. View all skills on GitHub →

Install Railway Skills

curl -fsSL railway.com/skills.sh | bash

or

npx skills add railwayapp/railway-skills

Common workflows

1Deploy a Postgres database

  1. Ask OpenCode to add Postgres to your project
  2. OpenCode creates the database service via CLI
  3. OpenCode retrieves connection string with railway variables
  4. OpenCode updates your code to use the database

2Deploy with OpenCode

  1. Ask OpenCode to deploy your project to Railway
  2. OpenCode runs railway login if needed
  3. OpenCode initializes and deploys with railway up
  4. OpenCode monitors deployment with railway logs

3Debug a failing deployment

  1. Ask OpenCode to check your deployment logs
  2. OpenCode runs railway logs to fetch recent logs
  3. OpenCode analyzes the error and suggests fixes
  4. OpenCode applies the fix and redeploys

4Switch models mid-task

  1. Start a task with one model (e.g. Claude)
  2. Press Tab to switch to the plan agent for analysis
  3. Switch to a different model for implementation
  4. Deploy the result with railway up

5Environment variable setup

  1. Ask OpenCode to configure production environment
  2. OpenCode lists current variables with railway variables
  3. OpenCode sets new variables with railway variables set
  4. OpenCode triggers redeploy with railway up

Tips for success

  • Use the plan agent (Tab key) to analyze before making changes
  • Switch between models mid-session to leverage different strengths
  • OpenCode's LSP integration provides better code understanding

Frequently asked questions

How do I deploy to Railway with OpenCode?

Make sure Railway CLI is installed and run railway login to authenticate. Then ask OpenCode to deploy your project with railway up. OpenCode will handle the entire flow.

Can I use different LLM providers with OpenCode?

Yes! OpenCode supports 75+ models including Claude, GPT-4, Gemini, and local models. You can even switch models mid-session while maintaining context.

How do I debug Railway deployment errors with OpenCode?

Ask OpenCode to run railway logs to fetch deployment logs. It will analyze the errors, suggest fixes, and can apply them directly to your code.

Troubleshooting

Issue:

OpenCode can't find Railway CLI

Solution:

Ensure Railway CLI is installed globally with npm install -g @railway/cli and is in your PATH.

Issue:

Model API key not configured

Solution:

Set your preferred LLM provider's API key as an environment variable (e.g. ANTHROPIC_API_KEY or OPENAI_API_KEY).

Issue:

Deploy fails with permission error

Solution:

Run railway login to re-authenticate, or check that your Railway token has the correct permissions.

Community resources

Ready to deploy with OpenCode?

Get started in minutes. Railway handles the infrastructure.