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. This is typically the first command an agent runs against an unfamiliar project.

Terminal window
npx datocms schema:inspect

A human typically inspects the schema visually in the dashboard. For a typed snapshot to use in your code, schema:generate is the right command: it emits a TypeScript file rather than a dump.

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

If you are a human, the online CMA reference is more ergonomic.

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

A human typically picks a project from the dashboard.

cma:call

Make a single Content Management API call from the terminal, without setting up a Node project.

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

If you are a human, importing @datocms/cma-client-node in a TypeScript file in your editor gives you auto-completion and is usually nicer.

cma:script

Run a one-off TypeScript script against the Content Management API, with a pre-configured client and the project schema as ambient types. Accepts either a file (export default async function(client: Client)) or stdin with top-level await.

Terminal window
npx datocms cma:script ./script.ts
echo "console.log(await client.items.list({ filter: { type: 'article' } }))" | npx datocms cma:script

If you are a human and your script is more than a handful of lines, write it as a regular TypeScript file in your project and run it with your usual tooling.

environments:primary

Print the name of the project's primary environment.

Terminal window
npx datocms environments:primary

Mostly useful inside shell scripts and CI pipelines that need to know which environment to target programmatically. A human developer normally knows this already.

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: