Approvals and budgets
Writ bounds spend two ways: a hard budget cap that every call is checked against before it proceeds, and an optional human approval gate for calls at or above a threshold you set, or that would take the spend made without your approval over a cumulative or per-window threshold.
Budget enforcement
budget.total_sats is a cumulative cap enforced at the credential-chain root: every sat any worker or delegated sub-worker spends counts against the same pool. budget.per_call_max_sats and each capability's own max_sats_per_call further cap any single call (the lower of the two wins).
Before a call runs, Writ reserves its ceiling against the remaining budget in one database update that succeeds only when the reservation fits. Concurrent calls are checked against the same remaining amount, so together they never reserve more than the cap.
A mission with a paid (l402-http) capability and a zero or missing budget.total_sats is refused by writ validate and writ run before anything runs (exit 2):
Manifest invalid (2 problem(s)):
- Top-level worker budgets sum to 40 sats, which exceeds budget.total_sats (0).
- budget.total_sats must be greater than 0 when the mission declares a paid (l402-http) capability; a zero or missing cap would allow unbounded spend.
The approval gate
Set approvals.threshold_sats in the manifest to require a human decision on any call at or above that amount:
approvals:
threshold_sats: 10
0 means every paid call needs approval. Omit approvals (or leave it {}) for fully autonomous operation.
In settlement.mode: simulated, a call is charged its capability ceiling (max_sats_per_call), so whether a capability trips the threshold depends only on the manifest. A mission with threshold_sats: 10 and a capability whose ceiling is 20 suspends on every call to that capability.
When a call crosses the threshold, the run suspends instead of failing (exit 4). To approve the call and finish the same run, the run must be resumable, which takes the setup in the next section.
Approve and resume a run, end to end
A suspended run continues with writ resume. A run can be resumed only when it started with both of these:
WRIT_ROOT_KEYset, to the same value when you resume. Writ derives the run's authority key from it; the value is any secret string you choose and keep. Without it, Writ uses a throwaway authority key that no other process can verify.- A persistent signer:
work_record.signing: key-file(orenv). Adev-ephemeralkey exists only in the process that ran the run.
Run these from an empty directory.
1. Create a signing key. This writes keys/receipt.key (private) and keys/signer-identity.json (public):
writ keys init --operator-name "Example Operator"
2. Save this manifest as mission.yaml. It makes one paid call whose 20-sat ceiling is above the 10-sat threshold:
mission:
name: approval-demo
goal: "One paid call that needs a person's approval."
budget:
total_sats: 50
per_call_max_sats: 25
settlement:
mode: simulated
approvals:
threshold_sats: 10
capabilities:
- id: data.premium
kind: l402-http
base_url: https://api.example.test/data
path: /fetch
method: GET
max_sats_per_call: 20
workers:
- name: buyer
scope: [data.premium]
budget_sats: 40
steps:
- type: call
capability: data.premium
input: { q: premium }
output: premium.json
work_record:
signing: key-file
key_file: keys/receipt.key
output_dir: runs/
3. Set WRIT_ROOT_KEY to a long random secret. These commands generate one without printing it:
export WRIT_ROOT_KEY="$(openssl rand -hex 32)"
$env:WRIT_ROOT_KEY = [Convert]::ToHexString([Security.Cryptography.RandomNumberGenerator]::GetBytes(32))
Keep the value where you keep other secrets, for example a password manager: writ resume needs the same value. To copy it there, print it once with printenv WRIT_ROOT_KEY (bash) or $env:WRIT_ROOT_KEY (PowerShell).
4. Run the mission. It suspends at the gated call (exit 4):
writ run mission.yaml
Running mission 'approval-demo' (run approval-demo-20261117-002310-8cd93b408d164e67a903ca0b80dea931)...
· buyer/mission.data.premium 0 sats ApprovalRequired
Run approval-demo-20261117-002310-8cd93b408d164e67a903ca0b80dea931: ApprovalRequired
Spent 0 / 50 sats · settlement simulated · 0 receipt(s)
Outputs:
- runs/approval-demo-20261117-002310-.../work-record.jsonl
- runs/approval-demo-20261117-002310-.../usage.json
- runs/approval-demo-20261117-002310-.../run.json
- runs/approval-demo-20261117-002310-.../report.html
Suspended — pending approval #1. Approve with: writ approvals approve 1 --run approval-demo-20261117-002310-8cd93b408d164e67a903ca0b80dea931
Then continue the run with: writ resume approval-demo-20261117-002310-8cd93b408d164e67a903ca0b80dea931 mission.yaml
Spend requires human approval.
The CLI prints absolute paths; the samples on this page shorten them. Replace the run id in the next commands with the one your run printed.
5. Review the request, then approve it:
writ approvals list --run approval-demo-20261117-002310-8cd93b408d164e67a903ca0b80dea931
Pending approvals for run 'approval-demo-20261117-002310-8cd93b408d164e67a903ca0b80dea931':
#1 mission.data.premium 20 sats — buyer:data.premium
resource /fetch → api.example.test (invocation #1); valid 15 min once approved
writ approvals approve 1 --run approval-demo-20261117-002310-8cd93b408d164e67a903ca0b80dea931
Approved #1. Continue the run with: writ resume approval-demo-20261117-002310-8cd93b408d164e67a903ca0b80dea931 <manifest> (the manifest it started with).
To refuse it instead, run writ approvals deny 1 --run <run-id>, which prints Denied #1.
6. Resume the run in a shell where WRIT_ROOT_KEY holds the same value:
writ resume approval-demo-20261117-002310-8cd93b408d164e67a903ca0b80dea931 mission.yaml
Resuming mission 'approval-demo' (run approval-demo-20261117-002310-8cd93b408d164e67a903ca0b80dea931)...
· buyer/mission.data.premium 20 sats Executed (simulated)
Run approval-demo-20261117-002310-8cd93b408d164e67a903ca0b80dea931: Completed
Spent 20 / 50 sats · settlement simulated · 1 receipt(s)
Outputs:
- runs/approval-demo-20261117-002310-.../premium.json
- runs/approval-demo-20261117-002310-.../work-record.jsonl
- runs/approval-demo-20261117-002310-.../usage.json
- runs/approval-demo-20261117-002310-.../run.json
- runs/approval-demo-20261117-002310-.../report.html
Verify: writ verify runs/approval-demo-20261117-002310-... --pubkey 3b2b9a7e0db5ae925b90f772737618fe99ddf0af751ed4013d8a43192dec9a3a
A run that started without WRIT_ROOT_KEY, or with a dev-ephemeral signer, still suspends at the gate, and says what to set before you run the mission again:
Suspended — pending approval #1.
This run cannot be resumed: it started without WRIT_ROOT_KEY. To approve and continue a run, set WRIT_ROOT_KEY to a secret you keep and use work_record.signing: key-file (or env), then run the mission again.
Spend requires human approval.
Cumulative and windowed thresholds
threshold_sats looks at one call at a time, so an agent could split a large spend into many calls just under it. Two more thresholds bound what an agent spends without you, across calls:
approvals:
threshold_sats: 50 # per call (optional)
cumulative_threshold_sats: 200 # total unapproved spend for the run
window_threshold_sats: 60 # unapproved spend per rolling window...
window_seconds: 3600 # ...of one hour
A call needs approval when any of these holds:
- Per call: the call's ceiling is at or above
threshold_sats. - Cumulative: the spend already made without approval in this run, plus this call's ceiling, would be more than
cumulative_threshold_sats. - Window: the spend made without approval in the last
window_seconds, plus this call's ceiling, would be more thanwindow_threshold_sats.
How the count works:
- It is read from the database, not from memory, so it survives a crash and
writ resume. A call whose payment is reserved, awaiting reconciliation, or completed with its receipt pending recovery counts at its ceiling (an in-flight payment counts as spent). A settled call counts at what actually moved: the amount the ledger charged, plus any proven payment the budget caps had no room for. - Spend you approved is not counted. Approving does not reset the count either.
- Headroom still runs. A call is held only when it would not fit. While a larger call waits for you, a smaller call that still fits under the threshold runs without asking.
- A denial does not stick. Denying a request refuses that attempt. The same call is judged again the next time it is made, and runs without asking if it fits by then (for example, after older spend has left the window).
- The window is keyed on reservation time: spend counts in the window when its budget hold was taken within the last
window_seconds, whenever it settled. - The scope of a manifest's thresholds is the run. Every worker and delegated sub-worker in the run shares one count; a worker cannot start a fresh count by delegating.
- Concurrent calls cannot both slip under. The check is repeated inside the same database transaction that reserves the budget, so when two calls race for the last few sats, one of them is asked. That transaction holds the database's write lock while it reads the count: one aggregate query over the scope's rows (a host-wide cumulative threshold reads every row in the host's database), so each paid call under an aggregate threshold costs that query twice (once to decide whether to ask, once inside the reservation), and its cost grows with the history it reads. Measured on Windows with 50,000 settled rows in scope: about 120 ms per query, and about 240 ms added to each paid call.
- A request that was raised waits for a decision. If the window rolls over while a request is pending, the same call still waits for you; approve or deny it.
The count is designed to keep the spend made without approval at or under the threshold, but it can end up above it:
- when a payment proven after the fact moved more than the call reserved (a late extra payment, or a payment that arrived after its hold was released);
- when spend was made before the threshold was set or lowered (a service host whose configuration changed).
writ approvals list says which threshold raised each request, with the numbers. For three 5-sat calls under cumulative_threshold_sats: 10, the third is held:
Pending approvals for run 'cumulative-demo-20261117-002355-5e66825e19f746aba578932ede6d75eb':
#1 mission.data.lookup 5 sats — researcher:data.lookup
resource /lookup → api.example.test (invocation #3); valid 15 min once approved
why: cumulative threshold: 10 sats already spent without approval + this call's 5 sats would exceed 10 sats for this run
A service host sets the same thresholds with WRIT_APPROVAL_CUMULATIVE_SATS, WRIT_APPROVAL_WINDOW_SATS and WRIT_APPROVAL_WINDOW_SECONDS (each greater than 0 when set). A host's thresholds are host-wide: they count the spend made without approval under every writ and in every workspace in that host's database, so issuing a new writ or naming another workspace does not start a fresh count. One workspace's spend therefore affects every other workspace on that host, and is visible to them in aggregate: the countedSats a held call reports for a host_cumulative or host_window gate is the host's total unapproved spend, across all workspaces, not that workspace's own. No request field changes them. writ_invoke returns approvalGate with the same details (host_cumulative or host_window), and writ_approvals lists them under gate.
With all three unset, the gate is per call only.
Who decides on a service host
The service hosts, writ-mcp (MCP server) and writ-api (HTTP API), are separate programs from the writ CLI: see Writ's programs. A service host serves two roles. The agent role runs calls, reads what remains and what happened, and sees the requests waiting for a decision. The operator role decides them, issues writs, and revokes. A spend held for approval waits for the operator's decision.
writ-mcpserves the agent role by default;writ-mcp --role operatoraddswrit_approve,writ_deny,writ_issueandwrit_revoke.- The HTTP API gives the agent token the agent routes and the operator token every route.
- The operator can also decide from the CLI, against the host's database:
writ approvals list --service-db ./.writ/writ.db
writ approvals approve 3 --service-db ./.writ/writ.db
After an approval, the agent retries the same call (same idempotency key) and it runs. In a mission run (writ run) the agent has no approval tool at all; requests are decided with writ approvals --run.
Run these with the host's WRIT_ROOT_KEY in the environment, after the host has started once. For how to set up the host so the operator's configuration stays the operator's, see Setting up the host.
What a grant is bound to
An approval isn't a blanket "yes": it's a grant for one specific call. A grant is bound to the exact combination of: workspace (run), credential, capability, amount ceiling, resource path, stated purpose, destination (the endpoint's authority, or the capability kind for an internal capability), and the invocation id that raised it. A full match on every one of those is required to consume it, so an approval for one purpose or path never authorizes a different call of the same capability because the amount happens to fit.
writ approvals list prints the dimensions that matter for a human decision: capability, amount, purpose, resource, and destination.
Approving the same request twice fails cleanly:
$ writ approvals approve 1 --run approval-demo-...
Could not approve #1: Approval request is already approved.
Exit 2. Same for denying (or approving) an id that doesn't exist:
$ writ approvals deny 999 --run approval-demo-...
Could not deny #999: Approval request not found.
Exit 2.
Approval TTL
A granted approval stays usable for 15 minutes by default after approval. After that it expires and is retired as a distinct outcome (expired), and a fresh pending request is raised in its place. A mission sets another value with approvals.approval_ttl_minutes (greater than 0; see the manifest reference), and a service host with WRIT_APPROVAL_TTL_MINUTES.
Superseded grants: at most one open grant (pending or approved-but-unconsumed) exists per binding. If the pipeline resolves an open grant against an invocation that's no longer a clean match (a failed or released attempt that gets a new invocation id, or an inconsistent state), the old grant is retired as superseded and a fresh pending request takes its place, instead of reusing a stale approval.
Resuming a suspended run
After a human approves, continue the same run with writ resume, passing the manifest it started with (and the same --var values); Approve and resume a run, end to end walks through it. The resume reopens the run's own database and progress journal, reuses the credentials the run already issued, skips the steps that already completed, and consumes the recorded approval for the gated step. A later gated step suspends the run again (exit 4); approve it and resume again. Running the manifest with writ run instead starts a new run that cannot see this run's approvals.
Worker credentials keep their original expiry (expires_minutes). Decide an approval within that time; a call resumed after it is refused as expired, and the remaining work needs a new run.
A resume that cannot be safe is refused before anything is opened, and changes nothing (exit 3). With a different WRIT_ROOT_KEY:
Resume refused: WRIT_ROOT_KEY is not the authority key run 'approval-demo-20261117-002310-8cd93b408d164e67a903ca0b80dea931' was started with (its journal does not authenticate under it), or the journal was edited. Nothing was changed.
With none:
Resume refused: WRIT_ROOT_KEY must be set to resume a run: its credentials were issued under that key, and only it can verify them. Nothing was changed.
Reconciling a pending wallet payment
A different kind of hold happens only in settlement.mode: wallet: if a wallet payment's outcome is unknown (the network call errored or timed out after the payment might have gone out), Writ keeps the budget hold as pending_reconciliation instead of guessing, and the run exits 7. See Settlement for the full mechanics.
writ reconcile records what it decides as a signed audit row, under the key in WRIT_AUDIT_KEY. Set it the same way as WRIT_ROOT_KEY, to a different secret you keep. Without it, writ reconcile and writ revoke stop with AuditKeyNotConfigured (exit 2); --development-audit-key uses a key built into Writ instead, for tests only.
simulated settlement never produces a pending payment, so writ reconcile on a simulated run finds nothing to do:
$ writ reconcile approval-demo-20261117-002310-8cd93b408d164e67a903ca0b80dea931
No invocations pending reconciliation for run 'approval-demo-20261117-002310-8cd93b408d164e67a903ca0b80dea931'.
Exit 0.
Resolving one for real (wallet mode):
writ reconcile <run-id> --invocation <N> --resolve paid # your wallet shows the payment went through
writ reconcile <run-id> --invocation <N> --resolve not-paid # the wallet reports it failed; return the hold
writ reconcile <run-id> --invocation <N> # omit --resolve to ask a lookup-capable wallet first
--resolve not-paid on a hold with a payment hash asks the wallet by that hash first, and returns the hold only when the wallet that paid reports the payment failed. Run writ reconcile from a shell configured with the wallet the run pays from. Without --resolve, and on writ resume, a not-paid answer returns the hold only from the kind of wallet that paid.
Upgrading a database to schema 13 charges earlier late payments that exceeded a cap to the links that had room, which lowers those links' remaining budget; writ db upgrade lists each charge. When no wallet can say (Strike, or no lookup-capable wallet configured) and you have checked the payment yourself, add --allow-unconfirmed-not-paid; the audit log records that you did. A wallet that reports the payment paid refuses not-paid either way. The codes and the full rules are in writ reconcile.
--resolve only accepts exactly paid or not-paid:
$ writ reconcile approval-demo-... --resolve maybe
--resolve must be exactly 'paid' or 'not-paid' (was 'maybe').
Exit 2. A manual paid resolution settles the budget hold but produces no new work-record receipt: there's no preimage to commit to, since the wallet call is what would have produced one.
Next steps
- Settlement: simulated and wallet mode, and the ambiguous-payment case in full.
- Security model and preview limitations: what the approval thresholds do and do not cover, in the limitations table.