Agent Skill · DatoCMS

datocms-cli

DatoCMS CLI (datocms) — command-line migrations, schema codegen, schema inspection, one-off CMA calls, typed TypeScript CMA scripts, env operations, deployment workflows, multi-project profile syncing. Use for datocms CLI commands/scripts: migrations:new, migrations:run; schema:generate; schema:inspect (dump models, blocks, fields, validators, appearance, fieldsets, nested blocks, referenced/embedding models); cma:call, cma:docs, cma:script (ad-hoc typed TS with ambient client/Schema globals); migration scaffolding for models/fields/blocks; CLI setup via datocms.config.json + profiles; OAuth (login/logout/whoami); projects:list; project link/unlink; env list/fork/promote/rename/destroy; maintenance-mode toggle; CI/CD migration pipelines; blueprint/client project sync; imports from WordPress or Contentful (assets + content); CLI plugin management (plugins:install/add/available/link/remove/update/reset/inspect).

Provider: DatoCMS Path in repo: skills/datocms-cli/SKILL.md

Skill body

DatoCMS CLI Skill

You’re an expert at datocms CLI. Follow these steps. Don’t skip.

Step 1: Detect Context

If context already set (CLI package, config, token, migrations dir, TS setup), skip detection. Re-inspect only when can’t answer from prior context.

CLI + link is required bootstrap for any repo interfacing with DatoCMS project. datocms npm package installed + datocms login + datocms link = agent visibility into live project (models, fields, ids, record state). Missing → fix first, same as git init or npm install.

Detection (don’t rely on which datocms — CLI runs via npx)

  1. datocms in package.json devDependencies → CLI available. Missing: install it (npm install --save-dev datocms) — never fall back to pasted tokens or manual Dashboard steps.
  2. datocms.config.json with siteId on active profile → linked. Missing: drive bootstrap below.
  3. npx datocms whoami succeeds → OAuth session active.
  4. migrations/ directory → migrations already scaffolded.
  5. tsconfig.json or migrations.tsconfig → TS migrations convention.

Bootstrap flow (CLI available but not linked)

Only datocms login needs terminal; rest runs in non-TTY.

npx datocms login  # user, one-time, interactive
npx datocms projects:list [hint] --json # agent discovers siteId
npx datocms link --site-id=<ID> [--organization-id=<ID>] # agent links

Always confirm target project with user before running datocms link, even when projects:list returns single candidate. Show candidate(s) (name, id, organization) and wait for explicit yes. Don’t treat “only one result” as consent — user may have access to project they didn’t mean to wire to this repo; fixing mis-linked project later is painful.

datocms link without --site-id requires terminal. In non-TTY it now exits cleanly with suggestion to pass --site-id; don’t retry without it. Same when credentials missing — ask user to run datocms login first.

Once project linked, use npx datocms schema:inspect (optionally with model API key, id, or display name) to learn what project actually contains — models, blocks, fields, validators, fieldsets, nested blocks, relationships. This is right tool any time agent or user needs generic info about project structure; reach for it before writing mutations, migrations, or CMA code so decisions rest on real schema rather than guesses. See references/schema-inspect.md.

Authentication policy

Token resolution order CLI uses:

Step 2: Understand the Task

Classify user’s task into one or more categories:

Category Examples
CLI setup Install CLI, authenticate (login/logout/whoami), discover accessible projects (projects:list), link/unlink projects (link/unlink), configure profiles, datocms.config.json
Schema changes Add, modify, or remove models, fields, fieldsets, or block models — via migration script (default) or direct CMA operation against chosen environment
Creating migrations Scaffold new migration scripts, autogenerate from environment diffs, custom templates (sub-task of schema changes once migration approach chosen)
Running migrations Execute pending migrations, dry-run, fork-and-run, in-place execution
Schema generation Run schema:generate, scope output to item types, target specific environment
Schema inspection Run schema:inspect to dump models, blocks, fields, validators, appearance, default values, fieldsets, nested blocks, referenced models, or embedding models — use any time agent or user needs to understand how project is structured before writing code or mutations
Direct CMA calls Use cma:docs to browse API reference, cma:call for single call with shape from docs, cma:script for one-off TS logic that needs loops, branching, or typed Schema.* types — stdin-mode for heredocs/pipes, file-mode for longer scripts in gitignored scratch dir
Environment management Fork, promote, rename, destroy, list environments via CLI commands
Deployment workflow Maintenance mode, safe deployment sequences, CI/CD integration
Multi-project sync Shared migrations across blueprint/client projects via CLI profiles
Importing content WordPress import, Contentful import
CLI plugin management Install, remove, update, list, inspect, link, or reset CLI plugins (plugins:* commands)

Step 2.5: Collect Critical Inputs Before You Commit To Commands

Do not skip questions merely because category is obvious. Skip follow-up questions only if request already includes critical inputs for relevant category, or repo inspection answers them safely.

Ask minimum targeted question set needed to avoid flattening real workflow decision.

Category-specific inputs live in reference files

Each category reference loaded in Step 3 opens with “Inputs to confirm before running commands” section — that is per-category equivalent of this step. Don’t skip loading reference for task’s category: it carries workflow decisions this step is designed to protect. If you skip it, you skip checklist.

Schema changes — decide approach with user

DatoCMS schema operations fall into four buckets. Choice of approach is not automatic — ask user when bucket is not obvious from request, because reversibility and workflow preference matter more than which tool performs mutation.

Situation What it covers Approach
Destructive schema change DROP field, DROP model, bulk_destroy records, lossy field_type changes (e.g. string → json, json → string, anything that discards stored values) Migration via datocms-cli (migrations:new), against forked sandbox first. Never run these against primary environment without explicit, repeated user confirmation.
Reversible schema change Add field, add model or block, rename field, toggle required, add or tighten validation, reorder fieldsets Ask user. Both approaches safe; pick by preference and context. Lean to migration (datocms-cli) when repo already uses migrations workflow or user is on secondary branch — reviewable, reproducible. Direct mutation (cma:call, cma:script stdin-mode, or cma:script file-mode) fine for quick iteration on sandbox. Default to migration only when user has no preference AND repo shows migration conventions (migrations/ directory, prior migration commits).
User-requested one-off Phrases like “quickly, without migrations workflow”, “just patch this”, “one-off”, “don’t scaffold migrations for this” Honor opt-out. Use direct mutation via cma:call (single call with shape from cma:docs) or cma:script (stdin-mode for loops/multi-step, file-mode when script is long enough that heredoc hurts). Don’t re-suggest migrations unless change turns out to be destructive schema change.
Content operation Publish, unpublish, delete individual records, fix slugs, bulk update field value, re-tag uploads No migration needed. Prefer cma:call for single call; cma:script stdin-mode for loops, pagination, or multi-step logic; cma:script file-mode only when heredoc becomes painful. Code that needs to be committed and replayed across environments is migration (datocms-cli), not datocms-cma.

Regardless of which skill is loaded, question to ask user is same for reversible schema change: “Do you want this as reviewable migration, or direct mutation against sandbox?” Answer determines which skill owns follow-up — not which skill was loaded first.

Cross-skill routing:

Destructive and production-sensitive confirmations

Destructive schema changes always require these confirmations; list below also covers non-schema destructive commands.

If context missing, ask for explicit confirmation before proposing final commands for:

Step 3: Load References

Based on task classification, read appropriate reference files from references/ directory next to this skill file. Only load what’s relevant.

Always load:

Load per category:

Task category Reference file
Creating migrations references/creating-migrations.md
Running migrations references/running-migrations.md
Schema generation references/schema-generate.md
Schema inspection references/schema-inspect.md
Direct CMA calls references/direct-cma-calls.md (for cma:call) and/or references/cma-script.md (for cma:script)
Environment management references/environment-commands.md
Deployment workflow references/deployment-workflow.md
Multi-project sync references/blueprint-sync.md
Importing content references/importing-content.md
CLI plugin management references/cli-plugin-management.md

Load cross-cutting references when needed:

Step 4: Generate Code

Write commands and scripts following mandatory rules:

Command Prefix

Migration File Templates

File Naming

Migration Script Bodies

Schema Generation

Schema Inspection

Direct CMA Calls

Concrete shape, with JSON5 accepted in --data / --params:

npx datocms cma:call items list --params='{filter: {type: "article"}}'
npx datocms cma:call items find <ITEM_ID>
npx datocms cma:call items update <ITEM_ID> --data='{title: "Updated"}'
npx datocms cma:call items publish <ITEM_ID>
npx datocms cma:call fields create <ITEM_TYPE_ID> --data='{label: "Title", api_key: "title", field_type: "string"}'

Run npx datocms cma:call --help for full list of built-in examples, or npx datocms cma:docs <resource> <action> for body schema and required fields.

CLI Plugin Commands

Environment Safety

Step 5: Verify

Before presenting final commands or scripts:

  1. API token — Confirm CMA-enabled token available (via env var or --api-token flag)
  2. Config file — If using profiles, verify datocms.config.json exists and has right profile
  3. Migrations directory — Confirm migrations directory exists or will be created by command
  4. TypeScript config — If generating TS migrations, ensure tsconfig.json exists or --migrations-tsconfig is set
  5. Schema generation scope — If using schema:generate, verify output file path plus any --item-types / --environment scope match request
  6. Direct CMA calls — If using cma:call, verify positional args, --data, --params, and --environment align with targeted method. If using cma:script, verify script uses Schema.* types (not any/unknown), imports only from pre-installed package list, and targets intended environment
  7. Environment targeting — Verify correct --source / --destination environment specified
  8. Safety checks — For destructive operations (promote, destroy, destructive cma:call usage, risky imports, maintenance-mode force), confirm user intends to target right environment. For schema mutations, confirm chosen approach (migration vs direct) and — if direct — target environment (sandbox vs primary) before issuing commands
  9. CLI plugin commands — If using plugins:* commands, verify plugin name is correct and distinguish CLI plugins from DatoCMS project plugins

Cross-Skill Routing

This skill covers CLI commands, flags, configuration, workflows, and migration file scaffolding. If task involves any of following, activate companion skill:

Condition Route to
CMA API calls inside migration script bodies (records, schema, uploads) datocms-cma
Programmatic environment management via client.environments.* in code datocms-cma
Consuming generated schema types inside application code or reusable scripts datocms-cma
Querying content with GraphQL for frontend display datocms-cda
Setting up framework integration, draft mode, or real-time updates datocms-frontend-integrations
Building a DatoCMS plugin datocms-plugin