|Docs

Manage agents and sessions

A cloud agent is a machine. A session is a coding-agent process running on it. You can run several sessions on one machine, connect through a desktop app, and return to the same files later.

Find your agents

Run railway ca to browse agents and their running terminal sessions. For a list without opening the interface:

railway ca list
railway ca list --json

The default list finds agents you own across projects. Narrow it with --project and --environment. Agent names or IDs select existing machines for lifecycle commands.

Choose where agents run

For a new launch, Railway resolves the project and environment in this order:

OrderSource
1Explicit --project and --environment flags
2The directory's linked project and environment
3The default project saved by railway ca setup
4Interactive setup when no target is available

A stale link to a deleted project is ignored and can fall back to the configured default. Use railway link to repair it.

railway code --opencode --new --project <project-id> --environment production

Use railway ca setup --show to inspect saved preferences. The terminal interface also lets you change the launch target.

Reuse and create agents

railway code with a coding-agent flag creates a new VM unless you pass --agent <agent-name> or use connect. --agent and connect work with Codex, OpenCode, and Railway Agent:

railway code --opencode --agent <agent-name>
railway code --codex connect <agent-name>

railway ca --<agent> and railway ca start --<agent> reuse an agent instead. Railway remembers agents between launches, wakes the selected agent if needed, and creates one when there is none to use. If several agents match and Railway cannot choose safely, select one explicitly. Add --new to create a new VM:

railway ca start --claude
railway ca start --claude --new

railway agent uses its own agent, one per environment, and reuses it for every thread.

Desktop setup supports the same selection with any of its app flags. Use railway ca create when you want to provision a machine without opening a coding client:

railway ca create my-agent --project <project-id> --environment production

Agent names

New OpenCode agents have recognizable lowercase names:

Coding agentExamplePattern
OpenCodeoc-railg-3edoc- + project label + three random letters/digits

The label uses up to five letters or digits from the project name. When launching into your saved default Cloud Agents project, it comes from your local repository or directory name. Spaces and punctuation are removed. Existing agents keep their names.

Override the generated name when creating through railway code:

railway code --opencode --new --name reviews

The naming pattern also applies to new OpenCode agents created through Desktop setup or Railway CA. A name helps you recognize an agent; server discovery checks its configuration rather than relying on the prefix.

Work in terminal sessions

In railway ca, select an agent to see its sessions and press Enter on a session to connect. To start another session on an existing agent, select it and press ⌥p to start one from a prompt. Press n to create a new agent. ⌥n opens the same picker in the selected agent's project, and works while you type in a session. On macOS, ⌥n needs your terminal to use Option as Meta. Agents with no sessions occupy a single row; the status icon indicates when sessions are loading.

Railway CA with an agent tree and a connected coding session
KeyAction
enterConnect to a session and type in it
shift+esc or ^]Return keyboard control to the tree
⌥pStart a session from a prompt on the selected agent
nCreate a new agent, choosing its coding agent, bootstrap, and project
⌥nSame as n, starting in the selected agent's project
s / w / dSleep, wake, or delete an agent
cCopy a session's SSH command
⌥fToggle the session between a full-width view and the tree
?Show the complete key reference

Terminal sessions survive disconnects while the agent is awake. Sleeping stops those processes. Saved files and conversation history stay on disk, and your coding tool controls how a new process resumes that history.

All sessions on an agent share its disk. Use separate working directories or Git worktrees when tasks may edit the same files.

Connect from a desktop app

Use the guides for Claude Desktop, Codex Desktop, and OpenCode. Desktop chats and OpenCode server sessions are managed by those apps; the Railway CA tree lists its terminal sessions.

For OpenCode terminal clients, railway code --opencode connect discovers compatible running servers across your projects. A named connection can wake a saved server. See each client guide for details.

Sleep, wake, and delete

Disconnecting doesn't stop a cloud agent right away. An agent sleeps on its own after five minutes with:

  • no SSH client attached
  • almost no network traffic sent (under 8 KiB per 15 seconds)
  • no coding agent working or waiting on you (Railway Agent doesn't keep it awake while it waits)

A command left running in a detached session doesn't keep the agent awake. An SSH connection or a wake from the CLI or API wakes it again. A request to its public domain, including one from a bot, also wakes an agent that slept on its own, and compute billing resumes. An agent you slept, for example with railway ca sleep, stays asleep until you wake it or connect over SSH.

Agents created before October 8, 2026 don't sleep on their own and keep billing until you sleep them. To get idle sleep, create a new agent.

ActionRunning processesFilesCompute billing
Disconnect a clientKeep running until the agent sleeps; the app controls its sessionRetainedContinues until the agent sleeps
Sleep the agentStoppedRetainedStops
Wake the agentMost servers that were listening on a port start again on agents created since October 8, 2026. Start other processes again.RetainedResumes
Delete the agentStoppedDeleted with the diskStops
railway ca sleep <agent-name>

Connecting over SSH wakes a sleeping agent. If Claude or Codex Desktop times out while the agent wakes, wake it first and retry:

railway ca wake <agent-name>

Agents created since October 8, 2026 restart the OpenCode server when they wake, so reconnecting OpenCode usually works. If OpenCode can't connect, rerun railway ca desktop --opencode or a named connect command. On agents created before October 8, 2026, rerun setup after every sleep.

Delete an agent and its disk when you no longer need them:

railway ca delete <agent-name>

Deletion asks for confirmation. To sleep every running agent you own, use railway ca sleep --all; add an environment filter to narrow the scope. --keep-awake is accepted for compatibility and has no effect; it doesn't prevent idle sleep.

Open a shell

Use the agent's name or ID:

railway ca ssh <agent-name> -- bash

Without a command, railway ca ssh can attach to a durable terminal session. Use --session <name> to select one. It wakes a sleeping agent and never creates a replacement for a mistyped name.

Use the dashboard

The Agents tab in a project shows agent status and lets you open a console, view sessions, start work, copy an SSH command, or delete an agent. Use desktop setup from your computer when you want the CLI to write a connection into your installed app.

CLI command reference →