@baclet/cli
Command line tool for authorizing a machine with BACLET and pushing TypeScript models to a connected project database.
Install
Globally, when you want one command for all projects:
npm install --global @baclet/cli
baclet --help
Locally, when a repository should pin the version:
npm install --save-dev @baclet/cli
npx baclet --help
Node.js 18 or later is required.
Commands
| Command |
Description |
baclet login [--qr\|--link] |
Authorize this machine with a QR code, a link, or both. |
baclet logout |
Remove local credentials and revoke the CLI token. |
baclet whoami |
Show the authorized user's name and email. |
baclet init [--publishable-key KEY] |
Create baclet.config.ts, selecting a project when logged in. |
baclet setup [--yes\|--preview] |
Generate env-driven lib files and actions from your models. |
baclet projects list |
List projects you can access. |
baclet db status |
Print the schema diff without applying it. |
baclet db push [--yes] |
Apply the schema diff after confirmation. |
baclet db migrate [--yes] |
Alias for db push. |
baclet upgrade |
Upgrade @baclet/cli to the latest npm version. |
baclet --version |
Print the CLI version. |
Login
baclet login
The CLI prints an activation link, a verification code, and a QR code. Open the link or scan the QR code, sign in, and approve the code. Use --link or --qr to show only one option.
Tokens are stored in ~/.config/baclet/credentials.json with 0600 permissions. XDG_CONFIG_HOME changes the parent directory. Tokens are valid for 30 days and baclet logout revokes them.
Setup
baclet init --publishable-key pb_...
baclet setup
baclet setup reads baclet.config.ts, detects your environment and language, then asks which features you need. For each chosen feature it asks sharper questions: auth methods (email, guest, session, recovery), storage operations (upload, URL, delete), and database operations (list, get, create, set, update, remove) with optional filters and validation strictness. It writes a client initialization file, an actions/ directory, a barrel export, .env.example, and .env ignore rules into the chosen lib directory. Database actions are generated from the models matched by schema.models; if no models exist yet, auth and storage can still be generated.
Every planned file, export, and action is previewed before writing, and the final write requires confirmation. baclet setup --preview prints the full generated content and writes nothing. baclet setup --yes uses all detected defaults and skips prompts; code-fix suggestions are still skipped because they always require confirmation.
Before generating files, baclet setup checks baclet.config.ts and every matched model file for common BACLET syntax mistakes (wrong field type aliases, quoted booleans, default: "now()", string enum values, missing helper imports, and more). Unambiguous fixes are shown with before/after text and applied only after you confirm per file; declined or manual-only issues are left untouched. Fixes are backed up as .bak. Generated code reads only public configuration from the environment (publishable key, optional API URL, optional storage bucket), and no secret key is ever written to source or .env.example.
Import features from the generated index file:
import { baclet, authActions, productActions } from "./lib/index.js";
Schema push
Run baclet init while logged in to select a project and write the config automatically. Pass --publishable-key pb_... to supply the key directly. The CLI extracts the project UUID from the key before each request.
Otherwise, create baclet.config.ts in your project:
import { defineConfig } from "@baclet/sdk";
export default defineConfig({
publishableKey: "pb_45a8d1b2-3da5-4e1a-9435-ec40b58ee68b_...",
schema: { models: "./src/models/**/*.ts" },
});
Export a model from each matched file:
import { defineModel } from "@baclet/sdk";
export const Product = defineModel({
name: "products",
fields: {
name: { type: "string", required: true },
price: { type: "decimal", required: true, precision: 12, scale: 2 },
},
});
Then preview and apply:
baclet db status
baclet db push
Pushes are additive: new tables, columns, constraints, and indexes are applied in one transaction. Columns that exist in the database but not in your models are reported as warnings and are never dropped.
Updates
BACLET CLI checks npm for a newer @baclet/cli version at most every 12 hours (TTY only). When an update is available, it prints a notice. Disable with BACLET_NO_UPDATE_NOTIFIER=1.
baclet upgrade
Environment
| Variable |
Default |
Purpose |
BACLET_API_URL |
https://api.baclet.app |
API host. |
BACLET_DASHBOARD_URL |
https://baclet.app |
Fallback activation link host. |
XDG_CONFIG_HOME |
~/.config |
Parent directory for credentials. |
BACLET_NO_UPDATE_NOTIFIER |
unset |
Set to 1 to disable update checks. |