Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

cli

> 开发工具
Open source

Railway CLI

580 stars0 likes1 views
WebsiteGitHub

About

Railway CLI

Railway CLI

The Railway CLI lets you interact with your Railway projects from the command line. Read the CLI documentation.

Installation

Install the Railway CLI with agent support configured in one step (macOS, Linux, Windows via WSL):

bash
bash ` for explicit server setup, or `railway ca ssh `
for a shell. Bare launches and shared CA/Desktop provisioning retain their
existing targeting behavior.

## Local Railway TUI prototype

```bash
railway code --railway                       # new VM, local TUI on its public agent endpoint
railway code --railway --agent my-box --dir /app/project
railway code --railway connect my-box        # connect to an existing VM; wake it if asleep
railway code --railway remote                # run the TUI on a new VM over SSH
railway code --railway --connection-json     # setup and verify, without opening a TUI
railway code get-config my-box               # replay saved connection details

…

bash
railway code --codex --new
railway code --opencode --new
railway code --opencode2 --new

# Explicitly request the endpoint on a plain cloud agent:
railway ca create my-box --code-endpoint

# Choose a custom port instead of the default 4096:
railway code --opencode2 --new --code-port 5000
railway ca create my-box --code-port 5000

…

bash
railway ca create restored-box --from-checkpoint  --code-endpoint
# Or select a custom port:
railway ca create restored-box --from-checkpoint  --code-port 5000
railway code --opencode2 --agent restored-box

The equivalent API request is:

graphql
mutation {
  cloudAgentCreate(input: {
    environmentId: ""
    name: "restored-box"
    cloudAgentCheckpointId: ""
    codeEndpoint: { port: 5000 }
  }) {
    id
    name
    domains { prefix port domain }
  }
}

The disk is restored into a new VM with its own identity and domains. Processes do not carry over. Saved Codex/OpenCode credentials and project directories are reused, while the launchers adopt the new VM's configured endpoint. Source VM variables are not copied automatically; pass needed variables or use a bootstrap. Checkpoint and bootstrap creates opt in explicitly. The separate fork operation preserves the source VM's code endpoint and port.

OpenCode clients and remote servers

Prepare an authenticated server on a cloud agent and open your local client:

bash
railway code --opencode
railway code --opencode2
railway code --opencode2 --name my-box

…

bash
railway code --opencode connect
railway code --opencode2 connect my-box

…

bash
railway code --opencode remote
railway code --opencode2 remote

…

bash
railway ca bootstrap save dev --agent configured-vm
railway ca bootstrap list
railway ca bootstrap save updated --agent another-vm --default
railway ca bootstrap default dev

railway code --codex                         # uses your local environment default
railway code --codex --bootstrap updated     # selects a named bootstrap
railway code --codex --no-bootstrap          # starts with a clean VM
railway ca create scratch --bootstrap dev

…

bash
railway code --codex
railway code --codex --agent my-box --dir /app
railway code --codex connect my-box
railway code --codex connect

New Codex agents use the same naming rules as OpenCode, with a codex- prefix (for example, codex-railg-3ed). The generated name works with connect, get-config, and cloud-agent lifecycle commands; --name sets a custom name.

For a Desktop-only workflow:

bash
railway code --codex desktop-only
railway code --codex desktop-only --agent my-box --dir /app

…

bash
railway code --codex --connection-json connect my-box
railway code --codex remote             # run the UI inside Railway CA
railway code --codex -- exec "run tests" # execute inside the VM

…

bash
railway ca ssh my-box                 # open a login shell
railway ca ssh my-box --session       # attach to or start a durable session
railway ca ssh my-box --session name  # attach to a named session
railway ca ssh my-box --resume        # resume the latest Claude conversation

Plain SSH bypasses harness autostart. When opening a durable session after its terminal has ended, interactive users can choose a recent Claude conversation. In the CA frame, Option+O / Alt+O opens a shell on the selected VM and returns to the frame on exit. The sidebar's c action copies the shell command.

Retrieve saved connection configuration

bash
railway code get-config                  # most recently saved connection
railway code get-config my-box           # a specific agent by name
railway code get-config codex-railg-3ed   # generated names work too
railway code get-config         # use an ID if names are ambiguous
railway code get-config my-box --json

…

bash
railway ca desktop --claude
railway ca desktop --codex
railway ca desktop --opencode --agent my-box
railway ca desktop --opencode --new
railway ca desktop --opencode2 --new

