use-railway by railwayapp/railway-skills
npx skills add https://github.com/railwayapp/railway-skills --skill use-railwayRailway 以层级结构组织基础设施:
production、staging)。每个环境都有自己的变量、配置和部署历史。大多数 CLI 命令在已链接的项目/环境/服务上下文中操作。使用 railway status --json 查看上下文,并使用 --project、--environment、--service 标志来覆盖。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
用户经常粘贴 Railway 仪表板 URL。在执行任何操作之前提取 ID:
https://railway.com/project/<PROJECT_ID>/service/<SERVICE_ID>?environmentId=<ENV_ID>
https://railway.com/project/<PROJECT_ID>/service/<SERVICE_ID>
URL 始终包含 projectId 和 serviceId。它可能将 environmentId 作为查询参数包含。如果缺少环境 ID 且用户通过名称(例如 "production")指定了环境,则解析它:
scripts/railway-api.sh \
'query getProject($id: String!) {
project(id: $id) {
environments { edges { node { id name } } }
}
}' \
'{"id": "<PROJECT_ID>"}'
匹配环境名称(不区分大小写)以获取 environmentId。
优先向 CLI 命令(--project、--environment、--service)和脚本(--project-id、--environment-id、--service-id)传递显式 ID,而不是运行 railway link。这可以避免修改全局状态并且速度更快。
在任何变更操作之前,验证上下文:
command -v railway # CLI 已安装
railway whoami --json # 已认证
railway --version # 检查 CLI 版本
上下文解析 — URL ID 始终优先:
railway status --json — 它返回的是本地链接的项目,通常不相关。railway status --json 来获取链接的项目/环境/服务。如果缺少 CLI,请引导用户安装它。
bash <(curl -fsSL cli.new) # Shell 脚本 (macOS, Linux, Windows via WSL)
brew install railway # Homebrew (macOS)
npm i -g @railway/cli # npm (macOS, Linux, Windows). 需要 Node.js 版本 16 或更高。
如果未认证,运行 railway login。如果未链接且未提供 URL,运行 railway link --project <id-or-name>。
如果命令无法识别(例如 railway environment edit),CLI 可能已过时。使用以下命令升级:
railway upgrade
这些操作非常频繁,无需加载参考即可处理:
railway status --json # 当前上下文
railway whoami --json # 认证和工作区信息
railway project list --json # 列出项目
railway service status --all --json # 当前上下文中的所有服务
railway variable list --service <svc> --json # 列出变量
railway variable set KEY=value --service <svc> # 设置变量
railway logs --service <svc> --lines 200 --json # 最近日志
railway up --detach -m "<summary>" # 部署当前目录
railway bucket list --json # 列出当前环境中的存储桶
railway bucket info --bucket <name> --json # 存储桶存储和对象计数
railway bucket credentials --bucket <name> --json # S3 兼容凭证
对于超出快速操作范围的任何内容,加载与用户意图匹配的参考。仅加载所需内容,通常一个参考就足够,最多两个。
| 意图 | 参考 | 用途 |
|---|---|---|
| 分析数据库 ("analyze <url>", "analyze db", "analyze database", "analyze service", "introspect", "check my postgres/redis/mysql/mongo") | analyze-db.md | 数据库内省和性能分析。analyze-db.md 会引导你到特定数据库的参考。当提供了指向数据库服务的 Railway URL 并附带 "analyze" 时,这优先于 status/operate 路由。 |
| 创建或连接资源 | setup.md | 项目、服务、数据库、存储桶、模板、工作区 |
| 发布代码或管理版本 | deploy.md | 部署、重新部署、重启、构建配置、单体仓库、Dockerfile |
| 更改配置 | configure.md | 环境、变量、配置补丁、域名、网络 |
| 检查健康状况或调试故障 | operate.md | 状态、日志、指标、构建/运行时故障排查、恢复 |
| 从 API、文档或社区请求 | request.md | Railway GraphQL API 查询/变更、指标查询、Central Station、官方文档 |
如果请求涉及两个领域(例如,"deploy and then check if it's healthy"),则加载两个参考并组合成一个响应。
scripts/railway-api.sh。--json 输出以便可靠解析。这些命令会修改数据库状态,需要用户在其终端中直接运行。不要用 Bash 执行这些命令。而是显示命令并要求用户运行它。
| 命令 | 为何仅限用户执行 |
|---|---|
python3 scripts/enable-pg-stats.py --service <name> | 修改 shared_preload_libraries,可能重启数据库 |
python3 scripts/pg-extensions.py --service <name> install <ext> | 安装数据库扩展 |
python3 scripts/pg-extensions.py --service <name> uninstall <ext> | 移除数据库扩展 |
ALTER SYSTEM SET ... | 更改 PostgreSQL 配置 |
DROP EXTENSION ... | 移除数据库扩展 |
CREATE EXTENSION ... | 安装数据库扩展 |
当需要这些操作时:
多步骤工作流遵循自然的链条:
组合时,返回一个涵盖所有步骤的统一响应。不要要求用户分别调用每个步骤。
当用户想要创建或部署某些内容时,根据当前上下文确定正确的操作:
railway status --json。railway add --service <name>)。除非用户明确说 "new project" 或 "separate project",否则不要创建新项目。cd .. && railway status --json)。
rootDirectory 设置为子应用路径。railway list --json 并查找与目录名称匹配的项目。
railway link --project <name>)。railway init --name <name>)。railway whoami --json 中的名称进行匹配。命名启发式 : 像 "flappy-bird" 或 "my-api" 这样的应用名称是服务名称,而不是项目名称。使用目录或仓库名称作为项目名。
对于所有操作响应,返回:
保持输出简洁。仅当有助于用户理解发生了什么时才包含命令证据。
每周安装量
1.4K
仓库
GitHub 星标
209
首次出现
2026年2月25日
安全审计
安装于
opencode1.4K
codex1.3K
github-copilot1.3K
kimi-cli1.3K
gemini-cli1.3K
amp1.3K
Railway organizes infrastructure in a hierarchy:
production, staging). Each environment has its own variables, config, and deployment history.Most CLI commands operate on the linked project/environment/service context. Use railway status --json to see the context, and --project, --environment, --service flags to override.
Users often paste Railway dashboard URLs. Extract IDs before doing anything else:
https://railway.com/project/<PROJECT_ID>/service/<SERVICE_ID>?environmentId=<ENV_ID>
https://railway.com/project/<PROJECT_ID>/service/<SERVICE_ID>
The URL always contains projectId and serviceId. It may contain environmentId as a query parameter. If the environment ID is missing and the user specifies an environment by name (e.g., "production"), resolve it:
scripts/railway-api.sh \
'query getProject($id: String!) {
project(id: $id) {
environments { edges { node { id name } } }
}
}' \
'{"id": "<PROJECT_ID>"}'
Match the environment name (case-insensitive) to get the environmentId.
Prefer passing explicit IDs to CLI commands (--project, --environment, --service) and scripts (--project-id, --environment-id, --service-id) instead of running railway link. This avoids modifying global state and is faster.
Before any mutation, verify context:
command -v railway # CLI installed
railway whoami --json # authenticated
railway --version # check CLI version
Context resolution — URL IDs always win:
railway status --json — it returns the locally linked project, which is usually unrelated.railway status --json for the linked project/environment/service.If the CLI is missing, guide the user to install it.
bash <(curl -fsSL cli.new) # Shell script (macOS, Linux, Windows via WSL)
brew install railway # Homebrew (macOS)
npm i -g @railway/cli # npm (macOS, Linux, Windows). Requires Node.js version 16 or higher.
If not authenticated, run railway login. If not linked and no URL was provided, run railway link --project <id-or-name>.
If a command is not recognized (for example, railway environment edit), the CLI may be outdated. Upgrade with:
railway upgrade
These are frequent enough to handle without loading a reference:
railway status --json # current context
railway whoami --json # auth and workspace info
railway project list --json # list projects
railway service status --all --json # all services in current context
railway variable list --service <svc> --json # list variables
railway variable set KEY=value --service <svc> # set a variable
railway logs --service <svc> --lines 200 --json # recent logs
railway up --detach -m "<summary>" # deploy current directory
railway bucket list --json # list buckets in current environment
railway bucket info --bucket <name> --json # bucket storage and object count
railway bucket credentials --bucket <name> --json # S3-compatible credentials
For anything beyond quick operations, load the reference that matches the user's intent. Load only what you need, one reference is usually enough, two at most.
| Intent | Reference | Use for |
|---|---|---|
| Analyze a database ("analyze <url>", "analyze db", "analyze database", "analyze service", "introspect", "check my postgres/redis/mysql/mongo") | analyze-db.md | Database introspection and performance analysis. analyze-db.md directs you to the DB-specific reference. This takes priority over the status/operate routes when a Railway URL to a database service is provided alongside "analyze". |
| Create or connect resources | setup.md | Projects, services, databases, buckets, templates, workspaces |
| Ship code or manage releases | deploy.md | Deploy, redeploy, restart, build config, monorepo, Dockerfile |
| Change configuration | configure.md | Environments, variables, config patches, domains, networking |
| Check health or debug failures |
If the request spans two areas (for example, "deploy and then check if it's healthy"), load both references and compose one response.
scripts/railway-api.sh for operations the CLI doesn't expose.--json output where available for reliable parsing.These commands modify database state and require the user to run them directly in their terminal. Do NOT execute these with Bash. Instead, show the command and ask the user to run it.
| Command | Why user-only |
|---|---|
python3 scripts/enable-pg-stats.py --service <name> | Modifies shared_preload_libraries, may restart database |
python3 scripts/pg-extensions.py --service <name> install <ext> | Installs database extension |
python3 scripts/pg-extensions.py --service <name> uninstall <ext> | Removes database extension |
ALTER SYSTEM SET ... | Changes PostgreSQL configuration |
DROP EXTENSION ... | Removes database extension |
When these operations are needed:
Multi-step workflows follow natural chains:
When composing, return one unified response covering all steps. Don't ask the user to invoke each step separately.
When the user wants to create or deploy something, determine the right action from current context:
railway status --json in the current directory.railway add --service <name>). Do not create a new project unless the user explicitly says "new project" or "separate project".cd .. && railway status --json).
rootDirectory to the sub-app path.railway list --json and look for a project matching the directory name.
railway link --project <name>).railway init --name <name>).Naming heuristic : app names like "flappy-bird" or "my-api" are service names, not project names. Use the directory or repo name for the project.
For all operational responses, return:
Keep output concise. Include command evidence only when it helps the user understand what happened.
Weekly Installs
1.4K
Repository
GitHub Stars
209
First Seen
Feb 25, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykFail
Installed on
opencode1.4K
codex1.3K
github-copilot1.3K
kimi-cli1.3K
gemini-cli1.3K
amp1.3K
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
102,200 周安装
| operate.md |
| Status, logs, metrics, build/runtime triage, recovery |
| Request from API, docs, or community | request.md | Railway GraphQL API queries/mutations, metrics queries, Central Station, official docs |
CREATE EXTENSION ...| Installs database extension |
railway whoami --json.