Skip to content

Batches and Unattended Runs with the CLI

Run the CLI unattended: credentials, idempotency, authorization, and a cost-free smoke test of the purchase path.

Updated September 3, 20261 min readPostsale CLI

Automating Postsale from unattended runs means getting authorization right, keeping stdout clean, and failing closed when something risky is about to happen.

In this article, we will set non-interactive rules of thumb, sketch a unattended runs sequence, resume after partial failure, and use environment variables deliberately.

Before We Begin

This article assumes that:

  • You understand Safety Model and [Batch Work in Parallel](../features/parallel batch.md)
  • Secrets (token, LLM keys) are available to the job
  • For interactive multi-order shipping (not unattended runs), see Ship Many Orders

Rules for unattended runs

SituationRequirement
Direct money or destructive command--yes or exit 64
Parent postsale run money or destructive tools--yes or --authorize or fail
Parallel batches money or keyword-triggered batchBatch auth: TTY or POSTSALE_SWARM_AUTOAUTH=1
read-only parallel batch false positiveReword the template

Example unattended runs skeleton

Here's how a careful job might look:

bash
export POSTSALE_TOKEN="..."
export ANTHROPIC_API_KEY="..."

postsale doctor --pre-flight

# Read-only
postsale run "summarize carriers and origin addresses" > carriers.json

# Rehearsal
postsale run --dry-run "Ship order ${ORDER_ID} with the cheapest carrier" \
  > dry.json

# Live single order (parent only)
postsale run --authorize create_shipment,purchase_labels \
  "ship order ${ORDER_ID} with the cheapest carrier" > live.json

# Live swarm money only if pre-authorized
# export POSTSALE_SWARM_AUTOAUTH=1
# postsale run "ship today's ready orders cheapest" --yes

Parse stdout JSON. Keep stderr in logs for audit and debugging.

Resume after failure

bash
postsale conversations -n 5
postsale run --continue <id> "retry only the failed order ..."
postsale traces list
postsale traces show <trace_id>

Idempotency

  • Direct writes: --idempotency-key or POSTSALE_IDEMPOTENCY_KEY (else a UUID)
  • Parallel batches: deterministic keys from batch identity
  • Do not assume perfect backend dedup in every edge case

Environment checklist

See Environment variables. Critical for unattended runs:

  • POSTSALE_TOKEN, POSTSALE_ENVIRONMENT
  • LLM keys and optional provider override
  • POSTSALE_HTTP_TIMEOUT_MS and rate settings if you fan out hard
  • Trust variables only with eyes open (AUTHORIZED_TOOLS, SWARM_AUTOAUTH, CLI_V0_GUARD)
  • POSTSALE_TEST_LABEL_MODE=1 on a smoke-test job: the real purchase path runs against the carrier's test environment at zero cost, and any non-test shipment is refused before a request is sent. See Test Without Spending

Good to Know

A solid automation job:

  • Fails closed when authorization is missing
  • Parses stdout without scraping progress
  • Rehearses money paths with dry-run and test-label mode
  • Reviews batch templates for accidental money keywords on read jobs

Additional Reading