railway-environment by davila7/claude-code-templates
npx skills add https://github.com/davila7/claude-code-templates --skill railway-environment查询、暂存和应用 Railway 环境的配置更改。
关键提示: 通过 bash 运行 GraphQL 查询时,必须使用 heredoc 包装,以防止 shell 转义问题:
bash <<'SCRIPT'
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh 'query ...' '{"var": "value"}'
SCRIPT
如果没有 heredoc 包装,多行命令会中断,并且 GraphQL 非空类型中的感叹号会被转义,导致查询失败。
在链接的项目中创建新环境:
railway environment new <name>
复制现有环境:
railway environment new staging --duplicate production
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
使用特定于服务的变量:
railway environment new staging --duplicate production --service-variable api PORT=3001
将不同的环境链接到当前目录:
railway environment <name>
或通过 ID:
railway environment <environment-id>
railway status --json
提取:
project.id - 用于服务查找environment.id - 用于变更操作service.id - 如果用户未指定服务,则为默认服务如果用户按名称指定服务,则查询项目服务:
query projectServices($projectId: String!) {
project(id: $projectId) {
services {
edges {
node {
id
name
}
}
}
}
}
匹配服务名称(不区分大小写)以获取服务 ID。
获取当前环境配置和暂存的更改。
query environmentConfig($environmentId: String!) {
environment(id: $environmentId) {
id
config(decryptVariables: false)
serviceInstances {
edges {
node {
id
serviceId
}
}
}
}
environmentStagedChanges(environmentId: $environmentId) {
id
patch(decryptVariables: false)
}
}
示例:
bash <<'SCRIPT'
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
'query envConfig($envId: String!) {
environment(id: $envId) { id config(decryptVariables: false) }
environmentStagedChanges(environmentId: $envId) { id patch(decryptVariables: false) }
}' \
'{"envId": "ENV_ID"}'
SCRIPT
config 字段包含当前配置:
{
"services": {
"<serviceId>": {
"source": { "repo": "...", "branch": "main" },
"build": { "buildCommand": "npm run build", "builder": "NIXPACKS" },
"deploy": {
"startCommand": "npm start",
"multiRegionConfig": { "us-west2": { "numReplicas": 1 } }
},
"variables": { "NODE_ENV": { "value": "production" } },
"networking": { "serviceDomains": {}, "customDomains": {} }
}
},
"sharedVariables": { "DATABASE_URL": { "value": "..." } }
}
environmentStagedChanges 中的 patch 字段包含待处理的更改。有效配置是基础 config 与暂存 patch 合并的结果。
有关完整字段参考,请参阅 reference/environment-config.md。
有关变量语法和服务连接模式,请参阅 reference/variables.md。
上述 GraphQL 查询返回的是未渲染的变量 - 模板语法如 ${{shared.DOMAIN}} 会被保留。这对于管理/编辑是正确的。
要查看运行时出现的渲染后的(已解析的)值:
# 当前链接的服务
railway variables --json
# 特定服务
railway variables --service <service-name> --json
使用时机:
通过 environmentStageChanges 变更操作暂存配置更改。使用 merge: true 自动与现有的暂存更改合并。
mutation stageEnvironmentChanges(
$environmentId: String!
$input: EnvironmentConfig!
$merge: Boolean
) {
environmentStageChanges(
environmentId: $environmentId
input: $input
merge: $merge
) {
id
}
}
重要提示: 始终使用变量(而不是内联输入),因为服务 ID 是 UUID,不能用作未加引号的 GraphQL 对象键。
示例:
bash <<'SCRIPT'
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
'mutation stageChanges($environmentId: String!, $input: EnvironmentConfig!, $merge: Boolean) {
environmentStageChanges(environmentId: $environmentId, input: $input, merge: $merge) { id }
}' \
'{"environmentId": "ENV_ID", "input": {"services": {"SERVICE_ID": {"build": {"buildCommand": "npm run build"}}}}, "merge": true}'
SCRIPT
使用 isDeleted: true:
bash <<'SCRIPT'
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
'mutation stageChanges($environmentId: String!, $input: EnvironmentConfig!, $merge: Boolean) {
environmentStageChanges(environmentId: $environmentId, input: $input, merge: $merge) { id }
}' \
'{"environmentId": "ENV_ID", "input": {"services": {"SERVICE_ID": {"isDeleted": true}}}, "merge": true}'
SCRIPT
对于应立即部署的单个更改,使用 environmentPatchCommit 在一次调用中暂存和应用。
mutation environmentPatchCommit(
$environmentId: String!
$patch: EnvironmentConfig
$commitMessage: String
) {
environmentPatchCommit(
environmentId: $environmentId
patch: $patch
commitMessage: $commitMessage
)
}
示例:
bash <<'SCRIPT'
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
'mutation patchCommit($environmentId: String!, $patch: EnvironmentConfig, $commitMessage: String) {
environmentPatchCommit(environmentId: $environmentId, patch: $patch, commitMessage: $commitMessage)
}' \
'{"environmentId": "ENV_ID", "patch": {"services": {"SERVICE_ID": {"variables": {"API_KEY": {"value": "secret"}}}}}, "commitMessage": "add API_KEY"}'
SCRIPT
使用时机: 单个更改,无需批处理,用户希望立即部署。
不使用时机: 需要批处理的多个相关更改,或者用户说“仅暂存”/“暂时不要部署”。
提交暂存的更改并触发部署。
注意: 没有 railway apply CLI 命令。使用下面的变更操作或将用户引导至 Web 界面。
变更操作名称:environmentPatchCommitStaged
mutation environmentPatchCommitStaged(
$environmentId: String!
$message: String
$skipDeploys: Boolean
) {
environmentPatchCommitStaged(
environmentId: $environmentId
commitMessage: $message
skipDeploys: $skipDeploys
)
}
示例:
bash <<'SCRIPT'
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
'mutation commitStaged($environmentId: String!, $message: String) {
environmentPatchCommitStaged(environmentId: $environmentId, commitMessage: $message)
}' \
'{"environmentId": "ENV_ID", "message": "add API_KEY variable"}'
SCRIPT
| 字段 | 类型 | 默认值 | 描述 |
|---|---|---|---|
environmentId | String! | - | 来自状态的 Environment ID |
message | String | null | 更改的简短描述 |
skipDeploys | Boolean | false | 跳过部署(仅在用户明确要求时) |
保持非常简短 - 最多一句话。示例:
如果没有有意义的描述,请留空。
始终部署,除非用户明确要求跳过。仅当用户说“应用但不部署”、“提交但不部署”或“跳过部署”时才设置 skipDeploys: true。
成功时返回工作流 ID(字符串)。
默认情况下,立即应用更改。
单个更改: 使用 environmentPatchCommit 在一次调用中暂存和应用。
多个更改或批处理: 对每个更改使用 environmentStageChanges 并设置 merge: true,然后使用 environmentPatchCommitStaged 来应用。
当您不自动应用时,请告知用户:
更改已暂存。在此处应用它们:https://railway.com/project/{projectId} 或者要求我应用它们。
从 railway status --json → project.id 获取 projectId
Service "foo" not found in project. Available services: api, web, worker
No patch to apply
没有暂存的更改可提交。请先暂存更改。
常见问题:
buildCommand 和 startCommand 不能相同buildCommand 仅对 NIXPACKS 构建器有效dockerfilePath 仅对 DOCKERFILE 构建器有效You don't have permission to modify this environment. Check your Railway role.
No project linked. Run `railway link` to link a project.
每周安装数
156
仓库
GitHub 星标数
23.4K
首次出现
2026 年 1 月 21 日
安全审计
安装于
claude-code133
opencode124
gemini-cli122
cursor117
antigravity109
codex108
Query, stage, and apply configuration changes for Railway environments.
CRITICAL: When running GraphQL queries via bash, you MUST wrap in heredoc to prevent shell escaping issues:
bash <<'SCRIPT'
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh 'query ...' '{"var": "value"}'
SCRIPT
Without the heredoc wrapper, multi-line commands break and exclamation marks in GraphQL non-null types get escaped, causing query failures.
Create a new environment in the linked project:
railway environment new <name>
Duplicate an existing environment:
railway environment new staging --duplicate production
With service-specific variables:
railway environment new staging --duplicate production --service-variable api PORT=3001
Link a different environment to the current directory:
railway environment <name>
Or by ID:
railway environment <environment-id>
railway status --json
Extract:
project.id - for service lookupenvironment.id - for the mutationsservice.id - default service if user doesn't specify oneIf user specifies a service by name, query project services:
query projectServices($projectId: String!) {
project(id: $projectId) {
services {
edges {
node {
id
name
}
}
}
}
}
Match the service name (case-insensitive) to get the service ID.
Fetch current environment configuration and staged changes.
query environmentConfig($environmentId: String!) {
environment(id: $environmentId) {
id
config(decryptVariables: false)
serviceInstances {
edges {
node {
id
serviceId
}
}
}
}
environmentStagedChanges(environmentId: $environmentId) {
id
patch(decryptVariables: false)
}
}
Example:
bash <<'SCRIPT'
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
'query envConfig($envId: String!) {
environment(id: $envId) { id config(decryptVariables: false) }
environmentStagedChanges(environmentId: $envId) { id patch(decryptVariables: false) }
}' \
'{"envId": "ENV_ID"}'
SCRIPT
The config field contains current configuration:
{
"services": {
"<serviceId>": {
"source": { "repo": "...", "branch": "main" },
"build": { "buildCommand": "npm run build", "builder": "NIXPACKS" },
"deploy": {
"startCommand": "npm start",
"multiRegionConfig": { "us-west2": { "numReplicas": 1 } }
},
"variables": { "NODE_ENV": { "value": "production" } },
"networking": { "serviceDomains": {}, "customDomains": {} }
}
},
"sharedVariables": { "DATABASE_URL": { "value": "..." } }
}
The patch field in environmentStagedChanges contains pending changes. The effective configuration is the base config merged with the staged patch.
For complete field reference, see reference/environment-config.md.
For variable syntax and service wiring patterns, see reference/variables.md.
The GraphQL queries above return unrendered variables - template syntax like ${{shared.DOMAIN}} is preserved. This is correct for management/editing.
To see rendered (resolved) values as they appear at runtime:
# Current linked service
railway variables --json
# Specific service
railway variables --service <service-name> --json
When to use:
Stage configuration changes via the environmentStageChanges mutation. Use merge: true to automatically merge with existing staged changes.
mutation stageEnvironmentChanges(
$environmentId: String!
$input: EnvironmentConfig!
$merge: Boolean
) {
environmentStageChanges(
environmentId: $environmentId
input: $input
merge: $merge
) {
id
}
}
Important: Always use variables (not inline input) because service IDs are UUIDs which can't be used as unquoted GraphQL object keys.
Example:
bash <<'SCRIPT'
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
'mutation stageChanges($environmentId: String!, $input: EnvironmentConfig!, $merge: Boolean) {
environmentStageChanges(environmentId: $environmentId, input: $input, merge: $merge) { id }
}' \
'{"environmentId": "ENV_ID", "input": {"services": {"SERVICE_ID": {"build": {"buildCommand": "npm run build"}}}}, "merge": true}'
SCRIPT
Use isDeleted: true:
bash <<'SCRIPT'
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
'mutation stageChanges($environmentId: String!, $input: EnvironmentConfig!, $merge: Boolean) {
environmentStageChanges(environmentId: $environmentId, input: $input, merge: $merge) { id }
}' \
'{"environmentId": "ENV_ID", "input": {"services": {"SERVICE_ID": {"isDeleted": true}}}, "merge": true}'
SCRIPT
For single changes that should deploy right away, use environmentPatchCommit to stage and apply in one call.
mutation environmentPatchCommit(
$environmentId: String!
$patch: EnvironmentConfig
$commitMessage: String
) {
environmentPatchCommit(
environmentId: $environmentId
patch: $patch
commitMessage: $commitMessage
)
}
Example:
bash <<'SCRIPT'
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
'mutation patchCommit($environmentId: String!, $patch: EnvironmentConfig, $commitMessage: String) {
environmentPatchCommit(environmentId: $environmentId, patch: $patch, commitMessage: $commitMessage)
}' \
'{"environmentId": "ENV_ID", "patch": {"services": {"SERVICE_ID": {"variables": {"API_KEY": {"value": "secret"}}}}}, "commitMessage": "add API_KEY"}'
SCRIPT
When to use: Single change, no need to batch, user wants immediate deployment.
When NOT to use: Multiple related changes to batch, or user says "stage only" / "don't deploy yet".
Commit staged changes and trigger deployments.
Note: There is no railway apply CLI command. Use the mutation below or direct users to the web UI.
Mutation name:environmentPatchCommitStaged
mutation environmentPatchCommitStaged(
$environmentId: String!
$message: String
$skipDeploys: Boolean
) {
environmentPatchCommitStaged(
environmentId: $environmentId
commitMessage: $message
skipDeploys: $skipDeploys
)
}
Example:
bash <<'SCRIPT'
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
'mutation commitStaged($environmentId: String!, $message: String) {
environmentPatchCommitStaged(environmentId: $environmentId, commitMessage: $message)
}' \
'{"environmentId": "ENV_ID", "message": "add API_KEY variable"}'
SCRIPT
| Field | Type | Default | Description |
|---|---|---|---|
environmentId | String! | - | Environment ID from status |
message | String | null | Short description of changes |
skipDeploys | Boolean | false | Skip deploys (only if user explicitly asks) |
Keep very short - one sentence max. Examples:
Leave empty if no meaningful description.
Always deploy unless user explicitly asks to skip. Only set skipDeploys: true if user says "apply without deploying", "commit but don't deploy", or "skip deploys".
Returns a workflow ID (string) on success.
By default, apply changes immediately.
Single change: Use environmentPatchCommit to stage and apply in one call.
Multiple changes or batching: Use environmentStageChanges with merge: true for each change, then environmentPatchCommitStaged to apply.
When you don't auto-apply, tell the user:
Changes staged. Apply them at: https://railway.com/project/{projectId} Or ask me to apply them.
Get projectId from railway status --json → project.id
Service "foo" not found in project. Available services: api, web, worker
No patch to apply
There are no staged changes to commit. Stage changes first.
Common issues:
buildCommand and startCommand cannot be identicalbuildCommand only valid with NIXPACKS builderdockerfilePath only valid with DOCKERFILE builderYou don't have permission to modify this environment. Check your Railway role.
No project linked. Run `railway link` to link a project.
Weekly Installs
156
Repository
GitHub Stars
23.4K
First Seen
Jan 21, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykFail
Installed on
claude-code133
opencode124
gemini-cli122
cursor117
antigravity109
codex108
Angular HTTP 数据获取教程:基于信号的 httpResource() 与 resource() 使用指南
1 周安装
Angular路由配置指南:v20+懒加载、函数式守卫与信号参数详解
1 周安装
iOS数据持久化与数据库路由指南:SwiftData、Core Data、CloudKit、迁移与审计
154 周安装
Angular CLI 工具集完整指南:v20+ 项目创建、代码生成与构建优化
1 周安装
Codex Wrapped 报告生成技能 - 获取过去30天和7天的Codex使用数据洞察
1 周安装
DOCX文档处理技能:专业格式编辑、视觉布局审阅与自动化渲染指南
1 周安装