dx-org-devhub-configure
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseEnable Dev Hub & View Scratch Org Allocation
启用Dev Hub并查看Scratch Org配额
Enable Dev Hub on a Salesforce org, verify whether it is already on, and see
the org's scratch org allocation (Active and Daily limits and how many
remain) — for the default org or a named org. The skill can also configure Dev
Hub sub-preferences (packaging, org shape export, scratch org snapshots) and
list the active scratch orgs created from a Dev Hub.
Dev Hub is the org feature that lets you create and manage scratch orgs and
second-generation (2GP) / unlocked packages.
在Salesforce组织中启用Dev Hub,验证其是否已开启,并查看组织的scratch org配额(Active和Daily限制及剩余数量)——针对默认组织或指定名称的组织。该技能还可配置Dev Hub子偏好设置(打包、组织形态导出、scratch org快照),并列出从Dev Hub创建的活跃scratch org。
Dev Hub是一项组织功能,允许您创建和管理scratch org以及第二代(2GP)/解锁包。
When to use
适用场景
Trigger on requests like:
- "Enable Dev Hub" / "Turn on Dev Hub" / "Set up this org for scratch orgs."
- "Is Dev Hub enabled on my org?" / "Check if Dev Hub is on."
- "How many scratch orgs can I create?" / "What's my scratch org allocation / limit?" / "How many scratch orgs do I have left?"
- "Turn on packaging / 2GP / unlocked packages" / "Enable org shape export" / "Enable scratch org snapshots" (Dev Hub sub-preferences).
- "List the scratch orgs on my Dev Hub."
在以下请求触发此技能:
- "启用Dev Hub" / "开启Dev Hub" / "配置此组织以创建scratch org"
- "我的组织是否已启用Dev Hub?" / "检查Dev Hub是否开启"
- "我可以创建多少个scratch org?" / "我的scratch org配额/限制是多少?" / "我还剩多少个scratch org额度?"
- "开启打包/2GP/解锁包" / "启用组织形态导出" / "启用scratch org快照"(Dev Hub子偏好设置)
- "列出我的Dev Hub中的scratch org"
When NOT to use
不适用场景
Do not trigger this skill for:
- Creating or deleting an individual scratch org — that is
/
sf org create scratch, a different workflow. This skill enables the Dev Hub feature and reports allocation; it does not create scratch orgs.sf org delete scratch - Switching the default/active org — use .
dx-org-switch - Trial or org expiration dates ("when does my org expire") — use
.
dx-org-trial-expiration-check
请勿在以下场景触发此技能:
- 创建或删除单个scratch org——对应/
sf org create scratch,属于不同工作流。本技能仅启用Dev Hub功能并报告配额,不负责创建scratch org。sf org delete scratch - 切换默认/活跃组织——请使用
dx-org-switch - 查询试用版或组织到期日期(如“我的组织何时到期”)——请使用
dx-org-trial-expiration-check
How Dev Hub enablement is determined
Dev Hub启用状态的判定方式
The standard object is provisioned and becomes queryable
only when Dev Hub is enabled. So a successful means Dev Hub is ON; an error means it is
OFF. This is the reliable signal.
ScratchOrgInfoSELECT COUNT() FROM ScratchOrgInfoINVALID_TYPEDo not infer enablement fromalone: it reportssf org list limits/ActiveScratchOrgsrows even on orgs where Dev Hub is off, so limits show allocation but not enablement.DailyScratchOrgs
标准对象**仅在Dev Hub启用后才会被配置并可查询。因此,执行成功意味着Dev Hub已开启**;若返回错误则表示Dev Hub已关闭。这是最可靠的判定信号。
ScratchOrgInfoSELECT COUNT() FROM ScratchOrgInfoINVALID_TYPE请勿仅通过推断启用状态:即使在Dev Hub未开启的组织中,该命令仍会返回sf org list limits/ActiveScratchOrgs数据,因此仅能显示配额,无法反映启用状态。DailyScratchOrgs
How enabling works (important)
启用机制说明(重要)
- The Dev Hub master switch is the deployable Metadata API field
. There is no
DevHubSettings.enableScratchOrgManagementPreffield and no dedicatedenableDevHubcommand to turn it on — deploying this setting is exactly what the Setup toggle does.sf - Enabling is irreversible — once on, Dev Hub cannot be turned off.
- Requires a user with ModifyAllData or ModifyMetadata (a System
Administrator has these). A user without them gets .
INSUFFICIENT_ACCESS - Cannot be enabled in a sandbox, or in an org that has a registered namespace.
- Available in Developer, Enterprise, Performance, Unlimited, and trial editions.
- Dev Hub的主开关是可部署的Metadata API字段****。不存在
DevHubSettings.enableScratchOrgManagementPref字段,也没有专门的enableDevHub命令用于开启Dev Hub——部署此设置与在Setup界面中切换开关的效果完全一致。sf - 启用操作不可逆——一旦开启,Dev Hub无法关闭。
- 权限要求:用户需拥有ModifyAllData或ModifyMetadata权限(系统管理员默认拥有这些权限)。无权限用户会收到错误。
INSUFFICIENT_ACCESS - 不可在沙箱中启用,也无法在已注册命名空间的组织中启用。
- 支持的版本:Developer、Enterprise、Performance、Unlimited及试用版。
Steps
操作步骤
-
CRITICAL: Run the bundled helper script, which handles Dev Hub detection, the enablement deploy (with a safe dry-run default), allocation math, and structured output, and works on macOS and Linux. Always invoke it by absolute path from the skill directory — never, which resolves against the user's current directory and will either run the wrong script or fail. The script self-checks this: if
./scripts/is not absolute it exits with a usage error, so pass the full path to$0(the directory containing this SKILL.md).<skill_dir>bashbash "<skill_dir>/scripts/devhub.sh" <alias-or-username> # status: on? + allocation bash "<skill_dir>/scripts/devhub.sh" # default org (target-org) bash "<skill_dir>/scripts/devhub.sh" <org> --allocation # allocation only bash "<skill_dir>/scripts/devhub.sh" <org> --enable # validate enabling (dry run) bash "<skill_dir>/scripts/devhub.sh" <org> --enable --apply # actually enable (irreversible) bash "<skill_dir>/scripts/devhub.sh" <org> --list-scratch # list active scratch orgs bash "<skill_dir>/scripts/devhub.sh" <alias> --instance-url <url> --enable --apply # log in first, then enable bash "<skill_dir>/scripts/devhub.sh" <url> # bare instance URL: log in to itWhen the user supplies an instance URL (their My Domain, sandbox, or pre-release/scratch login URL — e.g.), pass that exact URL withhttps://my-domain.my.salesforce.com— the script accepts Salesforce-owned hostnames and logs in with--instance-url <url>and then continues. A bare URL positional is accepted as shorthand for the same thing.sf org login web --instance-url <url>is the absolute path to the directory containing this SKILL.md.<skill_dir> -
For enablement, default to a dry run first. Run(no
--enable) to validate the deploy, then relay the result. Because enabling is irreversible, only run--applywhen the user has clearly asked to actually enable Dev Hub. Applied operations require an explicit org alias or username; the script refuses to mutate an implicit default org. If the deploy is rejected for permissions, surface the Setup-UI fallback it prints.--enable --apply -
Relay the script output. When an org can't be queried, surface thecommand the script prints so the user can authenticate. Pick optional flags based on the request (see below):
sf org login webfor limits only,--allocationto enumerate scratch orgs,--list-scratch/--packaging/--snapshotsto turn on sub-preferences,--shapefor automation.--json
-
关键操作:运行附带的辅助脚本,该脚本可处理Dev Hub检测、启用部署(默认安全试运行)、配额计算和结构化输出,支持macOS和Linux系统。请始终通过绝对路径从技能目录调用该脚本——切勿使用,因为该路径会基于用户当前目录解析,可能导致运行错误脚本或执行失败。脚本会自行检查路径:若
./scripts/不是绝对路径则会退出并提示使用错误,因此请传入$0的完整路径(即包含此SKILL.md文件的目录)。<skill_dir>bashbash "<skill_dir>/scripts/devhub.sh" <alias-or-username> # 状态查询:是否开启+配额 bash "<skill_dir>/scripts/devhub.sh" # 默认组织(target-org) bash "<skill_dir>/scripts/devhub.sh" <org> --allocation # 仅查询配额 bash "<skill_dir>/scripts/devhub.sh" <org> --enable # 验证启用操作(试运行) bash "<skill_dir>/scripts/devhub.sh" <org> --enable --apply # 实际启用(不可逆) bash "<skill_dir>/scripts/devhub.sh" <org> --list-scratch # 列出活跃scratch org bash "<skill_dir>/scripts/devhub.sh" <alias> --instance-url <url> --enable --apply # 先登录,再启用 bash "<skill_dir>/scripts/devhub.sh" <url> # 直接传入实例URL:登录该组织当用户提供实例URL(如My Domain、沙箱或预发布/scratch登录URL——例如)时,请将该URL与https://my-domain.my.salesforce.com一起传入——脚本接受Salesforce官方主机名,并通过--instance-url <url>登录后继续执行。直接传入URL作为位置参数是简化写法。sf org login web --instance-url <url>是包含此SKILL.md文件的目录的绝对路径。<skill_dir> -
启用操作默认先执行试运行。运行(不带
--enable)验证部署操作,然后反馈结果。由于启用操作不可逆,仅当用户明确要求实际启用Dev Hub时,才运行--apply。执行修改操作需要指定明确的组织别名或用户名;脚本拒绝修改隐式默认组织。若因权限不足导致部署被拒绝,请反馈脚本输出的Setup界面备选方案。--enable --apply -
反馈脚本输出结果。若无法查询组织,请提供脚本输出的命令,以便用户进行身份验证。根据请求选择可选参数(如下所示):
sf org login web仅查看限制、--allocation枚举scratch org、--list-scratch/--packaging/--snapshots开启子偏好设置、--shape用于自动化场景。--json
Before you finish
完成前验证
Verify these before returning your answer:
- CRITICAL: Invoked the helper via its absolute path (), never
bash "<skill_dir>/scripts/devhub.sh" …(the script rejects a non-absolute./scripts/).$0 - Did not run unless the user clearly asked to actually enable Dev Hub or deploy a preference — enabling is irreversible.
--apply - Relayed the script's own output (status/allocation or the login/Setup-UI guidance it printed), rather than substituting a hand-written answer.
返回结果前请验证以下内容:
- 关键检查:通过绝对路径调用辅助脚本(),切勿使用
bash "<skill_dir>/scripts/devhub.sh" …(脚本会拒绝非绝对路径的./scripts/)。$0 - 除非用户明确要求实际启用Dev Hub或部署偏好设置,否则请勿运行——启用操作不可逆。
--apply - 反馈脚本自身的输出结果(状态/配额或登录/Setup界面指引),切勿手动编写替代内容。
Options
可选参数
| Flag | Purpose |
|---|---|
| Show only the scratch org allocation (Active/Daily). |
| List active scratch orgs created from this Dev Hub. |
| Enable Dev Hub (deploys |
| Configure sub-preferences without (re)enabling the master switch. Pair with a pref flag. |
| |
| |
| |
| |
| Any |
| Actually deploy to the explicit org argument. Default for |
| Authenticate an org first via |
| Log in to a specific instance (My Domain, sandbox, or pre-release/scratch instance) with |
| Emit machine-readable JSON. |
| Exit |
| Show usage. |
--enable--enable --packaging --applytarget-orgtarget-dev-hub| 参数 | 用途 |
|---|---|
| 仅显示scratch org配额(Active/Daily)。 |
| 列出从此Dev Hub创建的活跃scratch org。 |
| 启用Dev Hub(部署 |
| 配置子偏好设置,无需(重新)启用主开关。需搭配偏好参数使用。 |
| 设置 |
| 设置 |
| 设置 |
| 设置 |
| 设置任意 |
| 实际部署到指定的组织参数。 |
| 先通过 |
| 通过 |
| 输出机器可读的JSON格式内容。 |
| 若Dev Hub未启用则退出并返回状态码 |
| 显示使用说明。 |
--enable--enable --packaging --applytarget-orgtarget-dev-hubOutput examples
输出示例
The script prints the authoritative output at runtime. If you need to calibrate
what an enabled-vs-disabled status transcript looks like (including the
allocation table and the enable/Setup-UI guidance), read
— otherwise skip it to
keep this workflow lean.
examples/status-output.md脚本会在运行时输出权威结果。若需要了解启用/未启用状态的输出示例(包括配额表和启用/Setup界面指引),请阅读——否则可跳过此部分以简化工作流。
examples/status-output.mdStructured output for automation (--json
)
--json自动化场景的结构化输出(--json
)
--jsonUse in any mode for machine-readable output (no prose). Status returns
, , and an object; enablement returns
, , and . Deterministic, no LLM needed.
--jsondevHubEnabledstatusallocationsuccessapplieddevHubVerifiedStatebash
bash "<skill_dir>/scripts/devhub.sh" my-devhub --json在任意模式下使用参数可获取机器可读的输出结果(无描述性文本)。状态查询会返回、和对象;启用操作会返回、和。结果确定,无需依赖大语言模型。
--jsondevHubEnabledstatusallocationsuccessapplieddevHubVerifiedStatebash
bash "<skill_dir>/scripts/devhub.sh" my-devhub --json{"org":"my-devhub","devHubEnabled":true,"status":"enabled", ... }
{"org":"my-devhub","devHubEnabled":true,"status":"enabled", ... }
`--fail-if-disabled` exits `3` (and prints an `ALERT:` line to stderr) if Dev
Hub is not enabled, so a scheduled job can gate on it.
`--fail-if-disabled`参数会在Dev Hub未启用时退出并返回状态码`3`(同时向stderr输出`ALERT:`行),因此定时任务可基于此进行校验。Exit codes
退出状态码
- success
0 - an org could not be queried, or a deploy failed (auth/connection/deploy)
1 - bad usage or a missing dependency (
2orsf)jq - Dev Hub is not enabled (only when
3is set)--fail-if-disabled
- 执行成功
0 - 无法查询组织,或部署失败(身份验证/连接/部署问题)
1 - 使用方式错误或缺少依赖(
2或sf)jq - Dev Hub未启用(仅当设置
3时返回)--fail-if-disabled
Authentication
身份验证
If the org isn't authenticated yet, the skill can log in for you with
(or ), then continue with the requested action
in the same run — this is the preferred path when the user provides an instance
URL:
--login--instance-url <url>Substitute the user's actual instance URL for (shown here as the generic
placeholder):
<url>https://my-domain.my.salesforce.combash
undefined若组织尚未完成身份验证,技能可通过(或)为您登录,然后在同一次运行中继续执行请求的操作——当用户提供实例URL时,这是首选方式:
--login--instance-url <url>将用户提供的实际实例URL替换为(以下示例中使用通用占位符):
<url>https://my-domain.my.salesforce.combash
undefinedLog in to a specific instance (My Domain / pre-release / sandbox), then enable:
登录到指定实例(My Domain/预发布/沙箱),然后启用:
bash "<skill_dir>/scripts/devhub.sh" my-alias
--instance-url https://my-domain.my.salesforce.com --enable --apply
--instance-url https://my-domain.my.salesforce.com --enable --apply
bash "<skill_dir>/scripts/devhub.sh" my-alias
--instance-url https://my-domain.my.salesforce.com --enable --apply
--instance-url https://my-domain.my.salesforce.com --enable --apply
Bare instance URL as shorthand — logs in to it, then reports status:
直接传入实例URL作为简化写法——登录该组织,然后报告状态:
bash "<skill_dir>/scripts/devhub.sh" https://my-domain.my.salesforce.com
bash "<skill_dir>/scripts/devhub.sh" https://my-domain.my.salesforce.com
Just authenticate an org (no other action):
仅进行组织身份验证(无其他操作):
bash "<skill_dir>/scripts/devhub.sh" my-alias --login
`sf org login web` opens a browser for the OAuth flow; complete it promptly (the
session times out). A supplied positional (`my-alias`) becomes the CLI alias; a
positional that looks like a URL (contains `://`) is taken as the
`--instance-url` to log in to. The script accepts only HTTPS Salesforce-owned
hostnames for this option. Omit `--instance-url` for standard
production/DE/trial logins (`login.salesforce.com`). If the browser flow keeps
timing out, the script prints the `sf org login device` fallback for a
code-based login.
If an org isn't authenticated and no login flag was passed, the script instead
prints the exact command to log in and re-run — using the instance URL you
supplied when there is one:
```text
my-org could not query org (...)
To authenticate against https://my-domain.my.salesforce.com, run:
sf org login web --instance-url "https://my-domain.my.salesforce.com" --alias "my-org"
Or let this script log you in and continue in one step:
devhub.sh "my-org" --instance-url "https://my-domain.my.salesforce.com" --login
Then re-run. List existing logins with: sf org listbash "<skill_dir>/scripts/devhub.sh" my-alias --login
`sf org login web`会打开浏览器进行OAuth流程;请及时完成验证(会话会超时)。传入的位置参数(`my-alias`)会成为CLI别名;若位置参数看起来是URL(包含`://`),则会被视为`--instance-url`用于登录。该选项仅接受HTTPS协议的Salesforce官方主机名。对于标准生产/DE/试用版登录(`login.salesforce.com`),可省略`--instance-url`。若浏览器流程持续超时,脚本会输出`sf org login device`备选方案,用于基于验证码的登录。
若组织未完成身份验证且未传入登录参数,脚本会输出准确的登录命令并提示重新运行——若提供了实例URL,则会使用该URL:
```text
my-org 无法查询组织(...)
要在https://my-domain.my.salesforce.com进行身份验证,请运行:
sf org login web --instance-url "https://my-domain.my.salesforce.com" --alias "my-org"
或让此脚本一次性完成登录并继续执行:
devhub.sh "my-org" --instance-url "https://my-domain.my.salesforce.com" --login
然后重新运行。查看已登录组织列表: sf org listManual fallback (if the script is unavailable)
手动备选方案(若脚本不可用)
bash
undefinedbash
undefinedDetect Dev Hub (INVALID_TYPE error means OFF; a count means ON):
检测Dev Hub状态(返回INVALID_TYPE错误表示未开启;返回计数表示已开启):
sf data query --query "SELECT COUNT() FROM ScratchOrgInfo" --target-org <org> --json
sf data query --query "SELECT COUNT() FROM ScratchOrgInfo" --target-org <org> --json
Enable Dev Hub via the Tooling API (what the Setup toggle does; irreversible):
通过Tooling API启用Dev Hub(与Setup界面开关效果一致;不可逆):
sf api request rest "/services/data/v47.0/tooling/sobjects/DevHubSettings/DevHub"
--method PATCH
--body '{"FullName":"DevHub","Metadata":{"enableScratchOrgManagementPref":true}}'
--target-org <org>
--method PATCH
--body '{"FullName":"DevHub","Metadata":{"enableScratchOrgManagementPref":true}}'
--target-org <org>
sf api request rest "/services/data/v47.0/tooling/sobjects/DevHubSettings/DevHub"
--method PATCH
--body '{"FullName":"DevHub","Metadata":{"enableScratchOrgManagementPref":true}}'
--target-org <org>
--method PATCH
--body '{"FullName":"DevHub","Metadata":{"enableScratchOrgManagementPref":true}}'
--target-org <org>
Or enable in the UI: Setup > Quick Find > "Dev Hub" > turn Enable Dev Hub On.
或在UI中启用:Setup > 快速查找 > "Dev Hub" > 开启Enable Dev Hub。
View scratch org allocation:
查看scratch org配额:
sf org list limits --target-org <org> --json | jq '.result[] | select(.name|test("ScratchOrg"))'
undefinedsf org list limits --target-org <org> --json | jq '.result[] | select(.name|test("ScratchOrg"))'
undefinedNotes
注意事项
- Requires the Salesforce CLI () and
sfon the PATH, plus at least one authenticated org (jq).sf org login web - After enabling, set the org as your default Dev Hub:
.
sf config set target-dev-hub <org> - Enabling packaging () requires Dev Hub to be on first —
enablePackaging2handles the ordering in a single deploy.--enable --packaging - Non-admin users still need object access (Read/Create on and
ScratchOrgInfo) to create/view scratch orgs, and the "Create and Update Second-Generation Packages" permission to build 2GP/unlocked packages.ActiveScratchOrg - To switch the default org use ; to check expiration use
dx-org-switch.dx-org-trial-expiration-check
- 需要将Salesforce CLI()和
sf添加到PATH中,且至少有一个已完成身份验证的组织(通过jq登录)。sf org login web - 启用Dev Hub后,可将该组织设置为默认Dev Hub:。
sf config set target-dev-hub <org> - 启用打包()需要先开启Dev Hub——
enablePackaging2会在单次部署中处理顺序问题。--enable --packaging - 非管理员用户仍需拥有对象访问权限(和
ScratchOrgInfo的读/创建权限)才能创建/查看scratch org,且需要“创建和更新第二代包”权限才能构建2GP/解锁包。ActiveScratchOrg - 如需切换默认组织,请使用;如需查询到期日期,请使用
dx-org-switch。dx-org-trial-expiration-check