| name | payload-cli |
| description | PayloadCMS CLI for AI agents. Use when the user needs to create, read, update, or delete CMS content, upload/download media files, inspect collection schemas, or manage PayloadCMS data from the command line. |
| allowed-tools | Bash(npx payload-cli:*), Bash(payload-cli:*), Bash(pnpm payload-cli:*) |
payload-cli - PayloadCMS CLI for Agents
A command-line tool that gives you direct access to PayloadCMS data. No MCP, no protocol overhead. Just commands.
Core Workflow
Always follow this pattern when working with PayloadCMS data:
payload-cli collections
payload-cli describe posts
payload-cli describe posts --fields
payload-cli describe posts --examples
payload-cli find posts --limit 5
payload-cli create posts --data '{"title": "My Post", "status": "draft"}'
payload-cli find-by-id posts <id>
Rules
-
ALWAYS run payload-cli describe <collection> before creating or updating documents. This outputs the TypeScript interface from payload-types.ts showing the exact data shape Payload expects โ optional fields have ?, union types show valid values, relationship types show what they resolve to. Use --fields for a detailed field breakdown with constraints, localized flags, and defaults. Use --examples to see the expected structure of json fields (custom editors, tables, etc.).
-
ALWAYS preview destructive operations. payload-cli delete and payload-cli delete-many show a preview by default. Only add --confirm after verifying the preview.
-
Use --json when you need to parse output programmatically. Human-readable output is the default.
-
Use --select to limit returned fields when you only need specific data. This reduces output size.
-
Use --dry-run for write operations when you want to validate data without persisting it.
Command Reference
Introspection
payload-cli collections
payload-cli describe <collection|global>
payload-cli describe <collection> --fields
payload-cli describe <collection> --examples
payload-cli globals
payload-cli status
Reading Data
payload-cli find <collection> [--where '{"field":{"operator":"value"}}'] [--limit N] [--page N] [--sort field] [--select '{"field":true}'] [--depth N]
payload-cli find-by-id <collection> <id> [--depth N] [--select '...']
payload-cli get-global <slug> [--depth N] [--select '...']
Writing Data
payload-cli create <collection> --data '{"field":"value"}' [--dry-run]
payload-cli create <collection> --data '{"title":"About"}' --file 'heroImage=./hero.jpg'
payload-cli update <collection> <id> --data '{"field":"new value"}' [--dry-run]
payload-cli update <collection> <id> --data '{}' --file 'heroImage=./new-hero.jpg'
payload-cli update-many <collection> --where '{"field":{"equals":"value"}}' --data '{"field":"new value"}' [--dry-run]
payload-cli update-global <slug> --data '{"field":"value"}' [--dry-run]
Media (Upload / Download)
payload-cli upload <collection> <file|dir> [--data '{"alt":"..."}'] [--dry-run]
payload-cli upload <collection> ./file1.jpg ./file2.png
payload-cli upload <collection> ./photos/
payload-cli download <collection> <id> [--out ./path/]
payload-cli download <collection> --where '{"alt":{"contains":"hero"}}' [--out ./path/]
Deleting Data (requires --confirm)
payload-cli delete <collection> <id>
payload-cli delete <collection> <id> --confirm
payload-cli delete-many <collection> --where '{"status":{"equals":"draft"}}'
payload-cli delete-many <collection> --where '{"status":{"equals":"draft"}}' --confirm
Global Flags
| Flag | Description |
|---|
--json | Output as JSON for machine parsing |
--dry-run | Validate without executing writes |
--confirm | Confirm destructive operations |
--config <path> | Path to payload.config.ts |
--include-sensitive | Include sensitive fields in output |
Where Clause Syntax
The --where flag uses Payload's query syntax as JSON:
--where '{"status":{"equals":"published"}}'
--where '{"status":{"not_equals":"draft"}}'
--where '{"createdAt":{"greater_than":"2024-01-01"}}'
--where '{"title":{"contains":"hello"}}'
--where '{"and":[{"status":{"equals":"published"}},{"title":{"contains":"hello"}}]}'
--where '{"or":[{"status":{"equals":"draft"}},{"status":{"equals":"archived"}}]}'
Common Patterns
Create a blog post
payload-cli describe posts
payload-cli create posts --data '{"title":"My New Post","status":"draft","slug":"my-new-post"}'
Find and update a document
payload-cli find posts --where '{"title":{"contains":"hello"}}' --select '{"id":true,"title":true}'
payload-cli update posts <id> --data '{"status":"published"}'
Bulk publish drafts
payload-cli find posts --where '{"status":{"equals":"draft"}}' --limit 100
payload-cli update-many posts --where '{"status":{"equals":"draft"}}' --data '{"status":"published"}' --dry-run
payload-cli update-many posts --where '{"status":{"equals":"draft"}}' --data '{"status":"published"}'
Clean up old content
payload-cli delete-many posts --where '{"status":{"equals":"archived"}}'
payload-cli delete-many posts --where '{"status":{"equals":"archived"}}' --confirm
Upload media and attach to content
payload-cli describe pages
payload-cli upload media ./hero.jpg --data '{"alt":"Hero image"}'
payload-cli create pages --data '{"title":"About"}' --file 'heroImage=./hero.jpg'
Bulk upload images
payload-cli upload media ./photos/
payload-cli upload media ./img1.jpg ./img2.png
Error Handling
payload-cli provides AI-friendly error messages:
- Unknown field names: Suggests the closest matching field
- Missing required fields: Lists which fields are required
- Invalid collection: Shows available collections with suggestions
- Validation errors: Tells you exactly what failed and hints at how to fix it
When you see an error, run payload-cli describe <collection> to review the schema.
Output Modes
- Human mode (default): Readable tables and formatted output
- JSON mode (
--json): Raw JSON, suitable for piping to jq or parsing
Sensitive fields (password hashes, API keys, etc.) are automatically redacted unless --include-sensitive is passed.
Deep-Dive References