CLI
The `dyrected` command-line tool — scaffold a project, generate types, sync your schema to the Cloud, emit AI rules, and upgrade packages. Every command and flag in one place.
The dyrected CLI is how you scaffold and maintain a project from the terminal. It ships as a dev dependency (dyrected) and covers five jobs: bootstrapping a new project, generating types, pushing your schema to Dyrected Cloud, emitting rules for AI coding tools, and upgrading your Dyrected packages.
You don't install anything extra. Run any command with npx:
npx dyrected <command>After npx dyrected init, the most common commands are also wired into your package.json scripts, so you can reach for npm run generate:types (or your package manager's equivalent) instead of typing the full command each time.
Every command has built-in help. When you're unsure of a flag, ask the tool:
npx dyrected --help
npx dyrected generate:types --helpThis page is the reference for what each command does and every flag it accepts. Where a command has a deeper task guide, you'll find a link to it.
init
Bootstrap Dyrected in your project. init detects your framework, installs the right packages, writes a starter dyrected.config.ts, adds framework wiring and a .env template, drops in AI-assistant rules, and adds helper scripts to your package.json. It's interactive by default and prompts only for what it can't detect.
npx dyrected initRun it non-interactively by passing the answers as flags:
# Dyrected Cloud, Next.js, admin at /admin
npx dyrected init -y -f next -b cloud -p admin
# Self-hosted Next.js with Postgres, S3, and a custom admin path
npx dyrected init -y -f next -b self-hosted -d postgres -s s3 -p custom-admin| Flag | Description |
|---|---|
-y, --yes | Skip prompts and use defaults (SQLite + Local Storage). |
-f, --framework <framework> | Target framework: next, nuxt, react, or vue. Auto-detected when omitted. |
-b, --backend <backend> | cloud or self-hosted. React and Vue are Cloud-only. |
-d, --db <adapter> | Database adapter: sqlite, postgres, mysql, or mongodb (self-hosted). |
-s, --storage <adapter> | Storage adapter: local, s3, b2, or cloudinary (self-hosted). |
-p, --path <path> | Admin dashboard route path. Defaults to admin. |
-o, --overwrite | Overwrite existing config/env files without asking. |
init never clobbers your work silently — when a dyrected.config.ts or .env already exists, it asks before touching it unless you pass --overwrite (or --yes). It also creates AI-assistant pointers (AGENTS.md, CLAUDE.md, and Cursor/Copilot rule files) if they're missing, so your coding agent picks up Dyrected context automatically.
generate:types
Generate a TypeScript types file from your schema. With no flags it reads ./dyrected.config.ts and writes the types into your app's source directory (src/dyrected-types.ts, or app/dyrected-types.ts in Nuxt) so your TypeScript program picks up the generated schema. Point it at a different config, a running site, or a different output path with the flags below.
npx dyrected generate:types| Flag | Description |
|---|---|
-u, --url <url> | Base URL of a running Dyrected API. Generates from its /api/schemas instead of a local file. |
-c, --config <path> | Path to your dyrected.config.ts. Defaults to ./dyrected.config.ts. |
-o, --output <path> | Where to write the generated file. Defaults to <srcDir>/dyrected-types.ts (src/, or app/ in Nuxt). |
The output path is yours to choose — keep generated contracts wherever they fit your project:
npx dyrected generate:types --output ./types/cms.tsinit adds a dyrected:generate-types script to your package.json so you have a stable rerun command after every schema change. For the full workflow — when to generate a file versus infer types in-memory, what the generated file contains, and how to feed it to the SDK — see Generating Types.
sync:schema
Push your local schema to Dyrected Cloud so the hosted backend serves the collections, globals, and admin you defined. It reads your credentials from the environment (DYRECTED_API_KEY, DYRECTED_SITE_ID, and DYRECTED_URL) and regenerates your types afterward unless you tell it not to.
npx dyrected sync:schema| Flag | Description |
|---|---|
-k, --api-key <key> | Your Dyrected API key. Falls back to $DYRECTED_API_KEY. |
-s, --site-id <id> | Your Dyrected Site ID. Falls back to $DYRECTED_SITE_ID. |
-u, --url <url> | Cloud API URL. Falls back to $DYRECTED_URL, then Dyrected Cloud. |
-c, --config <path> | Path to your dyrected.config.ts. Defaults to ./dyrected.config.ts. |
--env-path <path> | Load a specific env file before syncing (for example ./.env.local). |
--skip-on-error | Don't fail the process if the sync fails. Useful in CI build steps. |
--skip-types | Don't regenerate types after a successful sync. |
If your API key or Site ID is missing, sync:schema skips quietly rather than failing — so it's safe to leave in a self-hosted build. One caveat worth knowing: Cloud only keeps the parts of your schema it can serialize safely.
That means sync:schema now does three different things:
- It keeps string and boolean
accessPolicies. - It keeps supported declarative string hooks on:
- collection/global
beforeRead - collection/global
afterRead - collection/global
beforeChange - field
beforeChange - field
admin.hooks.onChange
- collection/global
- It strips function-based access rules, function-based access policies, and unsupported function-only hook families such as
afterChange, delete hooks, fieldafterRead, andadmin.hooks.options.
When something is stripped, the CLI warns with the exact schema path that was removed. Replace any function rule, function policy, or function hook you expect Cloud to enforce with a serializable form before relying on it in production.
When you run init for a Cloud project, this command is wired into package.json as dyrected:sync-schema and added to your postbuild step, so your schema syncs automatically on deploy.
generate:ai-rules
Write the canonical Dyrected instructions for AI coding tools to .dyrected/ai-rules.md. init already creates this file, so reach for this command when you want to refresh it after upgrading Dyrected.
npx dyrected generate:ai-rules| Flag | Description |
|---|---|
-o, --output <path> | Where to write the rules file. Defaults to .dyrected/ai-rules.md. |
To go further — installing the Dyrected agent skill and getting the most out of an AI assistant — see Coding agents and AI app builders.
upgrade
Upgrade every @dyrected/* package in the current package to its latest published version. Pass --workspace to upgrade all packages across a monorepo at once.
npx dyrected upgrade| Flag | Description |
|---|---|
-w, --workspace | Upgrade every workspace package under the repository root, not just the current one. |
The command reads your package.json, resolves the latest published version of each Dyrected dependency it finds, and updates them together — so your @dyrected/* packages stay on matching versions.
The scripts init sets up
So you rarely have to type the full command, init adds these to your package.json:
{
"scripts": {
"dyrected:generate-types": "dyrected generate:types",
"dyrected:sync-schema": "node ./scripts/run-dyrected-sync.mjs"
}
}The dyrected:sync-schema script (and the postbuild hook that calls it) is only added for Cloud projects. You can always add flags — for example a custom --output on the type-generation script — and they'll be respected on your next init run.
Where to go next
- Generating Types — the full type-generation workflow and what the generated file contains.
- Configuration Overview — what the
dyrected.config.tsthat these commands act on actually holds. - Production deployment — where
sync:schemafits into a Cloud deploy.