Skip to main content
seofields
docs

CLI Configuration

Configure the CLI with a config file to store your Sanity credentials and avoid passing flags on every command.

Quick Setup

The fastest way to create a config file is with the interactive wizard:

bash
npx seofields create-config

This will prompt you for your project ID, dataset, and token, then generate the config file automatically.

Manual Setup

Create a seofields.cli.ts (or .js) file in your project root:

TypeScript

seofields.cli.ts
// seofields.cli.ts
import { defineSeoCli } from "sanity-plugin-seofields/define-cli";

export default defineSeoCli({
  projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID!,
  dataset: process.env.NEXT_PUBLIC_SANITY_DATASET!,
  token: process.env.SANITY_READ_TOKEN,
});

JavaScript

seofields.cli.js
// seofields.cli.js
import { defineSeoCli } from "sanity-plugin-seofields/define-cli";

export default defineSeoCli({
  projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
  dataset: process.env.NEXT_PUBLIC_SANITY_DATASET,
  token: process.env.SANITY_READ_TOKEN,
});

All Options

OptionTypeDescription
projectIdstringSanity project ID (required)
datasetstringDataset name, e.g. "production" (required)
tokenstring?API token with at least viewer access
typesstring[]?Limit report/export to these document types
showConnectionInfoboolean?Print source of credentials after report
seofields.cli.ts
// seofields.cli.ts
import { defineSeoCli } from "sanity-plugin-seofields/define-cli";

export default defineSeoCli({
  // Required: Sanity project ID
  projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID!,
  
  // Required: Dataset name
  dataset: process.env.NEXT_PUBLIC_SANITY_DATASET!,
  
  // Optional: API token (needs read access)
  token: process.env.SANITY_READ_TOKEN,
  
  // Optional: Limit report/export to specific document types
  types: ["post", "page", "article"],
  
  // Optional: Show project/dataset source after report
  showConnectionInfo: true,
});

Environment Variables

The CLI automatically loads .env, .env.local, and .env.development.local files at startup. Use process.env.VAR_NAME in your config file and it will resolve at runtime.

.env.local
# .env or .env.local
NEXT_PUBLIC_SANITY_PROJECT_ID="your-project-id"
NEXT_PUBLIC_SANITY_DATASET="production"
SANITY_READ_TOKEN="skXXXXXX..."

Resolution Order

When determining project ID, dataset, and token, the CLI checks these sources in order:

  1. 1

    CLI flags

    --project-id, --dataset, --token

    Highest priority — always wins

  2. 2

    seofields.cli.ts / .js

    defineSeoCli({ projectId: ... })

    Your dedicated CLI config file

  3. 3

    Environment variables

    SANITY_PROJECT_ID, SANITY_DATASET, SANITY_TOKEN

    Also checks NEXT_PUBLIC_* variants

  4. 4

    sanity.config.ts / .js

    Auto-detected from defineConfig()

    Fallback for project ID and dataset only

Supported File Names

The CLI looks for config files in this order:

  • seofields.cli.ts
  • seofields.cli.js
  • seofields.cli.mjs
  • seofields.cli.cjs

💡 Tips

  • Token permissions: The token only needs viewer access for report and export commands.
  • Git ignore: If you hardcode credentials, add seofields.cli.ts to your .gitignore.
  • showConnectionInfo: Enable this to debug which source your credentials are being read from.

Was this page helpful?