feat(init): create real app when authed in agent mode#254
Conversation
When `clerk init` runs in agent mode without `--app` and the user is already authenticated, create a real Clerk application named after the project and link it instead of falling back to keyless setup. Keyless still runs in agent mode when the user is not authenticated. Previously an authed agent run created an unowned keyless app and wrote a deferred-claim breadcrumb, leaving the project unlinked even though the user had logged in before the run; auto-claim only fired on a subsequent `clerk auth login`, which authed users had no reason to re-run. Adds a `createIfMissing` library option to `link` so the agent-mode autolink path can fall through to a deterministic create instead of the existing usage error, and threads a project-name derivation (`package.json#name`, `--name`, or directory basename) through `init`'s authenticated branch.
🦋 Changeset detectedLatest commit: b175cd3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR makes Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Review rate limit: 4/5 reviews remaining, refill in 12 minutes. Comment |
Railly
left a comment
There was a problem hiding this comment.
Reviewed locally. Logic checks out, autolink runs first to avoid duplicates, the guard still trips when createIfMissing is missing.
A couple things worth a look:
PLAPI accepts duplicate app names. Created two apps with the same name to confirm, different IDs each time. Agents running clerk init across multiple Next default projects will fill the dashboard with "my-app" entries. Worth either disambiguating the derived name or mentioning it in the changeset.
Also poked at createAndFetchApp and the second call is redundant. The raw POST /v1/platform/applications response already includes application_id, name, and a full instances[] array with instance_id, environment_type, secret_key, publishable_key. The follow-up GET /v1/platform/applications/{id} returns the same shape minus secret_key, so it actually drops information from the create response. Doesn't break anything because link only persists the instance ID and env pull fetches keys later, but it's an extra PLAPI round-trip per authed init that buys nothing. Easy to drop the second call, or leave a comment if it's defensive.
Otherwise looks good.
The PLAPI POST /v1/platform/applications response already returns the full SerializableStack (application_id, name, instances[] with instance_id, environment_type, secret_key, publishable_key), so the follow-up GET was an extra round-trip that produced an identical shape.
Summary
When
clerk initruns in agent mode without--appand the user is already authenticated, the CLI now creates a real Clerk application named after the project and links it, instead of falling back to keyless setup. Previously an authed agent run created an unowned keyless app and wrote a deferred-claim breadcrumb, so the project ended up unlinked even though the user had logged in before the run; auto-claim only fired on a subsequentclerk auth login, which authed users had no reason to re-run. Keyless still runs in agent mode when the user is not authenticated.The change adds a
createIfMissinglibrary option tolinkso the agent-mode autolink path can fall through to a deterministic create instead of the existing usage error, and threads a project-name derivation (package.json#name,--name, or directory basename) throughinit's authenticated branch.Test plan
bun run typecheckbun run lintbun run testclerk init --framework next --pm npmin agent mode while logged in → real app appears in the dashboard,.env.localhas dev keys,clerk doctorreports linkedclerk auth login