Railway
All agents

Claude Code + Railway

Claude Code is Anthropic's agentic coding tool that operates directly in your terminal. It can understand your entire codebase, execute terminal commands, edit files across your project, and manage git operations. When paired with Railway, Claude Code can deploy your applications, manage environments, check logs, and handle your entire deployment workflow.

Quick start

1

Install Claude Code

Install the Claude Code CLI globally

npm install -g @anthropic-ai/claude-code
2

Install Railway MCP Server

Give Claude native access to Railway's API

claude mcp add railway-mcp-server -- npx -y @railway/mcp-server
3

Start Claude Code

Launch Claude Code in your project directory

claude
4

Deploy a full-stack app

Claude will deploy railway.com/template/nextjs-ai-chatbot with a database and cache, all wired up automatically

Deploy the Next.js AI Chatbot template with Postgres and Redis

Environment variables

VariableDescription
ANTHROPIC_API_KEY
Your Anthropic API key for Claude
RAILWAY_TOKEN
Railway API token for programmatic accessExample: railway-token-xxx

Example prompts

Deploy this project to Railway

Add a Postgres database to my project

Check the deployment logs and fix any errors

Scale my service to 2 vCPUs and 1GB memory

Set up a custom domain with SSL for my app

Create separate staging and production environments

Deploy an AI chatbot with Postgres for history and Redis for rate limiting

Set up n8n with Postgres and Redis workers for workflow automation

Deploy a Next.js SaaS starter with authentication and Stripe payments

Create a high-availability Postgres cluster with read replicas and automatic failover

Claude Code skills

/deploy

Deploy

Deploy current project to Railway

/logs

Logs

View deployment logs

/status

Status

Check deployment status

Common workflows

1Deploy a Postgres database

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

2Deploy a new project

  1. Ask Claude to initialize a Railway project
  2. Claude runs railway login if needed
  3. Claude runs railway init to create project
  4. Claude runs railway up to deploy
  5. Claude checks logs with railway logs

3Debug a failing deployment

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

4Set up environment variables

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

5Configure custom domain

  1. Ask Claude to set up a custom domain
  2. Claude runs railway domain to add the domain
  3. Claude provides DNS configuration instructions
  4. Claude verifies domain is working with railway status

Tips for success

  • Install the Railway MCP server for native Railway integration
  • Use railway link to connect Claude to an existing project
  • Ask Claude to check railway status before deploying

Code snippets

railway.toml configuration
toml
[build]
builder = "nixpacks"

[deploy]
startCommand = "npm start"
healthcheckPath = "/health"
healthcheckTimeout = 300
restartPolicyType = "on_failure"
Deploy with environment
bash
# Link to project
railway link

# Set environment variables
railway variables set NODE_ENV=production
railway variables set DATABASE_URL=$DATABASE_URL

# Deploy
railway up

Frequently asked questions

How do I give Claude Code access to Railway?

Install the Railway MCP server with claude mcp add railway-mcp-server -- npx -y @railway/mcp-server. This gives Claude native access to Railway's API for deployments, logs, and project management.

Can Claude Code deploy to existing Railway projects?

Yes! Use railway link in your project directory to connect to an existing Railway project, then Claude can deploy and manage it.

How do I debug a failed Railway deployment with Claude?

Ask Claude to check your deployment logs with railway logs. Claude will analyze errors, suggest fixes, and can automatically apply them and redeploy.

Troubleshooting

Issue:

Claude can't find the Railway CLI

Solution:

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

Issue:

MCP server connection fails

Solution:

Run claude mcp list to verify the Railway MCP server is installed. Re-add it with claude mcp add railway-mcp-server -- npx -y @railway/mcp-server.

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 Claude Code?

Get started in minutes. Railway handles the infrastructure.