Skip to main content

Settlement

Every capability call that costs sats goes through one settlement pipeline: verify authority, reserve budget, approval gate (if configured), execute, settle or release, sign a receipt. The two settlement.mode values differ in whether real money moves.

simulated (default)​

settlement:
mode: simulated

The entire pipeline runs (credential minting, budget reservation, payment, settlement, signed receipt) against an in-process L402 endpoint. No wallet, no keys, no network call to a real capability provider. Every artifact from a simulated run is marked "simulated": true in its output (see the infra.json example in Your first mission). This is the recommended mode for evaluation, development, and demos, and it's the default if a manifest omits settlement entirely.

wallet (real Lightning)​

settlement:
mode: wallet

Wallet mode makes real Lightning payments from your own wallet, bounded by the manifest budget. It is opt-in per manifest; nothing in Writ switches it on for you.

Set up a wallet​

Writ finds your wallet from environment variables in the shell that runs writ run. Set the variables for one wallet. When several are set, Writ uses the first it finds in this order: LND, NWC, Strike.

WalletVariables
LNDLND_REST_HOST: your node's REST URL, for example https://localhost:8080. LND_MACAROON_HEX: a macaroon that can pay invoices, hex-encoded. LND_TLS_CERT_PATH (optional): the node's TLS certificate.
NWC (Nostr Wallet Connect)NWC_CONNECTION_STRING: the nostr+walletconnect:// connection string your wallet app creates. NWC_ENCRYPTION (optional): auto (default), nip04, or nip44_v2; some wallets need nip44_v2 and others nip04.
StrikeSTRIKE_API_KEY: an API key from your Strike account.

These values are secrets: keep them out of manifests (Writ refuses to interpolate them) and out of shell history. Give the wallet connection its own spending limit in your wallet app where it offers one, so the most it can spend is bounded outside Writ too. An OPENNODE_API_KEY is also detected, but OpenNode returns no payment preimage, so it cannot pay L402 invoices and Writ refuses it before any money moves.

writ run prints this warning before anything executes whenever a manifest resolves to wallet settlement and it isn't a dry run:

WARNING: wallet settlement — this run makes REAL Lightning payments, bounded by the mission budget (100 sats total).

A --dry-run on a wallet-mode manifest never prints this banner and never touches the wallet; it only plans.

Preimage requirement: L402 needs a wallet that returns a payment preimage on completion; it is the proof a receipt commits to. LND, NWC (most implementations), and Strike return one.

The price check happens before money moves. Every invoice's amount must be strictly positive and at or under both the capability's own ceiling and budget.per_call_max_sats before Writ pays it. An amountless, zero, or over-cap invoice is refused, and nothing is sent.

The model-CLI pre-flight probe​

If a manifest declares a paid (l402-http) capability, resolves to a CLI-backed model provider (claude-cli or codex — see the manifest reference), and has at least one step that will call the model (an agent step, or a call to any internal capability other than compose or compose.*), Writ runs a one-time pre-flight probe of that CLI at the very start of the run: a trivial completion using the exact flags and tool restrictions the real call would use, under a 30-second timeout, spending nothing.

Why: without the probe, a broken or unauthenticated CLI would only surface on the run's first model call — which, in a mission shaped "paid step first, model step second," is after real sats have already settled. The probe catches that before any capability is invoked:

15:33:22 warn: Writ.Engine.Llm.ClaudeCliLlmClient[0] claude CLI exited non-zero: ExitCode=1. Stderr (first 200 chars): ...

If the probe fails, the run fails pre-flight, before any capability call happens, naming the exit code and a bounded stderr excerpt (never the prompt or response body; see What the guardrails are designed to do). A manifest with no paid capability, or one whose steps never call the model (such as the first mission), skips the probe, so a missing claude binary can't fail a mission that never needed it. When the probe can't even start the executable, the run fails with exit 3 and a single line, no stack trace:

Pre-flight check failed: model provider 'claude-cli' needs the 'claude' executable, which could not be started (not installed, or not on PATH). Install it and make sure it is on PATH, or use the HTTP API instead: set `model.provider: anthropic` and export ANTHROPIC_API_KEY (removing the `model:` block does the same). No capability was invoked and nothing was settled.

The same step-aware rule applies to the service hosts: a catalog that serves only compose and paid capabilities does not probe the CLI at startup.

claude-cli on Windows

On Windows, Writ launches the target of npm's claude.cmd shim directly, without cmd.exe, so claude-cli steps run there with multi-line arguments intact. The claude --version command must work in the shell that runs Writ.

Ambiguous payment outcomes​

Wallet-mode payments are the one place Writ can't retry or roll back on its own. The invoice's payment hash is read before paying (an invoice with no payment hash is never paid). If the wallet call afterward times out, errors, or returns proof Writ can't use, Writ does not assume the money stayed put, because it might not have.

Instead:

  1. The budget hold is kept as pending_reconciliation, tagged with the invoice's payment hash.
  2. The run halts and exits 7, naming the invocation and the payment hash.
  3. Nothing is released, and nothing is double-counted as spent, until you run writ reconcile.
Invocation 3 is still pending reconciliation (payment hash 1b44320d..., 25 sats held): <reason>
Check the payment in your wallet by that hash, then run: writ reconcile <run-id> --invocation 3 --resolve paid|not-paid

writ reconcile first asks the wallet itself to look the payment up by hash: LND and NWC can usually answer; Strike's API has no lookup of an outgoing payment by hash, so a Strike hold needs your explicit --resolve paid|not-paid attestation, and --resolve not-paid on it also needs --allow-unconfirmed-not-paid, which the audit log records. See Approvals and budgets for the walkthrough. simulated mode never produces this state.

--production​

writ run --production takes a fail-closed posture: no dev-ephemeral signer (a persistent key-file or env signer and its identity record are required), WRIT_ROOT_KEY must be set, and wallet settlement is required. Use it for runs that spend real money and whose evidence you keep.

Next steps​