Skip to content

AI Code Tutorial · No. 06

Move off railway.json before Railway stops reading it.

A brief you can hand to a coding agent. It finds every service that still depends on railway.json or railway.toml, moves each one to .railway/railway.ts, refuses any plan that would detach a volume or take over resources it does not own, and proves each service with a fresh build before it moves on.

18 min read Intermediate
RailwayInfrastructure as CodeDeploymentDevOps
See the workflow

Why this, and why now.

Railway has deprecated Config as Code, the railway.json or railway.toml file in your repository that sets a service’s build and deploy options. Its replacement is Infrastructure as Code: one .railway/railway.ts file that the Railway CLI compares with your project and applies. Every deploy of a legacy service still reads the old file, until the cutoff. Railway’s CLI prints 1 December 2026; its documentation says 1 January 2027. Plan for the earlier one.

The trap is that nothing fails loudly. After the cutoff a service deploys on Railway’s defaults instead of your file. A web app usually still boots, so the site looks fine. What disappears is whatever the file was quietly doing: the start command that also launched a background worker and a scheduler, the pre-deploy migration, the healthcheck, the Dockerfile builder.

Railway ships a migration command, and for a simple service its output is correct. Across a real set of projects it is not: it can leave a volume out of the file, so applying it would unmount your data; it can turn one repository into the owner of a whole project; it can give a queue worker a web healthcheck it will never pass. All of these are visible before anything changes, in the output of railway config plan.

This tutorial is built around that plan. Your coding agent inventories every service, generates the file, reads the plan line by line, applies only plans that add settings and destroy nothing, and then proves each service with a fresh build that no longer has the old file.


The idea

The settings move out of the build.

Today the file travels with your code and is read during every deploy. Afterwards the settings live on the service itself, written once by the CLI from your machine. The deploy no longer reads anything from the repository about how to run.

Fig. 1 — Where a service’s settings come from, before and after
Config as Code compared with Infrastructure as Code on Railway On the left, before: a git push sends the repository, including railway.json, to Railway, and every deploy reads the file and overrides the dashboard settings. On the right, after: the coding agent on your machine runs railway config plan and apply, which write the settings onto the service. A git push still triggers a deploy, but the deploy reads the settings from the service, not from the repository. BEFORE · CONFIG AS CODE Your repository app code railway.json git push Every deploy reads the file, overrides the dashboard Service settings often stale: the file always won AFTER · INFRASTRUCTURE AS CODE Coding agent reads .railway/ railway.ts Repository app code only + railway.ts config plan config apply git push Service settings start · healthcheck · builder · volumes Every deploy reads the service, never the repo Config as Code compared with Infrastructure as Code on Railway BEFORE Repository · code + railway.json Every deploy reads the file, overrides the dashboard Service settings · often stale AFTER Coding agent config plan · config apply Service settings start · healthcheck · builder · volumes Every deploy · reads the service

The old file.

Read during each deploy, and it wins over the dashboard. Railway reads it from a path stored on the service, or, when no path is stored, auto-detects railway.toml or railway.json at the repository root. That second rule means one root file can silently configure every service built from the repository.

The new file.

Read by the CLI on your machine, never by a deploy. plan compares it with the project and lists the differences; apply writes them. A file declares a named partial, the slice of the project it owns, and can delete what it owns if you leave it out. Ownership is the whole safety model.

The whole method in one sentence: copy what the old file does onto the service, prove with a plan that nothing else changes, then delete the file and prove with a fresh build that the service still runs every process it ran before.


The workflow

Six phases, repeated per repository.

Phase 0 runs once for everything. Phases 1 to 5 run per repository, in order of risk: services whose start command runs workers first, while there is still time to fix a surprise. Nothing changes in production before phase 3.

Fig. 2 — One migration, phase by phase

  1. PHASE 0

    Inventory

    Read-only. Every live service, every repository, and what each old file sets.

    Gate: Every service ranked

  2. PHASE 1

    Generate

    Preview the IaC file, scoped to this repository, and compare it with the old file.

    Gate: Matches character for character

  3. PHASE 2

    Plan

    Read every line of railway config plan. Fix the file until only additions remain.

    Gate: 0 to destroy

  4. PHASE 3

    Apply

    Cut over, apply, re-plan. The settings now live on the service.

    Gate: “Already up to date”

  5. PHASE 4

    Prove

    Delete the old file, push, and watch a fresh build come up without it.

    Gate: Every process running

  6. PHASE 5

    Record

    Note what differed, what you dropped on purpose, and move to the next repository.

    Gate: Report written


Reading the plan

Additions are fine. Anything else is a stop.

A correct migration plan only moves settings from the old file onto the service, so every line reads null → value. Learn to recognise the three plans below and you have the whole safety check.

Apply

Plan: 0 to add, 1 to change, 0 to destroy
  ~ Update web deploy.healthcheckPath,
    deploy.startCommand
    └ deploy.healthcheckPath
      (null → "/health")
    └ deploy.startCommand
      (null → "bash start.sh")

Every change is an addition that matches the old file. Apply.

Stop: a volume detaches

Plan: 0 to add, 2 to change, 0 to destroy
  ~ Update web deploy.startCommand
    └ (null → "gunicorn app:app")
  ~ Update web volumeAttachments...
    └ mountPath ("/data" → null)
    └ volume ("volume.data" → null)

! 1 destructive change(s)

“0 to destroy” and still destructive. The generated file forgot the volume. Add it, re-plan.

Stop: whole project

// no "export const partial" line
export default defineRailway(() => {
  const db = postgres("Postgres");
  const cache = redis("Redis");
  const web = service("web", ...);
  const other = service("other", ...);
  return project("my-app", {
    resources: [db, cache,
                web, other],
  });
});

No partial and services from other repositories: this file would own, and could later delete, the whole project.

Fixing a forgotten volume.

Do not hand-write the volume. Link a throwaway folder to the same service and run railway config pull --force --variables=unmanaged there. It writes the project’s live configuration, including each volume(...) with its region and size, and the service’s volumeMounts. Copy those two pieces into your file, add the volume to resources, and plan again. The detach line disappears. Pull in a scratch folder, never the repository: it overwrites the authoring file with the whole project.

Fixing a whole-project file.

This happens when a repository holds two config files, say railway.json for the web service and a second one for a worker: the migrate command merges everything it finds. Throw the file away. Run railway config migrate --service <name> --show once per service the repository deploys, and merge the service blocks by hand into one file with one export const partial. The plan should then mention those services and nothing else.


Before you start

Fifteen minutes of preparation.

A current Railway CLI, logged in

The railway config commands are recent. Upgrade first, then check railway whoami. Every railway command now prints the deprecation warning; that is expected.

git and gh, signed in

The agent checks each repository on GitHub, not just your checkouts. A service can deploy from a repository you have no local copy of, and its file still counts.

A read-only Railway API token

For the inventory: which services exist, which repository each deploys, and what is stored on each. Keep it in an environment variable; the agent prints names, never values.

Builds that work

Check the Railway status page and that each service’s last deploy succeeded. Phase 4 needs a clean build to prove anything.

A quiet window per service

A deploy restarts schedulers. Note when each service’s timed jobs run and migrate between them, not during.

Clean working trees

Pull every repository first. The agent stages only the files it changes, but it should know about your uncommitted work before it starts.

Approve every command

Run the agent in a mode where you confirm each command, and expect your tool to ask before it changes production variables. That pause is the point.


Phase by phase

What the agent actually does.

You do not need to type any of this. It is here so you can follow along and know what a good run looks like.

Phase 0 · read-only, once

Inventory, and rank by blast radius.

  • Start from Railway, not from your disk. List every service in every workspace and the repository it deploys. Then check each repository on GitHub for railway.json and railway.toml. Local checkouts miss live repositories and include dead ones.
  • Map repository to services. One repository often feeds two services (web and worker), and sometimes services in two projects. Each of them reads the root file.
  • Read what each file sets, and what is already stored on each service: start command, config-file path, builder, healthcheck, restart policy. Differences are where the surprises are.
  • Rank by what would silently break. Critical: a start command that runs more than one process, or a preDeployCommand. High: a start command or builder the app cannot run without, or variables set in a toml. Medium: healthcheck and restart policy only.
  • Flag dead files. A second file such as railway.worker.json is only read if a service stores that path. If none does, its settings were never in effect; migrating them would change behaviour.
# which live repositories still carry a config file?
for repo in $(cat live_repos.txt); do
  for f in railway.json railway.toml; do
    gh api "repos/$repo/contents/$f" --jq .name \
      >/dev/null 2>&1 && echo "$repo: $f"
  done
done

# what does each file set? (no secrets in these files,
# but check before printing)
gh api repos/OWNER/REPO/contents/railway.json \
  --jq .content | base64 -d

# what is stored on the service today? (GraphQL)
serviceInstances { serviceName railwayConfigFile
  startCommand builder healthcheckPath
  restartPolicyType restartPolicyMaxRetries }

# every volume and its mount, per service
volumeInstances { serviceId mountPath volume { name } }

Gate: a table of every live service, its repository, what its file sets, its volumes and its risk, then the agent waits for you.

Phase 1 · per repository

Generate, scoped and compared.

  • Link the checkout. railway link --project <id> --environment production --service <name>. An unlinked folder makes the CLI prompt, and an agent cannot answer prompts.
  • Preview to a file. --show writes nothing. Always pass --variables unmanaged, so IaC never takes ownership of your secrets.
  • Compare with the old file, character for character. Start command, pre-deploy command, healthcheck, builder. One missing & in a start command is a dead worker.
  • Check what is really running. A start command in the preview but not in the old file came from the dashboard, which is what runs today. Confirm it in the deploy logs before keeping it.
  • Check the partial name. It must match [a-zA-Z0-9._-]. A service name with a space produces one Railway then rejects.
# preview only, scoped to one service
railway config migrate --variables unmanaged \
  --service "web" --show > scratch/preview.ts

# secret-shaped words? print the keyword, never the line
grep -noiE '[A-Za-z_]*(secret|token|password|api_key)' \
  scratch/preview.ts

# write the file once the preview is right
railway config migrate --variables unmanaged \
  --service "web" --apply

# a good result, for one service:
export const partial = "web";
export default defineRailway(() => {
  const web = service("web", {
    source: github("owner/repo", { branch: "main" }),
    build: { builder: "NIXPACKS" },
    start: "bash start.sh",
    healthcheck: "/health",
  });
  return project("my-project", {
    variables: { managed: false },
    resources: [web],
  });
});

Gate: the file declares only this repository’s services, under one valid partial, and every setting matches what runs today.

Phase 2 · the gate

Plan until only additions remain.

  • Write the plan to a file and read all of it. The summary line can say “0 to destroy” while a volume detach sits below it.
  • Volume detach: add the volume from a scratch-folder pull, as shown above.
  • Healthcheck on a worker: a root file’s healthcheck lands on every service from the repository. A queue worker with no HTTP server never answers it, and every deploy fails. Remove it for workers.
  • Variables from a toml: a [environments.production.variables] block vanishes with the file. Set each one on the service first, with the same value and --skip-deploys, then check by name only.
  • Restart policy: the generator may leave it out. Add deploy: { restartPolicyType: "ALWAYS" } if the old file set it; the plan will show it.
  • One repository, two projects: branch on ctx.projectName and plan against each project in turn.
railway config plan > scratch/plan.txt 2>&1
grep -E 'Plan:|└|!|destroy|→ null' scratch/plan.txt

# variables a toml used to set: names only
railway variable set APP_DB_PATH=/data/app.db \
  --service "web" --skip-deploys

# one repository, two projects
export default defineRailway((ctx) => {
  if (ctx.projectName === "project-b") {
    return project("project-b", { ... });
  }
  return project("project-a", { ... });
});

# Dockerfile builds: the builder only sticks
# with a path next to it
build: { builder: "DOCKERFILE",
         dockerfilePath: "Dockerfile" },

Gate: every line is null → value or a change you asked for, nothing is destructive, and only this repository’s services appear.

Phase 3 · production settings

Cut over, apply, re-plan.

  • Cutover clears the stored config-file path. When no path is stored, which is common, it prints “Nothing to do”. That is fine: the root file is auto-detected until you delete it.
  • Apply with --yes, never --confirm-destructive. Without that flag Railway refuses destructive changes for you, a second net under phase 2.
  • Re-plan. It must say “Your Railway configuration is already up to date.” If a change keeps reappearing, it did not persist: a Dockerfile builder without dockerfilePath is the usual cause.
  • Do not expect a redeploy. When the value equals what the old file already provided, apply often changes the settings without deploying. That is good: phase 4 does the proving.
railway config migrate cutover
railway config migrate status
# ✓ No services in production read Config as Code.

railway config apply --yes
#   ✓ service.<id>

railway config plan
# ✓ Your Railway configuration is already up to date.

# if you must undo before deleting the file:
railway config migrate undo

Gate: plan is clean, and the API shows the settings stored on the service.

Phase 4 · live traffic

Delete the file, prove it with a fresh build.

  • Only after apply. Railway warns: delete the file while a path is still stored and the next build fails looking for it.
  • Pin what you import. This push is a fresh build that resolves dependencies again. A package your code imports only through another library’s optional path can vanish. A common one: Celery on Redis needs packaging, which kombu’s Redis transport imports and nothing declares. Pin it first.
  • Stage only your files. git rm the old file, git add .railway/railway.ts, nothing else. A sparse checkout needs git add --sparse.
  • SUCCESS is not enough. A container can pass its healthcheck and then lose a worker. Read the logs for every process the start command launches.
  • Watch patterns can skip the proof. A service that only deploys on certain paths shows SKIPPED. Its proving deploy is the next matching push, or a redeploy you trigger.
git rm railway.json
git add .railway/railway.ts
git commit -m "Migrate Railway config to IaC"
git push

# poll until the new deployment finishes
railway deployment list -s "web" --json   # every 20 s

# every process from the start command, by name
railway logs -s "web" --deployment --lines 400 | grep -E \
  'Listening at|celery@.* ready|beat: Starting|ModuleNotFoundError|Traceback'

# Dockerfile service? the build log, not the API field
railway logs -s "web" --build --lines 400 | \
  grep -ci dockerfile

Gate: the build without the old file succeeds, every process is up, the health endpoint answers, and every volume is still attached.

Phase 5

Record, then the next repository.

For each repository, note what you moved, anything that now differs from before (a restart policy that fell back to Railway’s default of ten retries, for instance), and anything you dropped on purpose, like a dead config file or a worker healthcheck. Delete the scratch folders. Then run phases 1 to 5 for the next repository. When the list is done, check GitHub once more: no live repository should still carry a railway.json or railway.toml.


The checklist

Every test the agent runs.

Eighteen checks per repository. None of them prints a secret.

WhenTestHowPass
Before Every live service is in scope Services from the Railway API, files checked on GitHub per repository Nothing missed
Before Each file’s settings are known Decode each railway.json or railway.toml Listed per service
Before Stored settings are known railwayConfigFile, startCommand, builder, healthcheck, restart policy per service Differences noted
Before Volumes are known volumeInstances per service: name and mount path Listed
Before Imports are pinned Celery on Redis declares packaging; nothing imported comes only transitively Pinned
Generate Scope is this repository Services in the file are the ones this repository deploys Nothing else
Generate Partial name is valid export const partial matches [a-zA-Z0-9._-] Valid
Generate Start command matches Character-for-character against the old file, or the running one Identical
Generate No secret in the file Grep for secret-shaped words, print the keyword only Only variable names
Plan Only additions Every line null → value, or a change you asked for True
Plan Nothing destructive No “destructive change”, no volume → null, 0 to destroy 0
Apply Settings persisted railway config plan after apply Already up to date
Prove Fresh build succeeds Deployment after deleting the old file SUCCESS
Prove Every process is running Deploy logs: web server, worker, scheduler, each by name All present
Prove No import errors Deploy logs: ModuleNotFoundError, Traceback None
Prove Right builder was used Build log mentions the Dockerfile, for Dockerfile services Yes
Prove Volumes still attached volumeInstances per service after the deploy Same as before
After No config files left GitHub check across every live repository None

Failure modes

What can go wrong, and the fix.

A volume is detached.

The generated file omitted it and the plan was applied anyway. Prevented by the plan gate. If it happens, stop deploying, check in the dashboard that the volume still exists, and re-attach it to the same mount path before anything writes to the service.

One repository claims the project.

A merged, partial-less file was applied. It now owns every resource it declared and can delete them later. Use railway config partials list, then release or transfer what it should not own.

A worker crash-loops after the push.

The fresh build dropped a dependency, the worker dies on import, and a start command using wait -n takes the web server down with it. Read the traceback, pin the package, push. The old deployment is already gone, so be quick.

A worker deploy fails its healthcheck.

A root file’s /health landed on a service with no HTTP server. Remove the healthcheck from that service and apply. A failed deploy never replaced the running one, so nothing was down.

A setting will not stick.

Plan keeps showing the same change after apply. For a Dockerfile builder, add dockerfilePath. Otherwise read the IaC reference for the exact field.

Toml variables disappeared.

The [environments.*.variables] block was not copied to the service before the file was deleted. Set them on the service and redeploy.

A dead file comes back to life.

A second config file that no service ever read gets migrated anyway, and its old build command or start command takes effect for the first time. Check railwayConfigFile before migrating any non-root file.

The proving deploy was skipped.

Watch patterns did not match the deleted file. Nothing is wrong yet, but nothing is proven either. Trigger a redeploy and verify.

Someone else’s work got committed.

git add -A in a repository with uncommitted changes. Stage files by name, always.

The prompt

Hand this to your coding agent.

Fill in the parts in square brackets. The agent inventories everything first, reports, and waits for your go-ahead before it changes any production setting.

You are going to move my Railway services from Config as Code (railway.json / railway.toml) to Infrastructure as Code (.railway/railway.ts), before Railway stops reading the old files.

Railway workspace(s): [workspace name(s)]
Local folder with my repositories: [path]
Quiet windows to avoid: [scheduled jobs, by service and time, or "none"]

Goal: every live service keeps exactly the settings it runs with today (start command, pre-deploy command, builder, healthcheck, restart policy, volumes, variables), now stored on the service; no live repository still carries railway.json or railway.toml; no volume detached; no resource claimed by the wrong repository.

HARD RULES
- Never print, log or paste a secret. Print variable names, never values. Always pass --variables unmanaged to railway config migrate and pull.
- Never apply a plan that is destructive: no "destroy", no "destructive change", no volume or setting going to null unless I asked for it. Never pass --confirm-destructive.
- Never apply a generated file that has no "export const partial" or declares services this repository does not deploy.
- Run railway config pull only in a scratch folder outside every repository.
- Delete railway.json / railway.toml only after apply and a clean re-plan.
- Stage files by name. Never git add -A. Do not commit my uncommitted changes.
- Work read-only until I approve. Stop and wait after Phase 0, and whenever a check fails.
- If a command is denied, do not look for a workaround. Tell me.

PHASE 0 - INVENTORY (read-only, once)
1. Confirm the Railway CLI is current and logged in, and gh is signed in.
2. List every service in the workspace(s) with its project, environment and source repository.
3. For every source repository, check on GitHub whether railway.json or railway.toml exists. Map local checkouts to repositories; note live repositories with no checkout and checkouts with no live service.
4. For each file, decode what it sets. For each service, read what is stored: railwayConfigFile, startCommand, builder, healthcheckPath, restartPolicyType and restartPolicyMaxRetries, and its volumes with mount paths.
5. Note every repository that deploys more than one service or to more than one project, every second config file and whether any service stores its path, and every toml that sets variables.
6. For every service whose start command runs Celery (or another worker) on Redis, check that packaging is declared in its dependencies.
7. Rank services: critical (start command runs several processes, or a pre-deploy command), high (start command, builder or toml variables the app needs), medium (healthcheck and restart policy only).
Then report a table and an order, and wait.

