DatoCMS CLI

CLI for AI coding agents

A handful of CLI commands exist primarily to make life easier for AI coding agents (Claude Code, Codex, Cursor, and similar tools) when they operate on a DatoCMS project from your editor. They are perfectly usable from a human terminal, but a human developer typically has better alternatives (the dashboard, the typed CMA client in their editor, the online API docs). When an agent is at the keyboard instead, these commands turn the CLI into a powerful surface for autonomous interaction with DatoCMS.

Pro tip: Install Agent Skills to put these to work

The most leveraged way to use these commands is to install the DatoCMS Agent Skills. The Skills package the CLI together with the domain knowledge an agent needs to use it well — when to inspect the schema before generating types, how to scaffold a migration, when to fork an environment instead of working in primary, how to compose CMA calls without drifting from your project's conventions. The CLI is the engine; the Skills are the operator's manual.

The agent-first commands

schema:inspect

Dump the structure of a DatoCMS project (models, blocks, fields, validators, appearance, fieldsets, nested blocks, relationships) as JSON or in a token-efficient format optimised for LLM consumption. Typically the first command an agent runs against an unfamiliar project; a human inspects schemas visually in the dashboard, or uses schema:generate for a typed snapshot in code.

Terminal window
npx datocms schema:inspect
cma:docs

Browse the Content Management API reference from the terminal. Output is formatted for LLM consumption.

Terminal window
npx datocms cma:docs
npx datocms cma:docs item create
projects:list

List every DatoCMS project the authenticated account has access to. Supports fuzzy search by name or subdomain, and accepts --workspace, --limit, and --json flags. Agents invoke it during bootstrap to discover the siteId they need to pass to link.

Terminal window
npx datocms projects:list
cma:call

Make a single Content Management API call from the terminal, without setting up a Node project. Useful for one-off operations and shell pipelines; for non-trivial work, a typed @datocms/cma-client-node import in your editor is usually nicer.

Terminal window
npx datocms cma:call items create --data='{ "item_type": { "type": "item_type", "id": "..." }, "title": "Hello" }'
cma:script

Run a one-off TypeScript script against the Content Management API. It runs in two modes:

  • File-mode: pass a .ts file path. The script must export a default async function (client: Client) => Promise<void>. Imports resolve against your project's node_modules.

  • Stdin-mode: pipe top-level-await code. The CMA client is available as an ambient global, and Schema.* types are generated on demand. Named exports of @datocms/cma-client-node, datocms-structured-text-utils, and datocms-structured-text-dastdown are also exposed as globals, so most one-liners need no imports.

Terminal window
npx datocms cma:script <<'EOF'
console.log(
(await client.items.list({ filter: { type: 'article' } })).map((i) => i.id),
);
EOF

Both modes block explicit any / unknown annotations, casts to never, and @ts-ignore / @ts-expect-error / @ts-nocheck directives. Use console.log() for output: stdout is piped through cleanly so the command composes with | jq and similar.

Even outside an agentic context, cma:script is the fastest way to run a one-off script against a project: you get authentication and project-specific types out of the box, with nothing to set up. The file-mode shape is identical to the one produced by migrations:new, so a script that turns out to be worth keeping can be moved into the migrations directory and replayed as a migration without rewriting it.

environments:primary

Print the name of the project's primary environment. Mostly useful inside shell scripts and CI pipelines that need to know which environment to target programmatically; a human developer typically already knows this.

Terminal window
npx datocms environments:primary

Why these commands exist

A coding agent operating in your editor needs to discover, inspect, and operate on a DatoCMS project without going through a browser. Each of the commands above corresponds to one of those steps:

  • schema:inspect, cma:docs, and projects:list for discovery: figure out what the project contains, what the API can do, and which projects the account has access to.

  • cma:call and cma:script for operation: make changes through the CMA without scaffolding a Node project around them.

  • environments:primary for orientation: answer "which environment should I work on?" programmatically.

Combined with the rest of the CLI (auth, link, environments, migrations, schema generation), an agent has everything it needs to interact agentically with your DatoCMS project. The Agent Skills package the conventions and best practices that turn this surface into a productive workflow.

For the full list of flags accepted by each command above, see the datocms package README on GitHub or run datocms <command> --help.

Last updated: