I/O and schemas
This page covers everything an agent needs to read and write data with
wrangler-deploy.
Output: --json and --ndjson
Section titled “Output: --json and --ndjson”Every command that has a structured result supports --json. The output is
written to stdout as a single JSON document:
wd plan --stage staging --jsonFor list-style commands (and the dev event stream),
use --ndjson to get one object per line:
wd status --ndjsonwd dev --ndjsonThe schema for any command’s output is queryable:
wd schema outputs --json # every commandwd schema outputs --command apply --json # one commandwd schema outputs --command devEvent --json # dev event streamField projection: --fields
Section titled “Field projection: --fields”Pass a comma-separated list of dot-paths to project the output. Useful for keeping JSON small when only a few keys matter:
wd status --stage staging --json --fields stage,workers.api.urlNested objects and arrays are honoured. Missing paths are silently dropped.
Persisting output: --output-file
Section titled “Persisting output: --output-file”Pass --output-file <path> and the first JSON payload emitted by the command
will also be written to that path:
wd plan --stage staging --json --output-file .wrangler-deploy/plans/staging.jsonwd deploy --stage staging --json --output-file .wrangler-deploy/deploys/staging.jsonWorks on every JSON-emitting command — it’s wired into printJson itself,
not per-command code. For commands that emit multiple ticks (like
status --watch), only the first tick is persisted to avoid churn.
The directory is created if missing. Existing files are overwritten.
Reading input: --input
Section titled “Reading input: --input”Pass --input <path> to read JSON from a file, or --input - to read from stdin:
echo '{"only":["workers/api"],"onlyResources":["kv"]}' | \ wd plan --stage staging --input - --json
wd deploy --stage staging --input deploy-targets.json --jsonCurrently honoured by plan, apply, and deploy. Recognised keys merge
with CLI flags:
| Key | Equivalent flag |
|---|---|
only (string[]) | --only (repeatable) |
onlyResources (string[]) | --only-resources (repeatable) |
stage (string) | --stage (CLI flag still wins) |
Invalid JSON returns a structured error:
{ "ok": false, "command": "wd plan", "error": { "type": "validation", "code": "WD_E_VALIDATION", "message": "--input file ... is not valid JSON: ...", "retryable": false, "fix": "Validate the JSON file." }}Secret redaction: --no-secrets-in-output
Section titled “Secret redaction: --no-secrets-in-output”Pass --no-secrets-in-output (or set WD_NO_SECRETS=1, or AGENT_SANDBOX=1)
to strip secret-shaped values from JSON output before it goes to stdout and
to disk:
- Any object key matching
*SECRET*,*TOKEN*,*PASSWORD*,*KEY*,*API_KEY*,*PRIVATE*(case-insensitive) becomes[REDACTED] - Any standalone string of 40+ alphanumeric characters becomes
[REDACTED]
This redaction happens in printJson so it covers both stdout and --output-file
artifacts.
Schema introspection
Section titled “Schema introspection”The CLI publishes four kinds of schema:
CLI manifest
Section titled “CLI manifest”wd schema --json # full manifestwd schema --versioned --json # with schemaVersion + outputs + config bundledwd tools --json # tool metadata view (one entry per command)The manifest declares per-command flags, subcommands, mutating,
requiresAuth, requiresStage, network, writesFiles, supportsDryRun,
and the global agentEnvVars/globalFlags lists.
Output schemas
Section titled “Output schemas”wd schema outputs --jsonwd schema outputs --command apply --jsonwd schema outputs --command devEvent --jsonSchemas exist for: error, version, examples, plan, apply, deploy,
destroy, status, verify, check, gc, secrets, doctor, open,
dashboard, statusWatch, explain, history, rollbackList, devEvent.
Config schema
Section titled “Config schema”wd schema config --jsonReturns a Draft-07 JSON Schema for wrangler-deploy.config.ts. Use this in
agent-generated configs to validate before writing the file.
Error schema
Section titled “Error schema”wd schema errors --jsonReturns the error envelope schema plus the full list of WD_E_* codes and
error.type enum values. See Structured errors.
Examples
Section titled “Examples”wd examples --json # list every command that has exampleswd examples --command deploy --json # copy-pasteable snippets for one commandEach set has a summary and an array of { description, command, notes? }.
Useful for an agent that wants a verified canonical invocation rather than
inventing one from --help.
End-to-end example
Section titled “End-to-end example”# 1. Discover what the binary can dowd schema --json --output-file .wrangler-deploy/manifest.jsonwd schema config --json --output-file .wrangler-deploy/config-schema.json
# 2. Plan with a structured input, persist the planecho '{"only":["workers/api"]}' | \ wd plan --stage staging --input - --json \ --output-file .wrangler-deploy/plans/staging-api.json
# 3. Dry-run apply, persist the previewwd apply --stage staging --dry-run --json \ --output-file .wrangler-deploy/plans/staging-apply-dry.json
# 4. Real deploy, persist the resultwd deploy --stage staging --json \ --output-file .wrangler-deploy/deploys/staging.json
# 5. Verifywd verify --stage staging --json \ --output-file .wrangler-deploy/verify/staging.jsonEvery step writes a JSON artifact you can diff, review, or feed to the next step.