PER REPOSITORY, IN RISK ORDER
8. Pull the repository. Link it: railway link --project  --environment production --service .
9. Preview: railway config migrate --variables unmanaged [--service ] --show into a scratch file. Grep it for secret-shaped words and print only the keyword. If the repository deploys several services, preview each with --service and merge them by hand into one file with one partial. If it deploys to several projects, branch on ctx.projectName.
10. Compare every setting with the old file and with what runs today (deploy logs). The start command must match character for character. Remove a healthcheck from any service that has no HTTP server. Do not migrate settings from a file no service reads. Fix a partial name that is not [a-zA-Z0-9._-].
11. Write the file (--apply). Pin missing imports (packaging for Celery on Redis).
12. railway config plan, saved to a file, read in full. For each volume detach, run railway config pull in a scratch folder linked to the same service, copy the volume(...) declaration and volumeMounts into the file, add the volume to resources, and plan again. For a Dockerfile builder, include dockerfilePath. For toml variables, set each on the service with --skip-deploys first and confirm by name.
13. When the plan contains only additions and nothing destructive, run railway config migrate cutover, then railway config apply --yes, then railway config plan. It must say the configuration is up to date.
14. git rm the old file, git add .railway/railway.ts (and any dependency file you changed), commit, push.
15. Watch the new deployment until it finishes. If it is SKIPPED by watch patterns, tell me and trigger a redeploy.
16. Verify: SUCCESS; every process from the start command visible in the deploy logs; no ModuleNotFoundError or Traceback; the health endpoint answers; volumes still attached; for Dockerfile services, the build log shows the Dockerfile. If a check fails, stop, report, and fix before the next repository.

FINISH
17. Check GitHub again: no live repository carries railway.json or railway.toml, and each has .railway/railway.ts.
18. Give me a short report: per service what moved, what differs from before, what you dropped on purpose, any failed deploy or downtime with timestamps, and anything left for me.

Works with any agent that can run shell commands: Claude Code, Codex, Cursor and the like. Run it with command approval switched on.


Questions

The short answers.

When does Railway stop reading railway.json?

Railway’s CLI warns that existing Config as Code files keep working until 1 December 2026; its documentation gives a hard cutoff of 1 January 2027. Plan for the earlier date. After the cutoff, a service whose start command, healthcheck or builder lived only in railway.json or railway.toml deploys on Railway’s defaults instead, and nothing warns you at deploy time.

What breaks if I do nothing?

Whatever the file was setting. A web app usually still boots on defaults, which is exactly the danger: a start command that also launched a background worker or a scheduler silently drops them, a pre-deploy migration stops running, a healthcheck disappears, and a Dockerfile build can quietly switch to Railpack. The site looks fine; the jobs behind it stop.

Is railway config migrate enough on its own?

It writes a good first draft, and in simple cases the draft is correct. It is not enough to apply blind. In real projects it can leave out volume mounts, produce a whole-project file when a repository holds two config files, attach one file’s healthcheck to every service built from the repository, and generate a partial name Railway then rejects. Every one of those shows up in railway config plan. The plan is the gate.

Will migrating cause downtime?

Usually none. railway config apply writes settings to the service; when the value equals what railway.json already provided, it may not even redeploy. The deploy that matters is the one after you push the deletion of railway.json: it builds fresh, without the old file. A failed deploy never replaces the running one, so the risk is a build that succeeds and then crashes, which is why the agent reads the logs of every process, not just the deploy status.

Do I need to npm install railway?

Railway’s docs say to install the package that matches your authoring file. In our runs the CLI evaluated .railway/railway.ts without it, so a Python or Go repository does not need a package.json just for this. Install it as a dev dependency if you want editor types, or if you will run plan and apply from GitHub Actions, where the action needs it.

One repository deploys several services. One file or several?

One file per repository, with one named partial covering every service that repository deploys. If the repository deploys to more than one Railway project, the same file can branch on ctx.projectName and declare the right services for each; you link and apply once per project.

Is it safe to let an AI agent change production deploy settings?

With rules, yes. The agent works read-only until you approve, never applies a plan that destroys anything, stages only the files it changed, and runs in a mode where you approve each command. The plan output is short and human-readable, so you can check every change yourself before it lands.