With Codex selected alone, railway ca desktop --codex is a compatibility alias for railway code --codex desktop-only. It uses the same backend startup and Desktop import flow, forwarding --agent, --new, --dir, project/environment, and its SSH alias/config/verification options. The existing --dry-run, --remove, and multi-app setup commands remain available.

App flags can be combined to prepare the same agent for several apps. Setup carries available local sign-ins, applies your skills/MCP sync preferences, and writes the agent's SSH configuration. --dry-run previews the local files without creating or waking an agent or starting a connection. Existing agents are reused and woken as needed; if none exists in the target environment, setup creates one. --new always creates a fresh agent, including when several app flags are combined. It cannot be combined with --agent or --remove.

Codex setup registers the SSH host and named remote project using Codex Desktop's version-1 app configuration, entirely in the background. It never launches or activates the app. Codex Desktop imports the configuration on its next startup. Existing connections and retry/timeout preferences are retained; changed configuration is backed up to config.json.railway-backup. --dry-run previews the merged config. --remove removes the SSH block and that alias's import declaration; remove already-imported connections and projects inside Codex, since its import mechanism does not delete them.

OpenCode Desktop connects directly to the agent's existing HTTPS address. The CLI starts password-protected opencode serve in the background on the configured code port (default 4096, or 8080 for legacy connections), checks its public endpoint, and saves the URL, username, password, default server, and remote project in Desktop's settings. --opencode configures only standard OpenCode (ai.opencode.desktop). --opencode2 configures OpenCode V2 (ai.opencode.desktop.beta), using its compatible server runtime. These two flags cannot be combined. JSON server settings and SQLite renderer state are supported; a drafts-only database does not change where settings are saved.

For V2, the CLI seeds an opencode2 shim on the agent. It downloads the official @opencode/cli platform package, verifies its SHA-512 integrity, and extracts only the CLI executable. Releases are cached separately under ~/.railway/runtimes/opencode2//.

The installed local V2 client selects the server version. Setup and reconnect upgrade an older cloud server to that version, including servers installed from the retired beta release channel. The download is verified before the old server stops; credentials and the project directory are retained, and the server's SQLite database is backed up before migration. A matching running server is reused. Neither the local client nor a newer cloud server is downgraded. Without an installed V2 client, setup uses the current official V2 release.

The VM image's standard opencode installation and the CLI-managed V2 runtime are separate: refreshing the base image does not update an existing V2 server.

Use railway ca --opencode2 for a terminal session. In the new-session picker, highlight OpenCode and press Tab to switch to OpenCode2 [Beta]. Tab also switches editions in the prompt footer; Shift+Tab cycles harnesses.

Setup also prints the connection details and a reminder that you may need to restart OpenCode Desktop to load the updated configuration. Private .railway-backup files preserve the previous settings and server state. You can close the terminal after setup; there is no local tunnel to keep running.

Press Cmd+B (Ctrl+B on Windows/Linux) to open Home. Under Projects, find Railway: and /app (or your --dir), then use that project's menu → New session. Setting a default server does not move existing chats. Standard OpenCode provider sign-ins from auth.json are copied when available. OpenCode2 imports the active account for each provider from your local Beta credential database, preserving accounts already configured on the cloud agent. Legacy auth.json is used only when no Beta credential store exists. Credentials are sent over SSH and the temporary transfer file is removed after import. If there is no local sign-in to copy, connect the provider in the remote server's settings.

OpenCode uses the agent's code endpoint when available. Setup refuses to take over an occupied server port; stop the other process or use --new for a fresh agent. Rerunning railway ca desktop --opencode --agent my-box reuses the running server and its credentials, or starts it again after a sleep/wake or restart. The remote credential and process state are stored privately under ~/.railway/desktop/opencode/; startup logs are in server.log there.

railway ca desktop --opencode --agent my-box --remove (or --opencode2 for Beta) stops the managed OpenCode process on a running agent and removes the shared SSH block and the Desktop connection/project saved by setup. It does not wake a sleeping agent. The agent remains; railway ca sleep my-box stops its compute bill.

Contributing

See CONTRIBUTING.md for information on setting up this repository locally.

Feedback

Share feedback and suggestions on Central Station.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rustcliinfrastructurerailway

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category开发工具
PricingOpen source

> Related tools

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具