Better Auth CLI#
The Better Auth CLI (better-auth / auth) is a developer tool for scaffolding, managing, and upgrading Better Auth projects. It is distributed as the @better-auth/cli package and implemented using Commander.js. The CLI entry point is at packages/cli/src/index.ts and exposes the following commands :
| Command | Purpose |
|---|---|
init | Interactive project setup wizard (framework detection, database, providers) |
generate | Generate database schemas for Prisma, Drizzle, or Kysely adapters |
migrate | Run Kysely database migrations |
secret | Generate a random BETTER_AUTH_SECRET value |
info | Display system and Better Auth configuration info |
upgrade | Upgrade all better-auth packages to latest stable |
mcp | Configure the Better Auth MCP server for AI clients |
ai | Interactive setup for Agent Auth (AI agent authentication) |
login / logout | Authenticate with Better Auth Infrastructure |
upgrade Command#
The upgrade command scans package.json for any package matching better-auth or the @better-auth/ scope (excluding workspace: pinned packages) and upgrades them to the latest stable version.
Flow:
- Reads
dependenciesanddevDependenciesfrom the project'spackage.json. - For each candidate package, calls
fetchLatestVersion()to resolve the target version. - Uses
semver.lt()to filter packages where the installed version is behind the resolved version . - Prompts for confirmation (skippable with
--yes) then installs upgrades via the detected package manager .
Options:
-c, --cwd <cwd>— working directory (defaults toprocess.cwd())-y, --yes— skip confirmation prompt
Key Limitation: Stable-Only Upgrades#
fetchLatestVersion() queries the NPM registry's /latest dist-tag endpoint (https://registry.npmjs.org/{package}/latest) . NPM's latest tag is always a stable release — it never points to RC, alpha, beta, or any other pre-release version.
Consequence: Running better-auth upgrade will never upgrade to an RC or pre-release version, even if a newer pre-release exists. For example, if the installed version is 1.2.0 and 1.3.0-rc.1 is published but 1.2.3 is the latest stable, the command will upgrade to 1.2.3 and ignore 1.3.0-rc.1.
Workaround: To install a pre-release version, install it directly via your package manager using an explicit dist-tag or version:
npm install better-auth@rc
# or
npm install better-auth@1.3.0-rc.1
There is no --tag or --pre-release flag in the current upgrade command implementation .
Related Source Files#
| File | Role |
|---|---|
packages/cli/src/commands/upgrade.ts | upgrade command implementation |
packages/cli/src/utils/fetch-latest-version.ts | NPM registry version fetch utility |
packages/cli/src/index.ts | CLI entry point — registers all commands |
packages/cli/package.json | CLI package config, binary names, dependencies |