Skip to content

fix(init): pull API keys into bootstrapped project subdirectory#195

Merged
rafa-thayto merged 1 commit intomainfrom
rafa-thayto/init-improvements
Apr 21, 2026
Merged

fix(init): pull API keys into bootstrapped project subdirectory#195
rafa-thayto merged 1 commit intomainfrom
rafa-thayto/init-improvements

Conversation

@rafa-thayto
Copy link
Copy Markdown
Contributor

@rafa-thayto rafa-thayto commented Apr 21, 2026

Summary

  • When clerk init bootstraps a new project in a subdirectory and then runs env pull at the end, it fails with:

    error: No Clerk project linked to this directory.
    Either:
      - Run `clerk link` from your project directory
      - Pass --app <app_id> to target an app directly
    

    even though the Clerk app was just linked to the freshly-created subdirectory. Result: ✓ Clerk has been set up prints, then the command errors and .env.local is left without real API keys.

  • Root cause: pull() and resolveAppContext() both hardcoded process.cwd(), which is still the parent directory (init never chdirs). The profile was correctly written under the subdir path by clerk link, but the subsequent lookup walked up from the parent and never found it.

  • Fix: thread cwd as an optional parameter through resolveAppContext() and pull() (defaulting to process.cwd() for existing callers), pass ctx.cwd from init, and extract a shared AppContextOptions interface so EnvPullOptions extends it instead of redeclaring the fields. Also parallelizes the two independent awaits at the top of pull() with Promise.all.

Test plan

  • bun run typecheck, bun run lint, bun run format:check, bun run test — all green (72 test files pass)
  • New regression test in packages/cli-core/src/commands/env/pull.test.ts that passes cwd pointing at a directory distinct from process.cwd() and asserts the keys are written inside that directory (and not in process.cwd())
  • New unit test in packages/cli-core/src/lib/config.test.ts covering resolveAppContext({ cwd }) finding profiles keyed by the explicit path
  • Updated existing init assertion to verify pull is called with { file, cwd: ctx.cwd }
  • Manual end-to-end: mkdir /tmp/foo && cd /tmp/foo && clerk init, pick TanStack Start + create new Clerk app — verify flow ends without error and <project>/.env.local contains real keys

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 21, 2026

🦋 Changeset detected

Latest commit: 944c1cd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
clerk Patch

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

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 21, 2026

Warning

Rate limit exceeded

@rafa-thayto has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 52 minutes and 43 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 52 minutes and 43 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c8e77119-5905-46d7-b634-cca44502baec

📥 Commits

Reviewing files that changed from the base of the PR and between 9abc17e and 944c1cd.

📒 Files selected for processing (7)
  • .changeset/init-improvements.md
  • packages/cli-core/src/commands/env/pull.test.ts
  • packages/cli-core/src/commands/env/pull.ts
  • packages/cli-core/src/commands/init/index.test.ts
  • packages/cli-core/src/commands/init/index.ts
  • packages/cli-core/src/lib/config.test.ts
  • packages/cli-core/src/lib/config.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

After `clerk init` bootstraps a new project, the final `env pull` step
resolved the linked profile via `process.cwd()` (still the parent
directory), producing "No Clerk project linked to this directory" even
though the freshly-created app was correctly linked under the subdir's
absolute path. Thread `cwd` through `resolveAppContext` and `pull()` and
pass `ctx.cwd` from init.
@rafa-thayto rafa-thayto force-pushed the rafa-thayto/init-improvements branch from 944e508 to 944c1cd Compare April 21, 2026 20:11
@rafa-thayto rafa-thayto merged commit 890137f into main Apr 21, 2026
10 checks passed
@rafa-thayto rafa-thayto deleted the rafa-thayto/init-improvements branch April 21, 2026 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants