# Policy and approvals

> Decide which tools may run, which never may, and which need a person to say yes first.

A **policy** is three lists of tool patterns: `allow`, `deny` and `require_approval`. It applies to every tool call made with your account, whoever makes it: your code running an operation, your LLM through a [toolkit](https://www.noclick.com/docs/guide/toolkits.md), or a hosted agent calling its own tools.

```python
import noclick

noclick.Policy.set(
    deny=["*.delete_*"],
    require_approval=["gmail.send_email_message", "stripe.*"],
)
```

```ts
import { Policy } from "noclick";

await Policy.set({
  deny: ["*.delete_*"],
  requireApproval: ["gmail.send_email_message", "stripe.*"],
});
```

## Patterns

A pattern matches dotted tool names: an integration and an operation (`gmail.send_email_message`), with `*` as a wildcard (`gmail.*`, `*.delete_*`), or a capability (`search`, `fetch`, `code`). An agent's shell commands count as `code`.

- **Deny wins.** A tool that matches `deny` never runs.
- **Allow narrows.** An empty `allow` allows everything the other lists don't stop. A non-empty one allows only what matches it.
- **Approval holds.** A tool that matches `require_approval` runs only after a person approves that exact call.

Each list holds up to 200 patterns. `Policy.set` replaces the whole policy, so pass every rule you want to keep, or change one rule at a time with [`add` and `remove`](https://www.noclick.com/docs/guide/policy.md#change-one-rule).

A policy is about tools across your account. To make one connected account ask its owner before it acts, wherever it's used (the app's workflows included), require approval on [the connection itself](https://www.noclick.com/docs/guide/connections.md#require-approval-for-an-operation).

`wake_me` is the tool every agent has to [wake itself later](https://www.noclick.com/docs/guide/agents.md#wake-it-up-later), so `deny=["wake_me"]` keeps an agent from setting its own wake-ups.

The tools agents use on each other have names of their own. The `agents` capability's are `agents.spawn`, `agents.message`, `agents.ask`, `agents.status`, `agents.list` and `agents.cancel` (`agents.*` for all of them; see [Coordinators](https://www.noclick.com/docs/guide/sub-agents.md#a-coordinator)), and `tell_parent` is the one every spawned child has to report to its parent. So `require_approval=["agents.spawn"]` makes a person approve each new child.

## Rules with conditions

A pattern judges a tool whatever it's asked to do. A `noclick.Rule` also looks at the call: `when` is a [CEL](https://cel.dev) expression over `args` (the call's final arguments, [bound](https://www.noclick.com/docs/guide/connections.md#fix-arguments-the-model-mustn-t-choose) ones included) and `user` (the user it's made for: `id`, `email`, `name`, `metadata`), and the rule applies only when it's true. `approver` names who approves a held call: a `Human` or an email.

```python
import noclick

noclick.Policy.set(
    deny=[noclick.Rule("gmail.send_email_message", when='args.to.exists(t, t.endsWith("@rival.com"))')],
    require_approval=[
        noclick.Rule("stripe.create_refund", when="args.amount > 10000", approver="finance@acme.com"),
        noclick.Rule("quickbooks.create_bill", when="args.total_amount > 2500"),
        {"tool": "calendar.*", "when": 'user.metadata.plan != "pro"', "approver": noclick.Human()},
        "gmail.*",
    ],
)
```

```ts
import { Human, Policy, Rule } from "noclick";

await Policy.set({
  deny: [new Rule("gmail.send_email_message", { when: 'args.to.exists(t, t.endsWith("@rival.com"))' })],
  requireApproval: [
    new Rule("stripe.create_refund", { when: "args.amount > 10000", approver: "finance@acme.com" }),
    new Rule("quickbooks.create_bill", { when: "args.total_amount > 2500" }),
    { tool: "calendar.*", when: 'user.metadata.plan != "pro"', approver: new Human() },
    "gmail.*",
  ],
});
```

- A rule goes in any of the three lists, beside plain patterns; a dict with `tool`, `when` and `approver` works too. `get` and `list` read a rule back as a `Rule`. A `when` that isn't CEL, or reads anything but `args` and `user`, raises `noclick.InvalidRequest` when you save it.
- A rule without a `when` applies to every call it matches, like a pattern.
- A call a `when` can't judge (an argument the call doesn't have, values that don't compare) meets a `deny` or `require_approval` rule and misses an `allow` one, so a condition never opens what it was written to close. Write `has(args.amount) && args.amount > 10000` to say exactly what a missing argument means. Numbers compare within their own type: `double(args.amount) > 99.5` for an amount that may have a fraction.
- Only a `require_approval` rule has an `approver`. `noclick.Human()` there is the user the call is made for, `user.human` a particular user, and an email anyone. The approver is emailed the approval, and only they answer it: not your account's key, not the console. Without one, the [owner of what the call acts in](https://www.noclick.com/docs/guide/policy.md#who-approves) approves.

`evaluate` with `arguments=` judges one call, and each verdict's `rule` is the rule that decided it, whole:

```python
[verdict] = noclick.Policy.evaluate("stripe.create_refund", arguments={"amount": 25000}, user="user_42")
print(verdict.verdict, verdict.rule)   # approval Rule(tool='stripe.create_refund', when='args.amount > 10000', ...)
```

```ts
import { Policy } from "noclick";

const [verdict] = await Policy.evaluate("stripe.create_refund", { arguments: { amount: 25000 }, user: "user_42" });
console.log(verdict.verdict, verdict.rule);   // approval Rule { tool: 'stripe.create_refund', when: 'args.amount > 10000', ... }
```

Without `arguments`, a rule with a `when` never matches.

## Change one rule

`Policy.add` puts rules in one list and `Policy.remove` takes the rules for some tools out of every list, each in one change on the server that leaves the other rules alone, however many callers change the policy at once. So the code that owns a rule can keep it, without reading and rewriting the whole policy:

```python
noclick.Policy.add("quickbooks.create_bill")
noclick.Policy.add("slack.*", to="deny", user="user_42")
noclick.Policy.remove("slack.*", user="user_42")
```

```ts
import { Policy } from "noclick";

await Policy.add(["quickbooks.create_bill"]);
await Policy.add(["slack.*"], { to: "deny", user: "user_42" });
await Policy.remove(["slack.*"], { user: "user_42" });
```

`to` is `"require_approval"` (the default), `"deny"` or `"allow"`. A rule for a tool that list already has replaces it, in place, so adding the same rule on every deploy changes nothing and a new threshold replaces the old one:

```python
noclick.Policy.add(noclick.Rule("quickbooks.create_bill", when="args.total_amount > 2500", approver="finance@acme.com"))
```

```ts
import { Policy, Rule } from "noclick";

await Policy.add([new Rule("quickbooks.create_bill", { when: "args.total_amount > 2500", approver: "finance@acme.com" })]);
```
 `remove` takes the tools as written (`"gmail.*"` removes the `gmail.*` rule, not `gmail.send_email_message`'s), and a tool with no rule changes nothing. Both follow `as_user` like `set`, a list still holds up to 200 patterns (`noclick.InvalidRequest` past that), and only a key acting for your whole account changes a policy (`noclick.PermissionDenied` otherwise).

## A user's own policy

A user's policy narrows the account's. It can deny more or require more approvals, never less:

```python
noclick.Policy.set(allow=["search", "gmail.*"], user="user_42")
noclick.Policy.get(user="user_42")
noclick.Policy.list()   # the account's policy and every user's
```

```ts
import { Policy } from "noclick";

await Policy.set({ allow: ["search", "gmail.*"] }, { user: "user_42" });
await Policy.get({ user: "user_42" });
await Policy.list();   // the account's policy and every user's
```

Like every call, `set`, `get` and `evaluate` follow [`as_user`](https://www.noclick.com/docs/guide/users.md): inside it they address that user's policy, so a bare `Policy.set` there never replaces the account's. Pass `user=None` for the account's policy.

## Check a policy without running anything

`evaluate` says how the policy judges each tool, and which rule decided. Pass a `draft` to try rules before you save them:

```python
for verdict in noclick.Policy.evaluate(
    ["gmail.send_email_message", "gmail.fetch_emails_from_inbox"],
    draft={"layer": "account", "deny": ["gmail.*"]},
):
    print(verdict.tool, verdict.verdict, verdict.matched_pattern)
```

```ts
import { Policy } from "noclick";

for (const verdict of await Policy.evaluate(
  ["gmail.send_email_message", "gmail.fetch_emails_from_inbox"],
  { draft: { layer: "account", deny: ["gmail.*"] } },
)) {
  console.log(verdict.tool, verdict.verdict, verdict.matchedPattern);
}
```

## Approvals in your own code

When a call you make directly is held, it raises `noclick.ApprovalRequired`. The approval request is already on its way to the approver. Wait for it, then repeat the identical call with its `approval_id`:

```python
gmail = noclick.Connection.from_name("gmail")
args = {"to": ["team@acme.com"], "subject": "Q3 numbers", "body": "..."}

try:
    gmail.run("send_email_message", args)
except noclick.ApprovalRequired as pending:
    if pending.operation.wait():
        gmail.run("send_email_message", args, approval_id=pending.approval_id)
```

```ts
import { ApprovalRequired, Connection } from "noclick";

const gmail = Connection.fromName("gmail");
const args = { to: ["team@acme.com"], subject: "Q3 numbers", body: "..." };

try {
  await gmail.run("send_email_message", args);
} catch (pending) {
  if (!(pending instanceof ApprovalRequired)) throw pending;
  if (await pending.operation?.wait()) {
    await gmail.run("send_email_message", args, { approvalId: pending.approvalId });
  }
}
```

The approver has 24 hours to answer. A granted approval covers one call: the same tool with the same arguments, once. A rejected approval makes the retry fail with `noclick.PolicyDenied`.

`pending.operation` is there whoever approves, including when your server acts for a user and your account's owner approves. It's `None` only when a user's session, or a key pinned to that user, makes a call someone else approves, since their credential can't read your account's approvals: retry the call with `approval_id` later instead, which raises `noclick.ApprovalRequired` again until it's approved. `pending.approve_url` is set only when the approver is the one the call is made for (see [Who approves](https://www.noclick.com/docs/guide/policy.md#who-approves)).

## Approvals for LLMs and agents

A [toolkit](https://www.noclick.com/docs/guide/toolkits.md) never raises: a held call comes back to the model as an error result, and the approval's details go to your `on_approval` callback instead. A hosted agent is told only that the call waits for approval. Neither ever sees the approval link, so a model can't approve its own call.

Once the person approves, a toolkit model's retry of the identical call goes through. A hosted agent's held call resumes its conversation on its own: once the person decides, the conversation takes a turn with what came of it (see [When a call waits for approval](https://www.noclick.com/docs/guide/agents.md#when-a-call-waits-for-approval)).

- Approved, NoClick runs the exact call that was held (an operation's, with the arguments and the connection it was held with, once) and the turn reads its result; the agent is told not to make the call again.
- Declined, the turn says so, with the approver's note, and the call never runs.
- A held shell command or other tool that isn't an operation the agent makes again itself, as the turn tells it.

The reply goes out wherever the conversation lives (a chat, or on an email thread, the same thread, since an inbox agent's [`reply` tool](https://www.noclick.com/docs/guide/inboxes.md#a-conversation-per-thread-answered-with-a-reply-tool) is bound to the thread's latest message), so nothing waits on the agent being messaged again. A channel's conversation isn't resumed: the channel starts its turns. `agent.triggers()` lists this as kind `approval` while your policy may hold one of the agent's tools. An approver answering from your own UI passes the note with [`request.approve(note=...)` or `request.decline(note=...)`](https://www.noclick.com/docs/guide/humans.md#answer-from-your-own-code).

## Answer held calls from your code

Besides your policy's approvals, NoClick itself holds some calls for your account's owner's yes when an agent, a connected app, a key used through MCP or an app's own code makes them: a purchase, a deletion that can't be undone, a call whose terms a person accepts, and a raised spending limit. It sends the owner a link on the app they last texted NoClick on, else by email, and the call runs once they approve it ([MCP](https://www.noclick.com/docs/guide/mcp.md)).

Your own code can answer them too, so none of them has to wait for a person. Make a key for it alone that names the `approvals:answer` scope (a key with every scope, `*`, doesn't hold it unless it's named too), and decide from your server:

```python
import noclick

for approval in noclick.Approval.list(status="pending"):
    if approval.price and approval.price["amount_usd"] <= 20:
        approval.approve(note="Within budget.")
    elif approval.impact:
        approval.decline(note="Deletions wait for the weekly review.")
```

```ts
import { Approval } from "noclick";

for (const approval of await Approval.list({ status: "pending" })) {
  if (approval.price && Number(approval.price.amount_usd) <= 20) await approval.approve({ note: "Within budget." });
  else if (approval.impact) await approval.decline({ note: "Deletions wait for the weekly review." });
}
```

Over HTTP it's `POST /v1/approvals/{id}/answer` with `{"approved": true}`, and the held call's request answers the same way through [`request.approve()`](https://www.noclick.com/docs/guide/humans.md#answer-from-your-own-code). NoClick then runs an approved call itself, once, exactly as it was held, and whoever made it hears how it went.

A key answers only what you'd trust it with:

- It never answers a call made with it: by its own code, through MCP, or by an agent's turn or an app acting as it. Give the code that decides a key of its own.
- It approves only what it could make itself, acting for the same user the call acts for: the scopes the call needs (the ones its route takes, and the ones the call asks for by what it names, like purging a dict from the trash taking `dicts`), and a spending limit it may set. A call only your account's owner and your NoClick assistant make (raising your account's own monthly cap, a payment link, adding funds) isn't any key's to approve. Anything more raises `noclick.PermissionDenied`, and the call waits for the owner.
- What it approves counts against its own monthly cap: what it spent this month, plus the price of each purchase it approved this month, plus this one, must fit, else `noclick.SpendCapExceeded`. A purchase it approved that failed, was canceled or lapsed counts nothing, and so does one whose registration failed after the call (a domain the registry refused). Its approvals count against that key's cap alone, never a user's or an agent's. Once its cap (or the cap of the user the call acts for, or your account's) is used up, it approves nothing but a deletion. What it approved also counts against what the key may still spend itself. A change that commits your account to charges no quote priced, such as turning on a domain's auto-renew, isn't any key's to approve.
- It never approves a call whose terms a person accepts, such as a domain's registration agreement: the owner does, on the call's page. Your code may still decline one.
- It acts for your account: a key acting for a user, a user's session, an app's own code, an MCP connection and an agent's turn can't answer. NoClick's staff viewing your account make no key that holds `approvals:answer`.

An approved call then runs with no scope the answering key lacks, so it never does more than that key could.

While your account holds such a key that would approve this very call, a call NoClick can't send the owner's link for (they have no email address and text NoClick on no app, or your account's emails for the day are used up) is still held, for your code to answer: the call's `sent_to` is empty, and no link goes out later. The owner can still answer it signed in to NoClick. Without one, it goes to the next approver your routing names (below), else it's refused (`noclick.NotAvailable`, or `noclick.RateLimited` past the day's emails).

Each answer is kept with who gave it: the approval's `decided_by` is `code` and `decided_by_key` names the key, or `decided_by` is `owner` when the owner answered (`person` or `agent` for an approver your routing names).

### Hear them as they're held

Rather than list what waits, give a [webhook](https://www.noclick.com/docs/guide/webhooks.md) the `approval.*` events: `approval.requested` arrives once as each call is held (one whose link reached nobody, with an empty `sent_to`, included), and `approval.decided` once as it's decided, with `data.status` `approved`, `declined`, `expired` (nobody answered it within its day) or `canceled` (its call was withdrawn). Each event's `data` is the approval as `noclick.Approval` reads it, so the code that answers can listen instead of polling:

```python
import os
from flask import Flask, request

hook = noclick.Webhook.create("https://api.yourco.test/noclick/approvals", events=["approval.*"])

app = Flask(__name__)

@app.post("/noclick/approvals")
def held_calls():
    try:
        event = noclick.Webhook.verify(request.get_data(), request.headers, os.environ["NOCLICK_WEBHOOK_SECRET"])
    except noclick.WebhookSignatureError:
        return "", 400
    if event.type == "approval.requested":
        approval = noclick.Approval.from_id(event.data["id"])
        if approval.price and approval.price["amount_usd"] <= 20:
            approval.approve(note="Within budget.")
    return "", 204
```

```ts
import { Approval, Webhook, WebhookSignatureError, type Event } from "noclick";

const hook = await Webhook.create("https://api.yourco.test/noclick/approvals", { events: ["approval.*"] });

export async function POST(request: Request): Promise<Response> {
  let event: Event;
  try {
    event = await Webhook.verify(await request.text(), request.headers, process.env.NOCLICK_WEBHOOK_SECRET!);
  } catch (err) {
    if (err instanceof WebhookSignatureError) return new Response(null, { status: 400 });
    throw err;
  }
  if (event.type === "approval.requested") {
    const approval = Approval.fromId(String(event.data.id));
    const price = event.data.price as { amount_usd: number } | null;
    if (price && price.amount_usd <= 20) await approval.approve({ note: "Within budget." });
  }
  return new Response(null, { status: 204 });
}
```

An event never carries the approval's link or what only the owner reads: a secret argument reads `[sealed]`, and a person's contact details (a domain registrant's) are left out of `arguments`, as they are for an agent. A call made for a user is heard by your account's endpoints and that user's. Your agents can hear these events too ([triggers](https://www.noclick.com/docs/guide/triggers.md#wake-it-on-a-noclick-event)), but never answer them, and an agent's own triggers never hear a call its own turn made.

## What waits by default

Each call NoClick holds for a person is one kind of hold, and each kind has a default for each kind of caller: a connected app (`connected_app`), NoClick's assistant (`assistant`), a platform agent's tools (`agent`), a key used through MCP (`key`), code a connected app runs (`code`) and an app's own code (`app`). Read them all:

```python
policy = noclick.ApprovalPolicy.get()
print(policy.default("purchase", "agent"))   # ask
for kind in policy.kinds:
    print(kind.kind, kind.approver, kind.defaults)
```

```ts
import { ApprovalPolicy } from "noclick";

const policy = await ApprovalPolicy.get();
console.log(policy.default("purchase", "agent")); // ask
for (const kind of policy.kinds) console.log(kind.kind, kind.approver, kind.defaults);
```

Over HTTP it's `GET /v1/approvals/policy`. A default is `allow`, `ask` (held for its approver), `deny`, `under_auto_approve` (a purchase NoClick priced, by its quote or, for code, as it's made, at or under the connection's auto-approve amount goes through, anything else asks) or `once_previewed` (a deletion its preview confirmed goes through). The kinds:

| Kind | What it holds |
|---|---|
| `purchase` | A call with a price: a number, a domain, a machine, a renewal. |
| `delete` | A deletion that can't be undone. |
| `delete_reversible` | A deletion that goes to the trash: judged as a change. |
| `purge` | Purging something from the trash, for good. |
| `recurring_charge` | Committing the account to charges no quote priced: turning a domain's auto-renew on. |
| `raise_limit` | Raising or removing a spending limit (lowering one goes through). |
| `user_email` | Pointing a user's email, where their approvals are sent, at another address. |
| `terms` | A call whose terms a person accepts, such as a domain's registration agreement. |
| `person_filing` | An app's code buying in a person's name: a domain, or a number with its holder's details. |
| `outside_outbound` | Acting outside the account on a turn answering someone outside the agent's scope. |
| `outside_change` | Changing what that conversation didn't make, on such a turn. |
| `outside_other_connection` | On such a turn, acting beyond the connection the agent answers on. |
| `policy_rule` | A call your policy's `require_approval` rule names. |
| `tool_rule` | An action an agent's own tool rules ask first about. |
| `attach_connection` | Giving a workflow's step a connection, or an agent step a secret, it doesn't already hold. An agent gives only your account's own, to your account's own workflows ([below](https://www.noclick.com/docs/guide/policy.md#let-agents-attach-your-connections)). |
| `loosen_approvals` | A model loosening a key's, a connected app's or an agent's own approval settings, or [lifting a connection's approval rule](https://www.noclick.com/docs/guide/connections.md#lift-it), on its own, with no word of yours on its turn; tightening them, and a loosening you asked for, go through. |
| `admin` | An administrative call by a connected app or an agent holding the `admin` group: your policy's rules, resuming a user's spending, unfreezing a card. Off by default ([below](https://www.noclick.com/docs/guide/policy.md#let-an-agent-or-a-connected-app-administer)). |
| `elevate` | Loosening what an agent may do, by a connected app or an agent holding the `admin` group: a coding agent's permission mode past `approval-required`, app testing, model switching, Docker on your machines, a card to pay with or its limits. Off by default. |

These are NoClick's defaults, the same for every account. A call they hold is answered as [above](https://www.noclick.com/docs/guide/policy.md#answer-held-calls-from-your-code), or your account [switches the kind](https://www.noclick.com/docs/guide/policy.md#switch-them-for-your-account) so it isn't held at all.

## Switch them for your account

No call has to wait for a person for good. Your account switches each kind marked `settable` to `allow`, `ask` or `deny`, for every caller it applies to, in place of NoClick's default; a purchase allowed `under_usd` goes through at or under that price and asks above it:

```python
noclick.ApprovalPolicy.set(settings={
    "purchase": {"disposition": "allow", "under_usd": 20},
    "purge": "allow",
    "outside_outbound": "allow",   # a support agent answering strangers may message people
    "delete": "ask",               # even a connected app holding delete asks first
})
```

```ts
import { ApprovalPolicy } from "noclick";

await ApprovalPolicy.set({ settings: {
  purchase: { disposition: "allow", under_usd: 20 }, purge: "allow", outside_outbound: "allow", delete: "ask",
} });
```

Over HTTP it's `PUT /v1/approvals/policy` with `{"settings": {...}}`. The settable kinds are `purchase`, `delete`, `delete_reversible`, `purge`, `recurring_charge`, `raise_limit`, `outside_outbound`, `outside_change`, `outside_other_connection`, `attach_connection`, `loosen_approvals`, `admin`, `elevate`, `terms` and `person_filing` (the last two take `standing` in place of `allow`: [below](https://www.noclick.com/docs/guide/policy.md#terms-and-filings-kept-on-file)). Each kind in `get` lists the `dispositions` it takes.

- Only the account's owner signed in, or one of its own secret keys that names the `approvals:policy` scope, switches them (a key with every scope, `*`, doesn't hold it unless it's named too). An agent, a connected app or an app's code never does: a model never loosens the holds on its own calls.
- A call names only the kinds it changes; others stay as they are, and `null` puts one back to NoClick's default. Anything it refuses, it refuses whole.
- Letting purchases or deletions through past the default (`allow`, at any amount) needs a monthly spending cap on the account first (`noclick.PermissionDenied` with `reason` `spend_cap_required` otherwise), so whatever goes through unasked is bounded by money. Remove the cap later and such a switch sleeps, NoClick's default holding until a cap is set again.
- `until` on a kind's setting makes it lapse at that moment, back to what it replaced: `{"disposition": "allow", "until": "2026-11-21T18:00:00Z"}`.
- `ceilings` are the loosest a narrower scope ([a key](https://www.noclick.com/docs/guide/policy.md#set-them-for-one-key-or-connected-app), [an agent](https://www.noclick.com/docs/guide/policy.md#set-them-for-one-agent)) may set a kind to; your account's own setting can't be looser than its ceiling.
- A key's loosening takes effect after a 10-minute undo window, and the owner is told once per call, on the app they last texted NoClick on, else by email; the owner's own change applies at once. Tightening always applies at once. Take back a change still waiting with `noclick.ApprovalPolicy.undo(change_id)` (`POST /v1/approvals/policy/changes/{id}/undo`).
- Every change is kept (`noclick.ApprovalPolicy.history()`, `GET /v1/approvals/policy/changes`) and each call is one `approvals.policy.changed` [webhook event](https://www.noclick.com/docs/guide/webhooks.md).
- A connection's own approval rule is lifted on the connection, by the same rule: [`lift_approval`](https://www.noclick.com/docs/guide/connections.md#lift-it), at once signed in or on your word to your agent, after the undo window from a key holding `approvals:policy`, and on your approval when a model lifts one on its own (`loosen_approvals`). Each lift is one of these changes, with `scope` `credential`, `kind` `credential_rule` and `target` `operations`.
- An agent's own tool rules still ask what they ask: switching `outside_outbound` to `allow` doesn't lift an agent's rule that asks before acting outside.

`get` reads what each caller meets now (`effective`), and `explain` says what one call would meet, and why, without running anything:

```python
seen = noclick.ApprovalPolicy.explain("purchase", "agent", amount_usd=12)
print(seen.disposition, seen.source, seen.why)   # allow account None
```

```ts
import { ApprovalPolicy } from "noclick";

const seen = await ApprovalPolicy.explain("purchase", "agent", { amountUsd: 12 });
console.log(seen.disposition, seen.source, seen.why);
```

### Terms and filings kept on file

A person's acceptance of terms (a domain's registration agreement) and the details your app's code files in a person's name (a domain's registrant, a number's holder) can't be allowed away, but they can be given once and kept on file. Set `terms` and `person_filing` to `standing` and a call what's on file covers runs with nobody asked; a call nothing on file covers is refused at once with the step that files it, never held, so code buying for itself moves on rather than waiting:

```python
noclick.ApprovalPolicy.set(settings={"terms": "standing", "person_filing": "standing"})
# What's on file: the account's default registrant (or a user's), each with their own acceptance...
noclick.Domain.set_default_registrant(dana, user="user_42")   # dana.agreement_accepted_at: when she accepted
# ...and a number holder's profile, with when the holder accepted having it filed in their name.
noclick.PhoneNumber.set_holder_profile(holder, accepted_at=accepted_at, user="user_42")
```

```ts
import { ApprovalPolicy, Domain, PhoneNumber } from "noclick";

await ApprovalPolicy.set({ settings: { terms: "standing", person_filing: "standing" } });
await Domain.setDefaultRegistrant(dana, { user: "user_42" });
await PhoneNumber.setHolderProfile(holder, { acceptedAt, user: "user_42" });
```

- A domain registers with no hold when the person it's registered to is on file and accepted the registration agreement as it stands now (`GET /v1/domains/agreement`): the account's default registrant, or acting for a user their registrant profile (`PUT /v1/domains/registrant`, with `NoClick-User`). A purchase naming no registrant uses it; one naming the same person takes their acceptance from it. An app's code buys in its app's scope (a user's app, that user's).
- With nothing on file, someone else named, or an acceptance of an earlier version of the agreement, it's refused (`noclick.PolicyDenied`, `hold_kind` `terms` or `person_filing`) with the step that files it: for the account, the console page where its default registrant is set (`url`); for a user, the profile your server files once they've accepted.
- A name with a trademark notice is refused under `standing`: a person reads its notice for each name, so nothing on file covers it. Pick another name, or have a person read it and buy it with `accept_claims` from your own server.
- A number an app's code buys files its holder with `holder_on_file: true` (or the same holder and answers as the profile): it runs when the holder profile is on file (`PUT /v1/phone_numbers/holder`), and is refused naming that call when it isn't.
- `deny` refuses every call whose terms a person accepts, or that files in a person's name, whatever is on file. `ask`, NoClick's default, holds them for the owner as before.
- Holder profiles and registrants are personal data: `GET`/`PUT /v1/domains/registrant` and `/v1/phone_numbers/holder` are your server's or the signed-in owner's, never an agent's over MCP, and an app's code never files a holder itself.

## Set them for one key or connected app

One key, or one connected app, can do more (or less) without asking than the rest of your account. Its own settings take the place of the account's for the calls it makes itself: a key's through MCP and the code it runs, a connected app's and its code's, NoClick's assistant's through its grant. They're never looser than the account's ceiling for the kind, else the account's own setting, else NoClick's default for that caller, so raise the ceiling first, then loosen the one:

```python
noclick.ApprovalPolicy.set(ceilings={"purchase": {"disposition": "allow", "under_usd": 50}})
mine = noclick.ApprovalPolicy.set_for_key(key_id, {"purchase": {"disposition": "allow", "under_usd": 20}})
noclick.ApprovalPolicy.set_for_connected_app(app_id, {"delete": "ask"}, auto_approve_under_usd=10)
```

```ts
import { ApprovalPolicy } from "noclick";

await ApprovalPolicy.set({ ceilings: { purchase: { disposition: "allow", under_usd: 50 } } });
await ApprovalPolicy.setForKey(keyId, { purchase: { disposition: "allow", under_usd: 20 } });
await ApprovalPolicy.setForConnectedApp(appId, { settings: { delete: "ask" }, autoApproveUnderUsd: 10 });
```

Over HTTP it's `approvals` on `PATCH /v1/keys/{id}` and on `PATCH /v1/connected_apps/{id}`, which also takes `auto_approve_under_usd` (and, signed in, `spend_cap_usd_per_month` and `capabilities`).

- Lowering the ceiling later tightens every key and connection at once: what each set is read clamped to it, and so is a connection's auto-approve amount. A setting looser than the ceiling isn't written.
- A purchase or a deletion let through past its caller's default needs a monthly spending cap on the account, as the account's own switch does.
- A purchase code makes comes under its connection's auto-approve amount, priced by NoClick as it's made: code needs no quote.
- NoClick's assistant's grant is a connected app: it has no auto-approve amount and asks before every deletion that can't be undone until you change it there. Its monthly cap follows its agent's budget.
- You say what your agents may do and it happens. Tightening is a plain change from any of your account's callers: your keys, your connected apps (one tightening itself included) and your agents.
- A loosening takes effect on your own word: signed in, or told to your agent (NoClick's assistant, or any agent of yours) on a turn your own message started, or that another of your agents passed on. It's recorded as yours (`responsible_user_id`), with the key or connection and the agent it came through. "Let the deploy key buy domains under $20 without asking" in the chat is enough.
- A loosening a model makes on its own (a connected app, a turn a schedule, an event or a wake-up started, one someone else's message started) waits for you, from the link NoClick sends you (the `loosen_approvals` kind, a default you can switch). Nothing loosens its own on its own initiative.
- One of your keys loosens one only when it holds `approvals:policy`; its loosening waits the 10-minute undo window and tells you, and it only lowers an auto-approve amount.
- A call acting for one of your users changes only a connected app (or an agent) acting for that same user.
- A loosening that couldn't apply at all (past the ceiling, or a purchase past the default with no monthly cap) isn't held for you: the call is refused, saying why.
- `get(key_id=...)` and `explain(..., key_id=...)` (or `connected_app_id`) read what that key or connection meets: each kind's `own`, and `source` `key` where its own setting decides.
- An agent's turn acting as a key meets the agent's own settings (below), else the account's, never the key's.

## Set them for one agent

An agent's own settings take the place of the account's for its own calls: what its NoClick tools do (a purchase, a deletion) and its own tool calls (acting beyond the connection it answers on, for a turn answering someone outside). NoClick's assistant is an agent like any, so its purchases follow its own. Give it `approvals` when you create it, or change them later:

```python
noclick.ApprovalPolicy.set(ceilings={"purchase": {"disposition": "allow", "under_usd": 50}})
buyer = noclick.Agent.create("buyer", instructions="Buy the numbers the team asks for.", tools=["noclick"],
                             approvals={"purchase": {"disposition": "allow", "under_usd": 20}})
noclick.Agent.from_name("support").update(approvals={"outside_other_connection": "allow"})
```

```ts
import { Agent, ApprovalPolicy } from "noclick";

await ApprovalPolicy.set({ ceilings: { purchase: { disposition: "allow", under_usd: 50 } } });
const buyer = await Agent.create("buyer", { instructions: "Buy the numbers the team asks for.", tools: ["noclick"],
  approvals: { purchase: { disposition: "allow", under_usd: 20 } } });
await Agent.fromName("support").update({ approvals: { outside_other_connection: "allow" } });
```

Over HTTP it's `approvals` on `POST /v1/agents`, `PATCH /v1/agents/{id}` and `POST /v1/agents/{id}/children`. That buyer's $19 purchase goes through and its $21 one waits for you.

- An agent with no parent is clamped to the account's ceiling, as a key is, when written and when read. A purchase or a deletion past the default needs a monthly cap on the account.
- A child follows its parent's settings where it sets none, and its own only tighten them: one looser than its parent's is refused, and tightening the parent tightens every child at once.
- A tool rule allowing `noclick.spend` or `noclick.delete` (`tool_rules`) sets `purchase` or `delete` to allow with it, judged exactly as `approvals` saying so. An `ask` rule still asks whatever `approvals` say.
- Who changes them is the rule above: anyone who may change the agent tightens them; a loosening takes effect on your own word (signed in, or your own message to any of your agents, "you can buy numbers under $20 without asking me" included, recorded as yours); a key holding `approvals:policy` waits the undo window; an agent loosening its own or another's on its own initiative waits for your yes (`loosen_approvals`; switched to allow, an agent still never loosens its own). Code never answers such a held call.
- `get(agent_id=...)` and `explain(..., agent_id=...)` read what that agent meets: `source` `agent` where its own setting decides, `parent` where it follows its parent's.
- NoClick's assistant's grant settings (above) don't reach its agent's turns: set the assistant's own with `PATCH /v1/agents/{its id}`, or tell it.

## Let agents attach your connections

An agent building or fixing one of your workflows gives its steps your account's own connections and secrets itself, as you would on the canvas: `set_connection` on a step ([workflows](https://www.noclick.com/docs/guide/workflows.md#change-it-step-by-step)) and an agent step's `secrets`. That's the `attach_connection` kind, allowed by default. Each change is a version of the workflow naming who made it (the key its turn acted as), so what an agent attached stays in the workflow's history, and restoring the version before it takes it off.

It never gives a step another member's connection, one of your users', or one held for someone else, and it attaches only in workflows your account owns: any of those is refused, naming it. Switch it like any kind, for your whole account, one connected app or key, or one agent, so a person picks a step's account instead. Here every agent asks you first but one, which the ceiling lets do more than the rest:

```python
noclick.ApprovalPolicy.set(settings={"attach_connection": "ask"}, ceilings={"attach_connection": "allow"})
noclick.Agent.from_name("builder").update(approvals={"attach_connection": "allow"})
```

```ts
import { Agent, ApprovalPolicy } from "noclick";

await ApprovalPolicy.set({ settings: { attach_connection: "ask" }, ceilings: { attach_connection: "allow" } });
await Agent.fromName("builder").update({ approvals: { attach_connection: "allow" } });
```

- `ask`: the edit waits for you, from the link NoClick sends you, and lands as it was sent once you approve it.
- `deny`: the edit is refused, and the agent asks you which account the step should use instead; what you pick is attached as yours.
- An agent's own setting wins over the account's, as for every kind, and telling your agent "you can connect my accounts to the workflows you build" in the chat is your word. A key or a connected app acting for your whole account attaches any connection your account may use, as you do, unless its own setting or the account's says otherwise; your own server's key, used directly, is never asked.

## Route held calls to another approver

Who answers a held call is a setting too, so a swarm of agents never waits on one person. Your account names an approver for what its callers hold, and a key, connected app or agent can name its own, which comes first:

```python
noclick.ApprovalPolicy.set(routing={"approver": {"agent_id": "supervisor"}, "on_timeout": "escalate",
                                    "expires_in_s": 3600})
noclick.Agent.from_name("worker").update(approvals={"routing": {"approver": {"code": True}}})
noclick.ApprovalPolicy.set_for_key(key_id, {"routing": {"approver": {"email": "ops@example.com"}}})
```

```ts
import { Agent, ApprovalPolicy } from "noclick";

await ApprovalPolicy.set({ routing: { approver: { agent_id: "supervisor" }, on_timeout: "escalate",
  expires_in_s: 3600 } });
await Agent.fromName("worker").update({ approvals: { routing: { approver: { code: true } } } });
```

Over HTTP it's `routing` on `PUT /v1/approvals/policy`, and `approvals.routing` on `PATCH /v1/keys/{id}`, `PATCH /v1/connected_apps/{id}`, `POST /v1/agents`, `PATCH /v1/agents/{id}` and `POST /v1/agents/{id}/children`. `approver` is one of:

- `"owner"`: your account's owner, from the link NoClick sends them (the default, and always last).
- `{"email": ...}`: a person, from a link NoClick emails them.
- `{"user_id": ...}`: one of your users, by your id, at their email.
- `{"agent_id": ...}`: one of your account's own agents, by id or name: a supervisor. It's woken in its own `approvals` conversation with every call waiting on it (fifty held calls are one turn, not fifty) and answers them in one `approvals__answer` call: approve, decline (with a note whoever made the call reads), or escalate.
- `{"code": true}`: your own code, with a key holding `approvals:answer` (above), hearing each at the `approval.requested` webhook. No email goes out.

A call goes up the chain, most specific first: the agent's own approver, then each of its ancestors', or the key's or connected app's, then your account's, then the owner. `get()` lists each caller's chain as `approvers`, and `explain()` the one a call would meet. It's asked of the first that can answer it:

- An agent approves only what it could do itself: a purchase within its own `purchase` amount, never a deletion that can't be undone, a purge or a call your policy rules hold. One beyond it goes past it, and one it can't approve any more (you lowered its settings) it escalates.
- A parent agent answers its children's calls, and their children's, so a supervisor can sit at the top of its own line: a coordinator whose workers ask before every purchase approves theirs within its own amount. It never answers its own call, nor its parent's or any other ancestor's: the call goes past it. Naming an agent itself, or one of its children, as its approver is refused.
- What only a person accepts or files (terms, a filing in a person's name), a user's email and a loosening of approval settings go to the owner alone.
- `{"code": true}` is asked only while your account holds a key that would approve the call; else it goes on.
- An owner NoClick can't reach (no email address, no app they text NoClick on, or a send that failed) passes the call to the next approver; with none left, your code answers it where a key of yours would (above), else it's refused (`noclick.NotAvailable`), saying the routing setting would send it elsewhere.

Each approver has `expires_in_s` (60 seconds to 7 days; a day unless a scope says otherwise). Unanswered by then, the call is declined (`on_timeout` `decline`, the default), or goes to the next approver up (`escalate`); nobody left to escalate to declines it. A scope naming no approver passes its `expires_in_s` and `on_timeout` up to the next one that does (to the owner, past your account's), so `{"expires_in_s": 3600}` alone gives your owner an hour.

Your account's owner can always answer, signed in. An approval says who it waits on (`approver`, with `on_timeout`), and who decided: `decided_by` `owner`, `person` (an email or user approver), `agent` (`decided_by_agent` names it) or `code`.

A workflow's Approval steps go the same way: a step can name its own `approver`, `on_timeout` and `expires_in_s` in its settings, which come first; then your account's routing, then the owner. A step that names none follows your account's, with 7 days unless a scope says otherwise, as steps always had. An agent approves a step only if its own tools could run the workflow, and never one whose run its own turn (or an ancestor's) started. See [Name who answers a step](https://www.noclick.com/docs/guide/workflows.md#name-who-answers-a-step).

Naming an approver other than the owner is a loosening, guarded as one: your own word applies at once; a key holding `approvals:policy` waits the 10-minute undo window; an agent or connection on its own waits for your yes. Pointing calls back at the owner, and the timing, are plain changes.

## Let an agent or a connected app administer

Over MCP, the calls that change your account's own guards are out of reach: policy, keys, caps, approvals, secrets' values and raw tokens stay with a person, or with your own server's key. Two of them open to a connected app or an agent you grant the `admin` group:

- **Administrative calls** (kind `admin`): your policy's rules (`PUT /v1/policy`, `POST /v1/policy/add`, `POST /v1/policy/remove`), resuming a user's paused spending (`POST /v1/users/{id}/spending/resume`) and unfreezing a card (`POST /v1/cards/{id}/unfreeze`).
- **Loosening what an agent may do** (kind `elevate`): a `permission_mode` other than `approval-required`, `app_testing` other than `never`, `model_switching` that lets an agent move by itself, a card given to an agent or its limits changed, and Docker on [your own machines](https://www.noclick.com/docs/guide/machines.md).

Nothing holds `admin` unless it's named: a connected app only when its client asks for the `admin` scope by name and you tick it at consent, an agent only with `"noclick.admin"` in its tools (`"noclick"` alone, `"everything"` and NoClick's assistant never hold it), and a key used through MCP never. A connected app or an agent's turn can't give another agent `"noclick.admin"` unless it holds it itself.

Holding it opens nothing yet: both kinds are `deny` by default for every caller over MCP, and a call is refused naming the setting that opens it. Switch them like any kind, to `ask` (held for you, from the link NoClick sends you) or `allow`, for your whole account, one connected app or key, or one agent. Here one agent may loosen others' permission modes once you approve each, and no other caller may:

```python
noclick.ApprovalPolicy.set(ceilings={"elevate": "ask"})
ops = noclick.Agent.create("ops", instructions="Keep the coding agents moving.", tools=["noclick", "noclick.admin"],
                           approvals={"elevate": "ask"})
```

```ts
import { Agent, ApprovalPolicy } from "noclick";

await ApprovalPolicy.set({ ceilings: { elevate: "ask" } });
const ops = await Agent.create("ops", {
  instructions: "Keep the coding agents moving.", tools: ["noclick", "noclick.admin"], approvals: { elevate: "ask" },
});
```

- Asked: your own message to the agent is your yes. A turn your message started goes through at once; one a schedule, an event, a wake-up or another agent started waits for its approver ([routing](https://www.noclick.com/docs/guide/policy.md#route-held-calls-to-another-approver): you by default; an agent approves one only holding `admin` itself, with the kind allowed for it). A `deny` holds even on your word.
- A call loosening what an agent may do carries nothing else the gate would hold or price: a budget raised, approval settings a model loosens on its own, or a machine's new size beside it is refused, to be sent apart (`noclick.InvalidRequest` naming the field).
- A turn carrying words from someone outside your account (a channel's outsider, a stranger it answers) never makes either kind of call.
- Keys and their values, secrets' values, raw tokens, sessions, terminals and the routes only you signed in make (keys, your account, connected apps, approval settings) stay out of reach whatever an agent holds. Your code makes keys with [`keys:create`](https://www.noclick.com/docs/guide/keys.md#let-your-code-make-keys).

## What the approver sees

The approval page and its email say what is being approved, in words a person can judge: the operation's name as the service labels it ("Stripe: Create Refund", with the tool beside it), its arguments as a table, the user the call is made for, and, for an agent's call, the agent, a link to the conversation in your console and the agent's reason: what it wrote in its turn before making the call (a coding harness's words reach NoClick only when its turn ends, so its calls carry none). The email carries the same summary, so a person on their phone can decide without opening the page. Each argument shows up to 500 characters, and up to 30 of them.

`request.request["details"]` holds the same (`Action`, `User`, `Agent`, `Reason`, `Conversation` and `Arguments`), and the request's `approval` names the `label`, `agent`, `conversation` and `reason` on their own.

## Who approves

A [rule's `approver`](https://www.noclick.com/docs/guide/policy.md#rules-with-conditions) approves the calls its rule holds. Otherwise the owner of what a call acts in approves it:

- A call on a user's own connection is approved by that user, through `user.human`.
- A call on one of your account's connections, an operation that runs on NoClick's key with no connection, and a capability (`search`, `fetch`, `code`) are approved by your account's owner. They spend your account's money, not anything of the user's.
- A call on a connection [shared from another scope](https://www.noclick.com/docs/guide/connections.md#share-one-across-users) is approved by that connection's owner.

Who is talking to an agent doesn't change this. When a customer asks your account's support agent for a refund and it calls `stripe.create_refund` on your account's Stripe, your account's owner approves it, never the customer.

Every scope's rules are still judged: your account's, those of the user the call is made for, and those of the connection's owner. The strictest decides. So a user's own `require_approval` rule holds your account agent's call in that user's conversation, and your account's owner approves it.

The approver gets an email with a link to the approval page, and pending approvals addressed to you appear in the developer console. The approve link comes back in `noclick.ApprovalRequired` only when the approver is the one the call is made for: your account's owner for your own calls, the user for calls on their own connection.

A user with no email address can't be emailed, so:

- When a toolkit or hosted agent call on their connection is held, your account's owner approves instead. If nobody who could approve has an email address, the call fails with `noclick.NotAvailable`.
- When your own direct call on their connection is held, nothing is emailed. Pass the error's `approve_url` on to the user yourself.
