Skip to content

Commit 0a5bfa8

Browse files
authored
refactor: move claim to workos env claim subcommand (#93)
Claim is an environment lifecycle action, so it belongs under `env` alongside add/remove/switch/list. Keeps a visible top-level alias for discoverability.
1 parent 87bade6 commit 0a5bfa8

7 files changed

Lines changed: 33 additions & 23 deletions

File tree

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ workos [command]
5050

5151
Commands:
5252
install Install WorkOS AuthKit into your project
53-
claim Claim an unclaimed environment (link to your account)
5453
auth Manage authentication (login, logout, status)
55-
env Manage environment configurations
54+
env Manage environment configurations (add, remove, switch, list, claim)
5655
doctor Diagnose WorkOS integration issues
5756
skills Manage WorkOS skills for coding agents (install, uninstall, list)
5857

@@ -99,7 +98,7 @@ workos env list
9998
# Shows: unclaimed (unclaimed) ← active
10099

101100
# Claim the environment to link it to your WorkOS account
102-
workos claim
101+
workos env claim
103102
```
104103

105104
Management commands work on unclaimed environments with a warning reminding you to claim.

src/bin.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,17 @@ yargs(rawArgs)
406406
await runEnvList();
407407
},
408408
);
409+
registerSubcommand(
410+
yargs,
411+
'claim',
412+
'Claim an unclaimed environment (link it to your account)',
413+
(y) => y,
414+
async (argv) => {
415+
await applyInsecureStorage(argv.insecureStorage);
416+
const { runClaim } = await import('./commands/claim.js');
417+
await runClaim();
418+
},
419+
);
409420
return yargs.demandCommand(1, 'Please specify an env subcommand').strict();
410421
})
411422
.command(['organization', 'org'], 'Manage WorkOS organizations (create, update, get, list, delete)', (yargs) => {
@@ -2085,6 +2096,7 @@ yargs(rawArgs)
20852096
await runDebugSync(argv.directoryId, resolveApiKey({ apiKey: argv.apiKey }), resolveApiBaseUrl());
20862097
},
20872098
)
2099+
// Alias — canonical command is `workos env claim`
20882100
.command(
20892101
'claim',
20902102
'Claim an unclaimed WorkOS environment (link it to your account)',

src/commands/claim.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* `workos claim` — claim an unclaimed environment.
2+
* `workos env claim` — claim an unclaimed environment.
33
*
44
* Reads claim token from active environment, generates a nonce via
55
* createClaimNonce(), opens browser to dashboard claim URL, and polls

src/commands/env.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,6 @@ export async function runEnvList(): Promise<void> {
233233

234234
if (hasUnclaimed) {
235235
console.log('');
236-
console.log(chalk.dim(' Run `workos claim` to keep this environment.'));
236+
console.log(chalk.dim(' Run `workos env claim` to keep this environment.'));
237237
}
238238
}

src/lib/unclaimed-env-provision.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export async function tryProvisionUnclaimedEnv(options: UnclaimedEnvProvisionOpt
6464
config.activeEnvironment = 'unclaimed';
6565
saveConfig(config);
6666

67-
// Verify config persisted — critical for `workos claim` in a later process
67+
// Verify config persisted — critical for `workos env claim` in a later process
6868
const readBack = getActiveEnvironment();
6969
if (!readBack || readBack.type !== 'unclaimed') {
7070
logError('[unclaimed-env-provision] Config read-back failed after save — claim token may not persist');
@@ -73,7 +73,7 @@ export async function tryProvisionUnclaimedEnv(options: UnclaimedEnvProvisionOpt
7373
}
7474

7575
logInfo('[unclaimed-env-provision] Unclaimed environment provisioned and saved');
76-
const inner = ` ✓ ${chalk.green('Environment provisioned')} — Run ${chalk.cyan('workos claim')} to keep it. `;
76+
const inner = ` ✓ ${chalk.green('Environment provisioned')} — Run ${chalk.cyan('workos env claim')} to keep it. `;
7777
renderStderrBox(inner, chalk.green);
7878

7979
return true;

src/lib/unclaimed-warning.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export async function warnIfUnclaimed(): Promise<void> {
5959
warningShownThisSession = true;
6060

6161
if (!isJsonMode()) {
62-
const inner = ` ${chalk.yellow('⚠ Unclaimed environment')} — Run ${chalk.cyan('workos claim')} to keep your data. `;
62+
const inner = ` ${chalk.yellow('⚠ Unclaimed environment')} — Run ${chalk.cyan('workos env claim')} to keep your data. `;
6363
renderStderrBox(inner, chalk.yellow);
6464
}
6565
} catch (error) {

src/utils/help-json.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,20 @@ const commands: CommandSchema[] = [
269269
name: 'list',
270270
description: 'List all configured environments and show which is active',
271271
},
272+
{
273+
name: 'claim',
274+
description: 'Claim an unclaimed WorkOS environment (link it to your account)',
275+
options: [
276+
{
277+
name: 'json',
278+
type: 'boolean',
279+
description: 'Output in JSON format',
280+
required: false,
281+
default: false,
282+
hidden: false,
283+
},
284+
],
285+
},
272286
],
273287
},
274288
{
@@ -1034,21 +1048,6 @@ const commands: CommandSchema[] = [
10341048
},
10351049
],
10361050
},
1037-
{
1038-
name: 'claim',
1039-
description: 'Claim an unclaimed WorkOS environment (link it to your account)',
1040-
options: [
1041-
insecureStorageOpt,
1042-
{
1043-
name: 'json',
1044-
type: 'boolean',
1045-
description: 'Output in JSON format',
1046-
required: false,
1047-
default: false,
1048-
hidden: false,
1049-
},
1050-
],
1051-
},
10521051
// --- Workflow Commands ---
10531052
{
10541053
name: 'seed',

0 commit comments

Comments
 (0)