Skip to content

Repository files navigation

wpx -- WordPress CLI for AI Agents & Humans

CILicense: MIT/Apache-2.0Rust

Rust-native CLI for managing WordPress sites remotely via the REST API. Inspired by WP-CLI, but built from the ground up for AI agents -- because agents shouldn't need PHP installed to manage a WordPress site.

WP-CLI requires a local PHP runtime, a bootstrapped WordPress installation, and SSH access to run. That's fine for humans on a server, but it's a non-starter for AI coding agents like Claude, Cursor, or Codex that operate remotely over HTTPS. wpx solves this by communicating purely via the WordPress REST API as a single static binary with zero runtime dependencies.

Designed agent-first: structured JSON output, schema introspection, and semantic exit codes let AI agents operate WordPress programmatically. Designed human-friendly: auto-detecting table output, colored terminals, and shell completions make it pleasant for interactive use.

Features

  • Full WordPress REST API coverage -- 34 command groups spanning posts, pages, media, users, plugins, themes, menus, widgets, blocks, and more
  • Structured output -- JSON, Table, CSV, YAML, and NDJSON formats with automatic TTY detection
  • Schema introspection -- wpx schema <command> emits JSON Schema for any command's input/output
  • Semantic exit codes -- 11 distinct codes (0-10) so agents can programmatically decide retry/abort/fix strategies
  • Multi-site fleet management -- run commands across dozens of sites concurrently with wpx fleet exec
  • Application Passwords & OAuth 2.1 -- secure authentication without exposing wp-admin credentials
  • Field masking -- --fields id,title,status to reduce payload size for agent consumption
  • Automatic pagination -- --all-pages streams every result as NDJSON
  • Site discovery -- wpx discover <url> probes a site's REST API capabilities
  • Dry-run mode -- --dry-run previews destructive operations before executing

Quick Start

Install

Homebrew (macOS/Linux):

brew tap osodevops/wpx
brew install osodevops/tap/wordpress-cli

Cargo (from source):

cargo install --git https://github.com/osodevops/wordpress-cli wpx-cli

Binary download -- grab the latest release for your platform from the Releases page.

Configure a Site

wpx auth set --site production --username admin --password "xxxx xxxx xxxx xxxx"

Credentials are stored in ~/.config/wpx/credentials.toml with restricted file permissions.

Test Authentication

wpx auth test --site production

Your First Commands

# List recent posts (human-readable table in terminal)
wpx post list --site production
# Same command, but pipe to jq (auto-switches to JSON)
wpx post list --site production | jq '.[0].title'# List plugins as JSON
wpx plugin list --site production --output json
# Create a draft post
wpx post create --site production --title "Hello from wpx" --status draft
# Global search
wpx search "migration guide" --site production

Command Reference

Content

CommandDescriptionSubcommands
postManage postslist, get, create, update, delete, search
pageManage pageslist, get, create, update, delete
mediaManage media attachmentslist, get, update, delete
commentManage commentslist, get, create, update, delete
blockManage reusable blockslist, get, create, update, delete, search, render
searchGlobal search across content(direct command -- takes a query argument)

Taxonomy

CommandDescriptionSubcommands
categoryManage categorieslist, get, create, update, delete
tagManage tagslist, get, create, update, delete
taxonomyList and inspect taxonomieslist, get

Users

CommandDescriptionSubcommands
userManage userslist, get, me, create, update, delete

Site Management

CommandDescriptionSubcommands
pluginManage pluginslist, get, install, activate, deactivate, update, delete, status
themeManage themeslist, get, activate, delete, status
settingsManage site settingslist, get, set
optionAlias for settingslist, get, set

Block Editor

CommandDescriptionSubcommands
block-typeList and inspect block typeslist, get
block-patternList block patternslist
block-pattern-categoryList block pattern categorieslist

Navigation & Layout

CommandDescriptionSubcommands
menuManage navigation menuslist, get, create, update, delete
menu-itemManage menu itemslist, get, create, update, delete
menu-locationList and inspect menu locationslist, get
widgetManage widgetslist, get, create, update, delete
widget-typeList and inspect widget typeslist, get
sidebarList and inspect sidebarslist, get

Introspection

CommandDescriptionSubcommands
post-typeList and inspect post typeslist, get
post-statusList and inspect post statuseslist, get
discoverProbe a site's REST API capabilities(direct command -- takes a URL argument)
schemaShow JSON Schema for a command(direct command -- takes a command path)

Utilities

CommandDescriptionSubcommands
fleetRun commands across multiple sitesexec, status
authManage authenticationset, test, list, logout, oauth
infoShow version, sites, capabilities(direct command)
versionShow version information(direct command)
completionsGenerate shell completions(direct command -- takes a shell argument)

Global Flags

FlagEnv VarDefaultDescription
--site <name>WPX_SITEdefaultTarget site profile name
--url <url>WPX_URL--Direct URL override (skips profile lookup)
--output <fmt>WPX_OUTPUTautoOutput format: json, table, csv, yaml, ndjson, auto
--fields <f1,f2>----Comma-separated field mask to reduce output
--no-colorNO_COLOR--Disable colored output
--no-promptWPX_NO_PROMPT--Disable all interactive prompts
--quiet----Suppress non-essential output
--verbose----Enable debug logging to stderr
--timeout <secs>WPX_TIMEOUT30Request timeout in seconds
--retries <n>WPX_RETRIES3Retry count for failed requests
--dry-run----Show what would be done without executing
--confirm----Skip confirmation prompts for destructive actions
--all-pages----Fetch all pages and stream results (forces NDJSON)

Configuration

Config Files

  • User-level:~/.config/wpx/config.toml
  • Project-level:./.wpx.toml (checked in to your repo for team defaults)
  • Credentials:~/.config/wpx/credentials.toml (never commit this)

Example config.toml:

[default]
output = "json"timeout = 60retries = 5
[sites.production]
url = "https://example.com"auth = "application-password"username = "admin"
[sites.staging]
url = "https://staging.example.com"auth = "application-password"username = "editor"

Environment Variables

VariableDescription
WPX_SITEDefault site profile name
WPX_URLDirect WordPress URL (bypasses profile lookup)
WPX_OUTPUTDefault output format
WPX_TIMEOUTRequest timeout in seconds
WPX_RETRIESRetry count for failed requests
WPX_NO_PROMPTDisable interactive prompts
NO_COLORDisable colored output (standard convention)

Precedence

CLI flags > env vars > project config (.wpx.toml) > user config (~/.config/wpx/config.toml) > defaults

Authentication

Application Passwords (Recommended)

WordPress 5.6+ supports Application Passwords natively. No plugins required.

  1. Log in to wp-admin and navigate to Users > Profile
  2. Scroll to Application Passwords
  3. Enter a name (e.g., "wpx CLI") and click Add New Application Password
  4. Copy the generated password (spaces are fine -- wpx strips them)
  5. Store it with wpx:
wpx auth set --site production --username admin --password "XXXX XXXX XXXX XXXX"

OAuth 2.1

For environments that require OAuth (headless WordPress, enterprise SSO):

wpx auth oauth \
--site production \
--client-id "your-client-id" \
--authorize-url "https://example.com/oauth/authorize" \
--token-url "https://example.com/oauth/token"

This opens a browser for the authorization code flow with PKCE, then stores the resulting token.

Output Formats

wpx supports six output formats. By default (--output auto), it renders tables when stdout is a TTY and JSON when piped.

FormatFlagDescription
Auto--output autoTable if TTY, JSON if piped
JSON--output jsonPretty-printed JSON
Table--output tableASCII table for human reading
CSV--output csvComma-separated values
YAML--output yamlYAML format
NDJSON--output ndjsonNewline-delimited JSON (one object per line)
# Interactive terminal: auto-renders a table
wpx post list --site production
# Piped to another program: auto-switches to JSON
wpx post list --site production | jq '.[] | .title'# Force a specific format
wpx plugin list --site production --output csv > plugins.csv

Fleet Management

Run commands across multiple WordPress sites concurrently:

# Check plugin status across all configured sites
wpx fleet exec"plugin list" --sites "production,staging,dev"# Update a plugin everywhere (with concurrency limit)
wpx fleet exec"plugin update --slug akismet" --concurrency 3
# Check fleet health
wpx fleet status

Exit Codes

Every wpx command returns a semantic exit code that agents can use for programmatic error handling:

CodeNameDescription
0SuccessCommand completed successfully
1General ErrorUnclassified error
2Invalid ArgsBad CLI arguments or configuration
3Auth FailureAuthentication failed (bad credentials, expired token)
4Not FoundRequested resource does not exist
5Permission DeniedAuthenticated but not authorized
6Rate LimitedToo many requests (check retry_after_secs in error JSON)
7Network ErrorDNS, TLS, or connection failure
8Server ErrorWordPress returned HTTP 5xx
9ConflictResource conflict (e.g., duplicate slug)
10Validation ErrorInvalid field value (check field in error JSON)

Errors are emitted as structured JSON on stderr:

{
"error": true,
"message": "Resource not found: post 99",
"exit_code": 4,
"resource": "post",
"id": "99",
"suggestion": "Use 'wpx post list' to find valid IDs"
}

Schema Introspection

Agents can discover the input/output shape of any command at runtime:

# Show schema for a specific command
wpx schema post list
# List all available schemas
wpx schema

Architecture

wpx binary (6 crates)
├── wpx-cli CLI parsing (clap), command dispatch, shell completions
├── wpx-core Resource trait, domain types, semantic exit codes
├── wpx-api HTTP client (reqwest + rustls), retry, pagination
├── wpx-auth Application Passwords, OAuth 2.1 (PKCE)
├── wpx-config TOML config, site profiles, credential store
└── wpx-output JSON, Table, CSV, YAML, NDJSON rendering

All crates share a workspace version (0.1.0) and are published together.

Building from Source

# Clone
git clone https://github.com/osodevops/wordpress-cli.git
cd wordpress-cli
# Build
cargo build --release
# Run tests
cargo test --workspace
# Lint
cargo clippy --workspace -- -D warnings
# The binary is at target/release/wpx
./target/release/wpx --version

Generate Shell Completions

# Bash
wpx completions bash >~/.local/share/bash-completion/completions/wpx
# Zsh
wpx completions zsh >~/.zfunc/_wpx
# Fish
wpx completions fish >~/.config/fish/completions/wpx.fish

License

Licensed under either of:

at your option.

About

Rust-native WordPress CLI for AI agents & humans. Manages sites remotely via REST API with fleet management, structured output, and schema introspection.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages